Screen clipping

Post your working scripts, libraries and tools for AHK v1.1 and older
User avatar
Gorgrak
Posts: 26
Joined: 07 Dec 2015, 16:34

Re: Screen clipping

21 Apr 2024, 21:31

Mine is working perfectly in Win 10 Home x64 21H2. And my ScreenClipper script is running as 64bit. I have never used MouseGestureL before so I'm unfamiliar with the error you are experiencing.
Kingron
Posts: 9
Joined: 22 May 2023, 19:47

Re: Screen clipping

21 Apr 2024, 22:32

Gorgrak wrote:
21 Apr 2024, 21:31
Mine is working perfectly in Win 10 Home x64 21H2. And my ScreenClipper script is running as 64bit. I have never used MouseGestureL before so I'm unfamiliar with the error you are experiencing.
ScreenClipper will force start in 32-Bit mode, see the source code:

Code: Select all

if((A_PtrSize=8&&A_IsCompiled="")||!A_IsUnicode){ ;32 bit=4  ;64 bit=8
    SplitPath,A_AhkPath,,dir
    if(!FileExist(correct:=dir "\AutoHotkeyU32.exe")){
	    MsgBox error
	    ExitApp
    }
    Run,"%correct%" "%A_ScriptName%",%A_ScriptDir%
    ExitApp
    return
}
#NoTrayIcon
User avatar
Gorgrak
Posts: 26
Joined: 07 Dec 2015, 16:34

Re: Screen clipping

21 Apr 2024, 23:47

OH you right. I HEAVILY modified mine to suit my own tastes:

Code: Select all

/* Credits:
	@ Screen clipping by Learning one				https://autohotkey.com/board/topic/46069-screen-clipping/
	@ Joe Gline's modifications (SCW v1.02)			https://autohotkey.com/boards/viewtopic.php?f=6&t=12088
	@ OCR by malcev, teadrinker, joe glines, Jackie	https://autohotkey.com/boards/viewtopic.php?f=6&t=72674
	@ SpeedMaster's plugins:
		SM_Borders							https://autohotkey.com/boards/viewtopic.php?f=6&t=12088&start=240#p506407
		SM_AlwaysOnBottom/Top					https://autohotkey.com/boards/viewtopic.php?f=6&t=12088&start=260#p509493
	@ Tervon's various additions/tweaks
*/

;;;;;;;;;;;;;;;;;;;;
;;; AUTO-EXECUTE ;;;
;;;;;;;;;;;;;;;;;;;;
#NoEnv
;#Warn
#Persistent
#SingleInstance, Force
#Include Gdip_All.ahk
#Include Notify.ahk

help1 = ; info message about shortcuts
( LTrim
	GLOBAL SHORTCUT
	Win + LClick	hold and drag to create a rectangular snip of your screen
	
	LOCAL SHORTCUTS	(only useable on the focused clipping itself)
	Control + b	toggle blue border off/on with focused clipping
	Control + c	copy focused clipping to clipboard
	Control + s	save focused clipping to desktop as timestamped PNG
	Control + x	generate OCR of focused clipping and copy to clipboard
	RClick		close focused/hovered clipping
)
help2:= "This script could not be reloaded!" ; for if reloading script fails
global help3:= "ScreenClippingWindow ahk_class AutoHotkeyGUI" ; for checking if any clippings exist

Menu, Tray, icon, mmcndmgr.dll, 106
Menu, Tray, Tip, Screen Clipper
Menu, Tray, NoStandard
Menu, Tray, Add, Shortcuts, HelpSub
Menu, Tray, Default, Shortcuts
Menu, Tray, Add,
Menu, Tray, Add, Restore All Borders, RestoreBordersSub
Menu, Tray, Add, Set all current clippings to +AlwaysOnTop, ToggleOnTopSub
Menu, Tray, Add, Set all current clippings to -AlwaysOnTop, ToggleOnTopSub
Menu, Tray, Add,
Menu, Tray, Add, Reload, HelpSub
Menu, Tray, Add, Exit, ExitSub
return

ExitSub:
ExitApp

HelpSub:
if (A_ThisMenuItem = "Reload") {
	Reload
	Sleep 1000
}
Gui, +OwnDialogs
Gui, Show
MsgBox,, % "  Screen Clipper " ((A_ThisMenuItem = "Reload") ? "Error!": "Shortcuts:"), % ((A_ThisMenuItem = "Reload") ? help2 : help1)
Gui, Destroy
return

RestoreBordersSub:
SM_RestoreAllBorders()
return

ToggleOnTopSub:
Toggle:= (InStr(A_ThisMenuItem, "+") ? "1" : "")
SM_ToggleAlwaysOnTop(Toggle)
return

;;;;;;;;;;;;;;;
;;; HOTKEYS ;;;
;;;;;;;;;;;;;;;
#Lbutton::SCW()				; Win+LCLICK	|| hold and drag to make a rectangular snip of your screen
~Rbutton::G_CloseClipping()		; RCLICK		|| close focused/hovered clipping						<< submited by Gorgrak >>

#IfWinActive, ScreenClippingWindow ahk_class AutoHotkeyGUI
^b::SM_Borders()				; Control+b	|| toggle the focused clipping's border off (or on again)	<< submited by SpeedMaster >>
^c::SCW_Output(3)				; Control+c	|| copy focused clipping to clipboard
^s::SCW_Output(2)				; Control+s	|| save focused clipping to desktop as timestamped PNG		<< submited by Tervon >>
^x::SCW_Output(1)				; Control+x	|| generate OCR of selected clipping and copy to clipboard
PgDn::SM_ToggleAlwaysOnTop()		; PageDown	|| remove focused clipping's AlwaysOnTop setting			<< submited by SpeedMaster >>
PgUp::SM_ToggleAlwaysOnTop(1)		; PageUp		|| restore focused clipping's AlwaysOnTop setting			<< submited by SpeedMaster >>
#IfWinActive

;;;;;;;;;;;;;;;;;
;;; FUNCTIONS ;;;
;;;;;;;;;;;;;;;;;
SCW_Output(Output) {
	Send, !{PrintScreen} ; Active Win's client area to Clipboard
	Sleep, 50
	pToken:= Gdip_Startup()
	pBitmap:= Gdip_CreateBitmapFromClipboard()
	if (Output=1) { ; aka Win2OCR
		hBitmap:= Gdip_CreateHBITMAPFromBitmap(pBitmap) ; Convert an hBitmap from the pBitmap
		pIRandomAccessStream:= HBitmapToRandomAccessStream(hBitmap) ; OCR function needs a randome access stream (so it isn't "locked down")
		DllCall("DeleteObject", "Ptr", hBitmap)
		Clipboard:= OCR(pIRandomAccessStream, "en")
		ObjRelease(pIRandomAccessStream)
		Notify().AddWindow(Clipboard,{Icon:300,Background:"0x0000FF",Title:"CLIPBOARD UPDATED:",TitleSize:16,size:15,Time:4000})
		; ToolTip, % "<<New Clipboard>>`n" clipboard "<<//New Clipboard>>"
		; Sleep, 2000
		; ToolTip
	}
	if (Output > 1) {
		Gdip_GetImageDimensions(pBitmap, w, h)
		if (Output=2) { ; aka Win2File
			; File2:= A_Desktop . "\" . A_Now . ".PNG" ; Tervon's time/path to file to save
			; FormatTime, TodayDate, YYYYMMDDHH24MISS, MM_dd_yy @ h_mm_ss ; Joe's time format
			FormatTime, TodayDate, YYYYMMDDHH24MISS, yyyy_MM_dd @ HH_mm_ss ; Derek's time format
			File2:= A_Desktop . "\" . TodayDate . ".PNG" ; Joe's 'path to file to save
			Gdip_SaveBitmapToFile(pBitmap, File2) ; Exports automatcially to file
		}
		if (Output=3) ; aka Win2Clipboard
			Gdip_SetBitmapToClipboard(pBitmap)
	}
	Gdip_DisposeImage(pBitmap)
	Gdip_Shutdown(pToken) ; clear selection
} ; combines Win2Clipboard, Win2File (Made by Tervon, modified by Joe), & Win2OCR

G_CloseClipping() {
	MouseGetPos,,, TESTid ; get id of win under mouse
	WinGetTitle, TESTtitle, ahk_id %TESTid%
	WinGetClass, TESTclass, ahk_id %TESTid%
	TEST:= TESTtitle " ahk_class " TESTclass
	if (TEST = help3) ; is the win under your mouse a clipping win?
		WinClose, ahk_id %TESTid% ; if yes, DO IT. *Emperor Palpatine voice*
}

SM_Borders() { ; function to toggle clipping borders
	WinGet, Hwnd, ID, A
	WinGet, Style, Style, ahk_id %Hwnd%
	if (Style & 0x2000)  ; remove selected
	{
		WinSet, Style, -0x2000, A
		WinSet, Region, , A 
		return false
	}
	else                 ; restore selected
	{
		WinGetPos, X, Y, W, H,  ahk_id %Hwnd%
		W -= 6, H -= 6
		WinSet, Style, +0x2000, A
		WinSet, Region, 3-3 W%W% H%H%, A
		return true
	}	
} ; contributed by SpeedMaster @ https://www.autohotkey.com/boards/viewtopic.php?f=6&t=12088&start=240#p506407

SM_RestoreAllBorders() { ; function to restore all hidden borders
	MaxGuis:= SCW_Reg("MaxGuis"), i:= SCW_Reg("StartAfter")
	Loop % MaxGuis {
		i++
		Gui %i%: +lastfound
		WinSet, Style, -0x2000
		WinSet, Region,
	}
	return false
} ; contributed by SpeedMaster @ https://www.autohotkey.com/boards/viewtopic.php?f=6&t=12088&start=240#p506407

SM_ToggleAlwaysOnTop(ToggleON:= "") {
	WinGet, Hwnd, ID, A
	MaxGuis:= SCW_Reg("MaxGuis"), i:= SCW_Reg("StartAfter")
	j:= MaxGuis+i
	Loop % MaxGuis {
		if (A_ThisLabel = "ToggleOnTopSub") { ; if you clicked a tray menu option
			i++
			Gui % i ": " (ToggleON ? "+" : "-") "AlwaysOnTop" ; loop thru & change all clippings
			Continue
		}
		else if (SCW_Reg("G" --j "#HWND") = Hwnd) { ; if you used the PgDn/Up hotkey
			Gui % j ": " (ToggleON ? "+" : "-") "AlwaysOnTop"	; only change the selected clipping	
			break
		}
	}
} ; contributed by SpeedMaster @ https://www.autohotkey.com/boards/viewtopic.php?f=6&t=12088&start=260#p509493

SCW() {
	static c
	if !(SCW_Reg("WasSetUp"))
		SCW_SetUp()

	StartAfter:= SCW_Reg("StartAfter"), MaxGuis:= SCW_Reg("MaxGuis"), SelColor:= SCW_Reg("SelColor"), SelTrans:= SCW_Reg("SelTrans")
	c++
	if (c > MaxGuis)
		c:= 1

	GuiNum:= StartAfter + c
	Area:= SCW_SelectAreaMod("g" GuiNum " c" SelColor " t" SelTrans)
	StringSplit, v, Area, |
	if (v3 < 10 and v4 < 10) ; too small area
		return

	pToken:= Gdip_Startup()
	if (! pToken ) {
		MsgBox, 64, GDI+ error, GDI+ failed to start. Please ensure you have GDI+ on your system.
		return
	}
	Sleep, 100

	pBitmap:= Gdip_BitmapFromScreen(Area)
	SCW_CreateLayeredWinMod(GuiNum,pBitmap,v1,v2, SCW_Reg("DrawCloseButton"))
	
	Gdip_Shutdown(pToken)
}

SCW_SetUp(Options="") {
	if !(Options = "") {
		Loop, Parse, Options, %A_Space%
		{
			Field:= A_LoopField
			DotPos:= InStr(Field, ".")
			if (DotPos = 0)
				Continue
			var:= SubStr(Field, 1, DotPos-1)
			val:= SubStr(Field, DotPos+1)
			if var in StartAfter,MaxGuis,AutoMonitorWM_LBUTTONDOWN,DrawCloseButton,BorderAColor,BorderBColor,SelColor,SelTrans
				%var%:= val
		}
	}

	; setup all the default values
	SCW_Default(StartAfter,80), SCW_Default(MaxGuis,6)
	SCW_Default(AutoMonitorWM_LBUTTONDOWN,1), SCW_Default(DrawCloseButton,0)
	SCW_Default(BorderAColor,"ff6666ff"), SCW_Default(BorderBColor,"ffffffff")
	SCW_Default(SelColor,"Yellow"), SCW_Default(SelTrans,80)

	SCW_Reg("MaxGuis", MaxGuis), SCW_Reg("StartAfter", StartAfter), SCW_Reg("DrawCloseButton", DrawCloseButton)
	SCW_Reg("BorderAColor", BorderAColor), SCW_Reg("BorderBColor", BorderBColor)
	SCW_Reg("SelColor", SelColor), SCW_Reg("SelTrans",SelTrans)
	SCW_Reg("WasSetUp", 1)
	if AutoMonitorWM_LBUTTONDOWN
		OnMessage(0x201, "SCW_LBUTTONDOWN")
}

SCW_SelectAreaMod(Options="") {
	CoordMode, Mouse, Screen
	MouseGetPos, MX, MY
	loop, parse, Options, %A_Space%
	{
		Field:= A_LoopField
		FirstChar:= SubStr(Field,1,1)
		if FirstChar contains c,t,g,m
		{
			StringTrimLeft, Field, Field, 1
			%FirstChar%:= Field
		}
	}
	c:= (c = "") ? "Blue" : c, t:= (t = "") ? "50" : t, g:= (g = "") ? "99" : g
	Gui %g%: Destroy
	Gui %g%: +AlwaysOnTop -caption +Border +ToolWindow +LastFound -DPIScale ;provided from rommmcek 10/23/16

	WinSet, Transparent, %t%
	Gui %g%: Color, %c%
	Hotkey:= RegExReplace(A_ThisHotkey,"^(\w* & |\W*)")
	While (GetKeyState(Hotkey, "p")) {
		Sleep, 10
		MouseGetPos, MXend, MYend
		w:= abs(MX - MXend), h:= abs(MY - MYend)
		X:= (MX < MXend) ? MX : MXend
		Y:= (MY < MYend) ? MY : MYend
		Gui %g%: Show, x%X% y%Y% w%w% h%h% NA
	}
	Gui %g%: Destroy
	MouseGetPos, MXend, MYend
	If ( MX > MXend )
		temp:= MX, MX:= MXend, MXend:= temp
	If ( MY > MYend )
		temp:= MY, MY:= MYend, MYend:= temp
	Return MX "|" MY "|" w "|" h
}

SCW_CreateLayeredWinMod(GuiNum,pBitmap,x,y,DrawCloseButton=0) {
	static CloseButton:= 16
	BorderAColor:= SCW_Reg("BorderAColor"), BorderBColor:= SCW_Reg("BorderBColor")

	Gui %GuiNum%: -Caption +E0x80000 +LastFound +ToolWindow +AlwaysOnTop +OwnDialogs
	Gui %GuiNum%: Show, NA, ScreenClippingWindow
	hwnd:= WinExist()

	Width:= Gdip_GetImageWidth(pBitmap), Height:= Gdip_GetImageHeight(pBitmap)
	hbm:= CreateDIBSection(Width+6, Height+6), hdc:= CreateCompatibleDC(), obm:= SelectObject(hdc, hbm)
	G:= Gdip_GraphicsFromHDC(hdc), Gdip_SetSmoothingMode(G, 4), Gdip_SetInterpolationMode(G, 7)

	Gdip_DrawImage(G, pBitmap, 3, 3, Width, Height)
	Gdip_DisposeImage(pBitmap)

	pPen1:= Gdip_CreatePen("0x" BorderAColor, 3), pPen2:= Gdip_CreatePen("0x" BorderBColor, 1)
	if DrawCloseButton {
		Gdip_DrawRectangle(G, pPen1, 1+Width-CloseButton+3, 1, CloseButton, CloseButton)
		Gdip_DrawRectangle(G, pPen2, 1+Width-CloseButton+3, 1, CloseButton, CloseButton)
	}
	Gdip_DrawRectangle(G, pPen1, 1, 1, Width+3, Height+3)
	Gdip_DrawRectangle(G, pPen2, 1, 1, Width+3, Height+3)
	Gdip_DeletePen(pPen1), Gdip_DeletePen(pPen2)

	UpdateLayeredWindow(hwnd, hdc, x-3, y-3, Width+6, Height+6)
	SelectObject(hdc, obm), DeleteObject(hbm), DeleteDC(hdc), Gdip_DeleteGraphics(G)
	SCW_Reg("G" GuiNum "#HWND", hwnd)
	SCW_Reg("G" GuiNum "#XClose", Width+6-CloseButton)
	SCW_Reg("G" GuiNum "#YClose", CloseButton)
	Return hwnd
}

SCW_LBUTTONDOWN() {
	MouseGetPos,,, WinUMID
	WinGetTitle, Title, ahk_id %WinUMID%
	if (Title = "ScreenClippingWindow") {
		PostMessage, 0xA1, 2,,, ahk_id %WinUMID%
		KeyWait, Lbutton
		CoordMode, mouse, Relative
		MouseGetPos, x,y
		XClose:= SCW_Reg("G" A_Gui "#XClose"), YClose:= SCW_Reg("G" A_Gui "#YClose")
		if (x > XClose and y < YClose)
			Gui %A_Gui%: Destroy
		return 1 ; confirm that click was on module's screen clipping windows
	}
}

SCW_Reg(variable, value="") {
	static
	if (value = "") {
		yaqxswcdevfr:= kxucfp%variable%pqzmdk
		Return yaqxswcdevfr
	} else
		kxucfp%variable%pqzmdk = %value%
}

SCW_Default(ByRef Variable,DefaultValue) {
	if (Variable="")
		Variable:= DefaultValue
}

CreateClass(string, interface, ByRef Class) {
	CreateHString(string, hString)
	VarSetCapacity(GUID, 16)
	DllCall("ole32\CLSIDFromString", "wstr", interface, "ptr", &GUID)
	result:= DllCall("Combase.dll\RoGetActivationFactory", "ptr", hString, "ptr", &GUID, "ptr*", Class)
	if (result != 0) {
		if (result = 0x80004002)
			MsgBox No such interface supported
		else if (result = 0x80040154)
			MsgBox Class not registered
		else
			MsgBox error: %result%
		ExitApp
	}
	DeleteHString(hString)
}

CreateHString(string, ByRef hString) {
	DllCall("Combase.dll\WindowsCreateString", "wstr", string, "uint", StrLen(string), "ptr*", hString)
}

DeleteHString(hString) {
	DllCall("Combase.dll\WindowsDeleteString", "ptr", hString)
}

WaitForAsync(Object, ByRef ObjectResult) {
	AsyncInfo:= ComObjQuery(Object, IAsyncInfo:= "{00000036-0000-0000-C000-000000000046}")
	loop	{
		DllCall(NumGet(NumGet(AsyncInfo+0)+7*A_PtrSize), "ptr", AsyncInfo, "uint*", status)   ; IAsyncInfo.Status
		if (status != 0) {
			if (status != 1) {
				MsgBox AsyncInfo status error.
				ExitApp
			}
			ObjRelease(AsyncInfo)
			AsyncInfo:= ""
			break
		}
		Sleep, 10
	}
	DllCall(NumGet(NumGet(Object+0)+8*A_PtrSize), "ptr", Object, "ptr*", ObjectResult)   ; GetResults
}

HBitmapToRandomAccessStream(hBitmap) {
	static IID_IRandomAccessStream:= "{905A0FE1-BC53-11DF-8C49-001E4FC686DA}", IID_IPicture:= "{7BF80980-BF32-101A-8BBB-00AA00300CAB}", PICTYPE_BITMAP:= 1, BSOS_DEFAULT  := 0
	DllCall("Ole32\CreateStreamOnHGlobal", "Ptr", 0, "UInt", true, "PtrP", pIStream, "UInt")

	VarSetCapacity(PICTDESC, sz:= 8 + A_PtrSize*2, 0)
	NumPut(sz, PICTDESC)
	NumPut(PICTYPE_BITMAP, PICTDESC, 4)
	NumPut(hBitmap, PICTDESC, 8)
	riid:= CLSIDFromString(IID_IPicture, GUID1)
	DllCall("OleAut32\OleCreatePictureIndirect", "Ptr", &PICTDESC, "Ptr", riid, "UInt", false, "PtrP", pIPicture, "UInt")
	; IPicture::SaveAsFile
	DllCall(NumGet(NumGet(pIPicture+0) + A_PtrSize*15), "Ptr", pIPicture, "Ptr", pIStream, "UInt", true, "UIntP", size, "UInt")
	riid:= CLSIDFromString(IID_IRandomAccessStream, GUID2)
	DllCall("ShCore\CreateRandomAccessStreamOverStream", "Ptr", pIStream, "UInt", BSOS_DEFAULT, "Ptr", riid, "PtrP", pIRandomAccessStream, "UInt")
	ObjRelease(pIPicture)
	ObjRelease(pIStream)
	return pIRandomAccessStream
}

CLSIDFromString(IID, ByRef CLSID) {
	VarSetCapacity(CLSID, 16, 0)
	if res:= DllCall("ole32\CLSIDFromString", "WStr", IID, "Ptr", &CLSID, "UInt")
		Throw Exception("CLSIDFromString failed. Error: " . Format("{:#x}", res))
	return &CLSID
}

OCR(IRandomAccessStream, language:= "en") {
	static OcrEngineClass, OcrEngineObject, MaxDimension, LanguageClass, LanguageObject, CurrentLanguage, StorageFileClass, BitmapDecoderClass
	if (OcrEngineClass = "")	{
		CreateClass("Windows.Globalization.Language", ILanguageFactory:= "{9B0252AC-0C27-44F8-B792-9793FB66C63E}", LanguageClass)
		CreateClass("Windows.Graphics.Imaging.BitmapDecoder", IStorageFileStatics:= "{438CCB26-BCEF-4E95-BAD6-23A822E58D01}", BitmapDecoderClass)
		CreateClass("Windows.Media.Ocr.OcrEngine", IOcrEngineStatics:= "{5BFFA85A-3384-3540-9940-699120D428A8}", OcrEngineClass)
		DllCall(NumGet(NumGet(OcrEngineClass+0)+6*A_PtrSize), "ptr", OcrEngineClass, "uint*", MaxDimension)   ; MaxImageDimension
	}
	if (CurrentLanguage != language) {
		if (LanguageObject != "") {
			ObjRelease(LanguageObject)
			ObjRelease(OcrEngineObject)
			LanguageObject:= OcrEngineObject:= ""
		}
		CreateHString(language, hString)
		DllCall(NumGet(NumGet(LanguageClass+0)+6*A_PtrSize), "ptr", LanguageClass, "ptr", hString, "ptr*", LanguageObject)   ; CreateLanguage
		DeleteHString(hString)
		DllCall(NumGet(NumGet(OcrEngineClass+0)+9*A_PtrSize), "ptr", OcrEngineClass, ptr, LanguageObject, "ptr*", OcrEngineObject)   ; TryCreateFromLanguage
		if (OcrEngineObject = 0) {
			MsgBox Can not use language "%language%" for OCR, please install language pack.
			ExitApp
		}
		CurrentLanguage:= language
	}
	DllCall(NumGet(NumGet(BitmapDecoderClass+0)+14*A_PtrSize), "ptr", BitmapDecoderClass, "ptr", IRandomAccessStream, "ptr*", BitmapDecoderObject)   ; CreateAsync
	WaitForAsync(BitmapDecoderObject, BitmapDecoderObject1)
	BitmapFrame:= ComObjQuery(BitmapDecoderObject1, IBitmapFrame:= "{72A49A1C-8081-438D-91BC-94ECFC8185C6}")
	DllCall(NumGet(NumGet(BitmapFrame+0)+12*A_PtrSize), "ptr", BitmapFrame, "uint*", width)   ; get_PixelWidth
	DllCall(NumGet(NumGet(BitmapFrame+0)+13*A_PtrSize), "ptr", BitmapFrame, "uint*", height)   ; get_PixelHeight
	if (width > MaxDimension) or (height > MaxDimension) {
		MsgBox Image is too big - %width%x%height%.`nIt should be maximum - %MaxDimension% pixels
		ExitApp
	}
	SoftwareBitmap:= ComObjQuery(BitmapDecoderObject1, IBitmapFrameWithSoftwareBitmap:= "{FE287C9A-420C-4963-87AD-691436E08383}")
	DllCall(NumGet(NumGet(SoftwareBitmap+0)+6*A_PtrSize), "ptr", SoftwareBitmap, "ptr*", BitmapFrame1)   ; GetSoftwareBitmapAsync
	WaitForAsync(BitmapFrame1, BitmapFrame2)
	DllCall(NumGet(NumGet(OcrEngineObject+0)+6*A_PtrSize), "ptr", OcrEngineObject, ptr, BitmapFrame2, "ptr*", OcrResult)   ; RecognizeAsync
	WaitForAsync(OcrResult, OcrResult1)
	DllCall(NumGet(NumGet(OcrResult1+0)+6*A_PtrSize), "ptr", OcrResult1, "ptr*", lines)   ; get_Lines
	DllCall(NumGet(NumGet(lines+0)+7*A_PtrSize), "ptr", lines, "int*", count)   ; count
	loop, % count {
		DllCall(NumGet(NumGet(lines+0)+6*A_PtrSize), "ptr", lines, "int", A_Index-1, "ptr*", OcrLine)
		DllCall(NumGet(NumGet(OcrLine+0)+7*A_PtrSize), "ptr", OcrLine, "ptr*", hText)
		buffer:= DllCall("Combase.dll\WindowsGetStringRawBuffer", "ptr", hText, "uint*", length, "ptr")
		text .= StrGet(buffer, "UTF-16") "`n"
		ObjRelease(OcrLine)
		OcrLine:= ""
	}
	ObjRelease(BitmapDecoderObject)
	ObjRelease(BitmapDecoderObject1)
	ObjRelease(SoftwareBitmap)
	ObjRelease(BitmapFrame)
	ObjRelease(BitmapFrame1)
	ObjRelease(BitmapFrame2)
	ObjRelease(OcrResult)
	ObjRelease(OcrResult1)
	ObjRelease(lines)
	BitmapDecoderObject:= BitmapDecoderObject1:= SoftwareBitmap:= BitmapFrame:= BitmapFrame1:= BitmapFrame2:= OcrResult:= OcrResult1:= lines:= ""
	return text
} ; Made by teadrinker
Kingron
Posts: 9
Joined: 22 May 2023, 19:47

Re: Screen clipping

22 Apr 2024, 01:01

Gorgrak wrote:
21 Apr 2024, 23:47
OH you right. I HEAVILY modified mine to suit my own tastes:
Many Thanks, After I update gdip.ahk to gdip_all.ahk, all works fine. The old gdip.ahk have some issue to support AHK 64
Thank you very much.
User avatar
Gorgrak
Posts: 26
Joined: 07 Dec 2015, 16:34

Re: Screen clipping

22 Apr 2024, 02:03

Nice! Glad it happened to help solve your conundrum!

Return to “Scripts and Functions (v1)”

Who is online

Users browsing this forum: Archimede and 56 guests