Screen clipping

Post your working scripts, libraries and tools for AHK v1.1 and older
User avatar
SpeedMaster
Posts: 494
Joined: 12 Nov 2016, 16:09

Re: Screen clipping

Post by SpeedMaster » 26 Feb 2023, 16:35

[PLUGIN] Always On Bottom v1.2

Usage:
Press PageDown to make selected clip image not more always on top.
Press PageUp to make selected clip image always on top.

how to install this plugin ?
1° download FG ScreenClipper v1.2+ at viewtopic.php?p=506077#p506077
2° put this plugin in the Lib folder of the main RUN script
2° insert this line " #Include SM_AlwaysOnBottom.ahk " in the INCLUDE SECTION of the main script ---> RUN_ScreenCLip.ahk

Internal default shortcut:
Press PageDown to send current clip to bottom.
Press PageUp to restore current clip to always on top.

Note: you can always change the keyboard shortcut by the one you like, taking care not to conflict with the shortcuts of other plugins

File Name: SM_AlwaysOnBottom.ahk

Code: Select all

/*--------------------------------------------------------------------------------------------------------------------
[Plugin] Always On Bottom (by Speedmaster)
File Name : SM_AlwaysOnBottom.ahk
usage: press PageDown to make selected clip not more always on top
version: 1.2
topic: https://www.autohotkey.com/boards/viewtopic.php?p=506077#p506077
Help:
how to install this plugin ?
1° download FG ScreenClipper at https://www.autohotkey.com/boards/viewtopic.php?p=506077#p506077
2° put this script plugin SM_AlwaysOnBottom.ahk in the Lib folder of the main RUN script
3° insert "#Include SM_AlwaysOnBottom.ahk" in the INCLUDE SECTION of the main RUN script 

Note this plugin has internal default shortcuts (see below) that you can change 
or migrate in the #ifwinactive section of the main run script
*/---------------------------------------------------------------------------------------------------------------------

; DEFAULT SHORTCUTS ---------------------------------------------------
#IfWinActive, ScreenClipperWindow ahk_class AutoHotkeyGUI
PGDN::SM_AlwaysOnBottom()
PGUP::SM_AlwaysOnTop()
#IfWinActive


SM_AlwaysOnBottom(){
WinGet, Hwnd, ID, A
MaxGuis := SCW_Reg("MaxGuis"), i := SCW_Reg("StartAfter")
j:=MaxGuis+i
	Loop % MaxGuis {
		if (SCW_Reg("G" --j "#HWND") = hwnd) {
			currentgui := j
			break
		}
	}
	Gui %currentgui%: -AlwaysOnTop
}

SM_AlwaysOnTop(){
WinGet, Hwnd, ID, A
MaxGuis := SCW_Reg("MaxGuis"), i := SCW_Reg("StartAfter")
j:=MaxGuis+i
	Loop % MaxGuis {
		if (SCW_Reg("G" --j "#HWND") = hwnd) {
			currentgui := j
			break
		}
	}
	Gui %currentgui%: +AlwaysOnTop
}
Cheers
Last edited by SpeedMaster on 17 Mar 2023, 05:46, edited 2 times in total.

User avatar
SpeedMaster
Posts: 494
Joined: 12 Nov 2016, 16:09

Re: Screen clipping

Post by SpeedMaster » 27 Feb 2023, 08:00

[PLUGIN] Resizer v1.5

Usage:
Resize selected clip image with the mouse wheel.

function:
sm_resize(dir:=1, step:="0.1")
set dir=1 to scale up and dir=-1 to scale down
the function returns the scaling value in percent

autors:
Iseahound (imageput)
Speedmaster (plugin)

how to install this plugin ?
1° download FG ScreenClipper at viewtopic.php?p=506077#p506077
2° download "ImagePut (for v1).ahk" library at https://github.com/iseahound/ImagePut/archive/refs/heads/master.zip
3° rename it "ImagePut.ahk" and put it in the Lib folder of the main RUN script ---> RUN_ScreenCLip.ahk
4° put the script plugin SM_Resizer.ahk in the Lib folder of the main RUN script
5° insert '#Include SM_Resizer.ahk' in the 'include section' of the main RUN script

Internal default shortcut:
Press Ctrl + MouseWheel to resize selected clip image with the mouse.
Press Ctrl + Numpad Add/Sub to resize selected clip image with the keyboard.

Note: this plugin use cached images stored in the "\temp" folder in the script directroy. The cache folder is cleared at startup and on exit.

File Name: SM_Resizer.ahk

Code: Select all

/*--------------------------------------------------------------------------------------------------------------------
Resizer Plugin (by Speedmaster)
File Name : SM_Resize.ahk
usage: press Ctrl and resize the clip image with the mouse wheel
version: 1.5
topic: https://www.autohotkey.com/boards/viewtopic.php?p=506077#p506077
Help:
how to install this plugin ?
1° download FG ScreenClipper at https://www.autohotkey.com/boards/viewtopic.php?p=506077#p506077
2° download "ImagePut (for v1).ahk" library  at https://github.com/iseahound/ImagePut/archive/refs/heads/master.zip
3° rename it "ImagePut.ahk" and put it in the Lib folder of the main RUN script ---> RUN_ScreenCLip.ahk
4° put the script plugin SM_Resize.ahk in the Lib folder of the main RUN script
5° insert '#Include SM_Resize.ahk' in the 'include section' of the main RUN script 

Note this plugin has internal default shortcuts (see below) that you can change 
or migrate in the #ifwinactive section of the main run script
*/---------------------------------------------------------------------------------------------------------------------

#include ImagePut.ahk   ; ( for v1) (by iseahound)


; DEFAULT SHORTCUTS ---------------------------------------------------
#IfWinActive, ScreenClipperWindow ahk_class AutoHotkeyGUI
^NumpadAdd::
^wheelup::
tooltip % sm_resize(1)
return
^NumpadSub::
^wheeldown::
tooltip, % sm_resize(-1)
return

~ctrl up::
tooltip
return
#IfWinActive
;--------------------------------------------------------------


; FUNCTIONS 
;------------------------------------- Resize Up/Down current clip ------------------------------------------------
; HELP:
;dir=  1  resize up
;dir= -1  resize down
; the function returns the scaling value in percent

sm_resize(dir:=1,step:="0.1"){  
	global zlist
	(!CacheFolder)&&CacheFolder:="temp"

	IfNotExist, %CacheFolder%
		FileCreateDir, %CacheFolder%
		if (ErrorLevel){
			CacheFolder:=A_temp
		}
	
	WinGet, Hwnd, ID, A
	MaxGuis := SCW_Reg("MaxGuis"), i := SCW_Reg("StartAfter")		
	Loop % MaxGuis {
		if (SCW_Reg("G" ++i "#HWND") = hwnd) {
			currentgui := i
			break
		}
	}	

	WinSet, Region, , A   ; restore hidden borders (if any) before writing image in gui
	WinGetPos, X, Y, W, H,  ahk_id %Hwnd%
	X+=3, Y+=3, W-=6, H-=6
	sc:=zlist["Scaled", currentgui]
	(!sc)&&sc:=1
	
	imageput.gdiplusstartup()

	img:=CacheFolder "\" currentgui ".png"
	if (!FileExist(img)) {
		pBitmap_ := Gdip_BitmapFromScreen(X "|" Y "|" W "|" H)
		FileName := currentgui ".PNG"
		Gdip_SaveBitmapToFile(pBitmap_, CacheFolder "\" FileName)
		Gdip_DisposeImage(pBitmap_)
		img:=CacheFolder "\" FileName
		sc:=1
	}

	if (dir>0){	
		(!sc)?(sc:=1):(sc:=sc+step)
		(!zlist["Scaled",currentgui])&&zlist["Scaled",currentgui]:=1
		zlist["Scaled",currentgui]:=sc
	}
	if (dir<0){
		(!sc)?(sc:=1):((sc<=0.1)?(sc:=0.1):(sc:=sc-step))
		(!zlist["Scaled",currentgui])&&zlist["Scaled",currentgui]:=1		
		zlist["Scaled",currentgui]:=sc
	}
	
	gb:=ImagePutBitmap(img)
	imageput.BitmapScale(gb, sc)
	SCW_CreateLayeredWinMod(currentgui,gb,x,y)
	Gdip_DisposeImage(gb)
	imageput.gdiplusShutdown()

return round(sc*100) " %"
}


ClearCacheFolder(){
	global zlist, cachefolder
     zlist:={}
     loop 99 
	 FileDelete, % CacheFolder "\" a_index ".png"
}

DeleteCachedImage(name){
	global CacheFolder
	FileDelete, % CacheFolder "\" name ".png"
}
Cheers
Attachments
resizer.png
resizer.png (377.48 KiB) Viewed 4730 times
Last edited by SpeedMaster on 14 Mar 2023, 15:24, edited 5 times in total.

Avastgard
Posts: 133
Joined: 30 Sep 2016, 21:54

Re: Screen clipping

Post by Avastgard » 27 Feb 2023, 11:04

You're on a roll, @SpeedMaster! Nice to see so many plugins rolling out so often! Thanks for your effort!

User avatar
SpeedMaster
Posts: 494
Joined: 12 Nov 2016, 16:09

Re: Screen clipping

Post by SpeedMaster » 27 Feb 2023, 16:48

@Avastgard Thanks for the feedback. I still have other plugins in progress. ;)

I upgraded the SM_RotateFlip plugin to version 1.4 so that it also uses images from the temp folder.
:arrow: viewtopic.php?f=6&t=12088&start=240#p506431

User avatar
SpeedMaster
Posts: 494
Joined: 12 Nov 2016, 16:09

Re: Screen clipping

Post by SpeedMaster » 02 Mar 2023, 05:45

[PLUGIN] GK OCR v1.1 (Win 10+ only)

Usage:
Select a clip text image and press Y to use built-in OCR of Windows 10+ to send text to the clipboard.

how to install this plugin ?
1° download FG ScreenClipper v1.4+ at viewtopic.php?p=506077#p506077
2° put GK_OCR.ahk plugin script in the Lib folder of the main RUN script
3° insert this line " #Include GK_OCR.ahk " in the INCLUDE SECTION of the main script ---> RUN_ScreenCLip.ahk

Internal default shortcut:
Press Y to use windows 10+ built-in OCR.

Plugin Function:
GK_Win2OCR(lang:="en") ... you can choose a pre-installed language pack of windows10

Note: you can always change the keyboard shortcut by the one you like, taking care not to conflict with the shortcuts of other plugins

File Name: GK_OCR.ahk

Code: Select all

/*--------------------------------------------------------------------------------------------------------------------
[Plugin] GK_OCR (Win 10+) (by Gorgrak/Speedmaster)
File Name : GK_OCR.ahk
version: 1.1  2023 04 23
usage: select a clip text and press " Y " to use built-in OCR in Windows 10 to copy text to the clipboard.
topic: https://www.autohotkey.com/boards/viewtopic.php?p=506077#p506077
credits: Plugin: Gorgrak, Speedmaster  OCR: malcev, teadrinker, joe glines, Jackie 

Help:
how to install this plugin ?
1° download FG ScreenClipper at https://www.autohotkey.com/boards/viewtopic.php?p=506077#p506077
2° put this script plugin GK_OCR.ahk in the Lib folder of the main RUN script
3° insert "#Include GK_OCR.ahk" in the INCLUDE SECTION of the main RUN script 

Note this plugin has internal default shortcuts (see below) that you can change 
or migrate in the #ifwinactive section of the main run script
*/---------------------------------------------------------------------------------------------------------------------


; DEFAULT SHORTCUTS ---------------------------------------------------
#IfWinActive, ScreenClipperWindow ahk_class AutoHotkeyGUI
y::GK_Win2OCR()          ; Press Y to use built-in Win10+ OCR
#IfWinActive


; PLUGIN FUNCTION -----------------------------------------------------
GK_Win2OCR(lang:="en") {
	;Send, !{PrintScreen} ; Active Win's client area to Clipboard
	WinGet, hwnd, ID, ahk_class AutoHotkeyGUI
	Loop 99 {
		Gui %A_Index%: +LastFound
		if WinExist() = hwnd {
			currentgui := A_Index
			break
		}
	}
	winGetPos, X, Y, W, H, ahk_id %Hwnd%
	x:=x+3, y:=y+3, w:=w-6, h:=h-6
	pToken := Gdip_Startup()
	pBitmap := Gdip_BitmapFromScreen(X "|" Y "|" W "|" H)	
	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, lang)
	ObjRelease(pIRandomAccessStream)
	tooltip, %  clipboard
	Sleep, 4000
	ToolTip
	Gdip_DisposeImage(pBitmap)
	Gdip_Shutdown(pToken) ; clear selection
}


; OTHER FUNCTIONS -----------------------------------------------------

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%
			Reload
	}
	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
}

;********************teadrinker OCR ***********************************
OCR(IRandomAccessStream, language := "en"){
	static OcrEngineClass, OcrEngineObject, MaxDimension, LanguageClass, LanguageObject, CurrentLanguage, StorageFileClass, BitmapDecoderClass
	static rlangList := {"ar":"Arabic (Saudi Arabia)","bg":"Bulgarian (Bulgaria)","zh":"Chinese (Hong Kong S.A.R.)","zh":"Chinese (PRC)","zh":"Chinese (Taiwan)","hr":"Croatian (Croatia)","cs":"Czech (Czech Republic)","da":"Danish (Denmark)","nl":"Dutch (Netherlands)","En":"English (Great Britain)","en":"English (United States)","et":"Estonian (Estonia)","fi":"Finnish (Finland)","fr":"French (France)","de":"German (Germany)","el":"Greek (Greece)","he":"Hebrew (Israel)","hu":"Hungarian (Hungary)","it":"Italian (Italy)","ja":"Japanese (Japan)","ko":"Korean (Korea)","lv":"Latvian (Latvia)","lt":"Lithuanian (Lithuania)","nb":"Norwegian, Bokmål (Norway)","pl":"Polish (Poland)","pt":"Portuguese (Brazil)","pt":"Portuguese (Portugal)","ro":"Romanian (Romania)","ru":"Russian (Russia)","sr":"Serbian (Latin, Serbia)","sr":"Serbian (Latin, Serbia)","sk":"Slovak (Slovakia)","sl":"Slovenian (Slovenia)","es":"Spanish (Spain)","sv":"Swedish (Sweden)","th":"Thai (Thailand)","tr":"Turkish (Turkey)","uk":"Ukrainian (Ukraine)"}

	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){
			Run % "ms-settings:regionlanguage"
			MsgBox % 0x10, % "OCR Error"
						 , % "Can not use language """ rlangList[language] """ for OCR, please install the corresponding language pack."
			return "error"
		}
		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 to big - %width%x%height%.`nIt should be maximum - %MaxDimension% pixels
		return
	}
	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
}

Cheers
Last edited by SpeedMaster on 23 Apr 2023, 13:22, edited 1 time in total.

User avatar
SpeedMaster
Posts: 494
Joined: 12 Nov 2016, 16:09

Re: Screen clipping

Post by SpeedMaster » 11 Mar 2023, 13:34

New update for the main files : V1.5 :arrow: viewtopic.php?p=506077#p506077
  • Added "headers" and "footers" for the Include Section in RUN_ScreenCLip
  • Fixed bug in FG_screenclip (cached image not removed when creating new clip).
  • Added new item in fG_context_clip_menu to open saved image folder.
New update for the Resizer: V1.4 :arrow: viewtopic.php?f=6&t=12088&start=260#p509598
  • Added line Gdip_Shutdown("pToken") to close gdip
  • Now the function sm_resize() returns the scaling value in percent
New update for the grayscale: V1.3.02 :arrow: viewtopic.php?f=6&t=12088&start=260#p511867
  • Added line Gdip_Shutdown("pToken") to close gdip
New update for the RotateFlip: V1.5 :arrow: viewtopic.php?f=6&t=12088&start=240#p506431
  • Added line Gdip_Shutdown("pToken") to close gdip
Regards
Last edited by SpeedMaster on 14 Mar 2023, 15:30, edited 8 times in total.

User avatar
SpeedMaster
Posts: 494
Joined: 12 Nov 2016, 16:09

Re: Screen clipping

Post by SpeedMaster » 11 Mar 2023, 13:53

[PLUGIN] Grayscale v1.5

Usage: Press G to toggle grayscale for selected image.

how to install this plugin ?
1° download FG ScreenClipper at viewtopic.php?p=506077#p506077
2° put this plugin in the Lib folder of the main script
3° Install plugin SM_Resizer.ahk at viewtopic.php?p=509598#p509598
4° insert this line "#Include SM_Grayscale.ahk" in the INCLUDE SECTION of the main script ---> RUN_ScreenCLip.ahk

Internal default shortcut:
Press G to toggle grayscale.

Credits: Xtra (grayscale function), Speedmaster (plugin), Bentchi (mcode function), Iseahound (ImagePut library)

Note:
  • the plugin requires the SM_resizer.ahk plugin to be installed but it can also work in standalone by disabling the function call for resizing
  • the plugin use cached images to restore colored state. The cache folder is cleared at startup and on exit.
  • Use the duplicate if you want a permanent grey image.


File Name: SM_Grayscale.ahk

Code: Select all

/*--------------------------------------------------------------------------------------------------------------------
[Plugin] Grayscale (by Speedmaster)
File Name : SM_grayscale.ahk
version: 1.5
credits:
     Speedmaster (plugin)
	 Xtra        (grayscale function)
	 Bentchi     (mcode function)
	 Iseahound   (ImagePut library)

topic: https://www.autohotkey.com/boards/viewtopic.php?p=506077#p506077
Help:
how to install this plugin ?
1° download FG ScreenClipper at https://www.autohotkey.com/boards/viewtopic.php?p=506077#p506077
2° put this plugin in the Lib folder of the main script
3° Install plugin SM_Resizer.ahk at https://www.autohotkey.com/boards/viewtopic.php?p=509598#p509598
4° insert "#Include SM_Grayscale.ahk" in the INCLUDE SECTION of the main script ---> RUN_ScreenCLip.ahk

Note this plugin has internal default shortcuts (see below) that you can change 
or migrate in the #ifwinactive section of the main run script
*/---------------------------------------------------------------------------------------------------------------------

; DEFAULT SHORTCUTS ---------------------------------------------------
#IfWinActive, ScreenClipperWindow ahk_class AutoHotkeyGUI
g::sm_grayscale()              ; Press G to toggle grayscale
#IfWinActive


sm_grayscale(){
global zlist, cachefolder 	
	
WinGet, Hwnd, ID, A
WinSet, Region, , A   ; restore hidden borders (if any) before writing image in gui
	WinGetPos, X, Y, W, H,  ahk_id %Hwnd%
		 X+=3, Y+=3, W-=6, H-=6	

MaxGuis := SCW_Reg("MaxGuis"), i := SCW_Reg("StartAfter")		
	Loop % MaxGuis {
		if (SCW_Reg("G" ++i "#HWND") = hwnd) {
			currentgui := i
			break
		}
	}
if !currentgui
	return

imageput.gdiplusstartup()

pBitmap := Gdip_BitmapFromScreen(X "|" Y "|" W "|" H)

(!CacheFolder)&&CacheFolder:="temp"
IfNotExist, %CacheFolder%
   FileCreateDir, %CacheFolder%
     if (ErrorLevel){
	 CacheFolder:=A_temp
    }

img:=CacheFolder "\" currentgui ".png"
if (!FileExist(img)) {
	for i, j in zlist {
		for k, l in j {
			if (k=currentgui)
				zlist[i,k]:=""
		}
	}
	FileName := currentgui ".PNG"
	Gdip_SaveBitmapToFile(pBitmap, CacheFolder "\" FileName)
	img:=CacheFolder "\" FileName
}

if !(zlist["grayed",currentgui]) {
	zlist["grayed",currentgui]:=true	
	pBitmap:=Gdip_CreateBitmapFromFileSimplified(img, useICM:=0)
	Gdip_GrayScale(pBitmap)

	if (zlist["Scaled"][currentgui]) {
		sc:=zlist["Scaled",currentgui]
		imageput.BitmapScale(pBitmap, sc)                             ; imageput.ahk (for v.1) library (by iseahound)
	}
	hwnd := SCW_CreateLayeredWinMod(currentgui,pBitmap,X,Y)
}	

else if (zlist["grayed",currentgui]) {
	
	zlist["grayed",currentgui]:=false	

    gb:=ImagePutBitmap(img)
	if !(zlist["Scaled"][currentgui])
	   hwnd := SCW_CreateLayeredWinMod(currentgui,gb,x,y)

	if (zlist["Scaled"][currentgui]) {
	    sm_resize("1","0")                                              ; desactivate if SM_resiser.ahk plugin is not installed
	}
}

	Gdip_DisposeImage(pBitmap)
	imageput.gdiplusShutdown()
}


;--------------------------------------------------------------
; by Xtra
; https://www.autohotkey.com/boards/viewtopic.php?t=83208
Gdip_GrayScale(pBitmap)
{
	static GrayScaleMCode
	if (GrayScaleMCode = "")
	{
		if (A_PtrSize = 4) ; (32bit)
        {
            MCode := ""
			. "2,x86:VVdWU4PsCItMJCiLVCQgjUEDhckPScGLTCQkwfgChcl+"
			. "f4XSfnvB4AKLfCQcMe2JRCQEjQSVAAAAAIkEJI12AIsEJIn7jT"
			. "Q4kI20JgAAAACLE4PDBInQD7bOwegQD7bAacndAgAAacDZAAAA"
			. "AcgPtsqB4gAAAP9ryUoByMHoConBCcLB4AjB4RAJygnQiUP8Od"
			. "51vIPFAQN8JAQ5bCQkdZ+DxAgxwFteX13D"
        }
        else ; A_PtrSize = 8 (64bit)
        {
            mCode := ""
			. "2,x64:QVdBVkFVQVRVV1ZTSIPsOA8pdCQgQY1BA0WFyUEPScHB"
			. "+AJFhcCJRCQYD46ABAAAhdIPjngEAABIY0QkGEiJzkUx5EG7Aw"
			. "AAADHtSImMJIAAAABmD28dAAAAAEiJRCQQSMHgAkiJRCQIjUL/"
			. "Zg9vJRAAAACJRCQcZg9vLSAAAADp+QMAAEGJ0oseidgPts/B6B"
			. "APtsBEacndAgAAacDZAAAARAHIRA+2y4HjAAAA/0VryUpEAcjB"
			. "6ApBicEJw8HgCEHB4RBECcsJw0GD+gG4AQAAAIkeD4Q5AQAASI"
			. "uMJIAAAABBjUP+SJhIjRyBRIsLRInIRInJwegQD7bND7bARGnp"
			. "3QIAAGnA2QAAAEQB6EUPtulBgeEAAAD/RWvtSkQB6MHoCkGJxU"
			. "EJwcHgCEHB5RBFCelBCcFBg/oCuAIAAABEiQsPhMsAAABIi4wk"
			. "gAAAAEGNQ/9ImEiNHIFEiwtEichEicnB6BAPts0PtsBEaendAg"
			. "AAacDZAAAARAHoRQ+26UGB4QAAAP9Fa+1KRAHowegKQYnFQQnB"
			. "weAIQcHlEEUJ6UEJwUGD+gS4AwAAAESJC3VhSIuMJIAAAABJY8"
			. "NIjRyBRIsLRInID7bERGno3QIAAESJyMHoEA+2wGnA2QAAAEQB"
			. "6EUPtulBgeEAAAD/RWvtSkQB6MHoCkGJxUEJwcHgCEHB5RBFCe"
			. "lBCcG4BAAAAESJC0Q50g+ESgIAAEGJ1otMJBxEidNFKdZFjU78"
			. "RCnRQcHpAkGDwQGD+QJGjTyNAAAAAA+G6gAAAEiLjCSAAAAATA"
			. "HjRTHSTI0smTHbZkMPb0QVAIPDAWYPb8hmD2/wZg9y0RBmD9vL"
			. "Zg9y1ghmD9vzZg9v0WYPcvIDZg/60WYPb8pmD3LxBWYP+spmD2"
			. "/RZg9vzmYPc9YgZg/09GYPcPYIZg/0zGYPcMkIZg9izmYP/spm"
			. "D2/QZg/bxWYP29NmD2/yZg9y9gNmD/7yZg9y9gJmD/7WZg9y8g"
			. "FmD/7KZg9y0QpmD+vBZg9v0WYPcvEIZg9y8hBmD+vCZg/ryEMP"
			. "KUwVAEmDwhBEOcsPgj7///9EAfhFOfdIiYwkgAAAAA+EMwEAAE"
			. "iLjCSAAAAARI0MOE1jyUqNHIlEixNFidFEidFBwekQD7bNRQ+2"
			. "yURp6d0CAABFacnZAAAARQHpRQ+26kGB4gAAAP9Fa+1KRQHpQc"
			. "HpCkWJzUUJykHB4QhBweUQRQnqRQnKRI1IAUSJE0Q5yg+OwQAA"
			. "AEiLjCSAAAAAQQH5g8ACTWPJSo0ciUSLE0WJ0USJ0UHB6RAPts"
			. "1FD7bJRGnp3QIAAEVpydkAAABFAelFD7bqQYHiAAAA/0Vr7UpF"
			. "AelBwekKRYnNRQnKQcHhCEHB5RBFCepFCco5wkSJE35WAfhIi7"
			. "wkgAAAAEiYTI0Mh0GLGQ+2x0Rp0N0CAACJ2MHoEA+2wGnA2QAA"
			. "AEQB0EQPttOB4wAAAP9Fa9JKRAHQwegKQYnCCcPB4AhBweIQRA"
			. "nTCdhBiQGDxQFIA3QkCEQDXCQYTANkJBBBOeh0MkmJ8kGNe/1J"
			. "weoCSffaQYPiA0E50kQPR9KD+gQPjuX7//9FhdIPhd/7//8xwO"
			. "lt/f//Dyh0JCAxwEiDxDhbXl9dQVxBXUFeQV/DkJCQkJCQkJD/"
			. "AAAA/wAAAP8AAAD/AAAA3QIAAN0CAADdAgAA3QIAAAAAAP8AAA"
			. "D/AAAA/wAAAP8="
        }
		GrayScaleMCode := MCode(mCode)
    }
	
    Gdip_GetImageDimensions(pBitmap, w, h)
	if !(w && h)
		return -1

	if (E1 := Gdip_LockBits(pBitmap, 0, 0, w, h, stride, scan, bitmapData))
		return -2
    
	E := DllCall(GrayScaleMCode, "uint", scan, "int", w, "int", h, "int", stride, "cdecl")
    
	Gdip_UnlockBits(pBitmap, bitmapData)
	
	return (E = "") ? -3 : E
}

MCode(mcode)    ; <Bentchi function>
{
    static e := {1:4, 2:1}, c := (A_PtrSize=8) ? "x64" : "x86"
    if (!regexmatch(mcode, "^([0-9]+),(" c ":|.*?," c ":)([^,]+)", m))
        return
    if (!DllCall("crypt32\CryptStringToBinary", "str", m3, "uint", 0, "uint", e[m1], "ptr", 0, "uint*", s, "ptr", 0, "ptr", 0))
        return
    p := DllCall("GlobalAlloc", "uint", 0, "ptr", s, "ptr")
    if (c="x64")
        DllCall("VirtualProtect", "ptr", p, "ptr", s, "uint", 0x40, "uint*", op)
    if (DllCall("crypt32\CryptStringToBinary", "str", m3, "uint", 0, "uint", e[m1], "ptr", p, "uint*", s, "ptr", 0, "ptr", 0))
        return p
    DllCall("GlobalFree", "ptr", p)
}

Cheers
Last edited by SpeedMaster on 14 Mar 2023, 15:24, edited 1 time in total.

User avatar
SpeedMaster
Posts: 494
Joined: 12 Nov 2016, 16:09

Re: Screen clipping

Post by SpeedMaster » 13 Mar 2023, 03:42

[PLUGIN] Move Clip v1.0

Usage:
Move the clip image with arrow cursors.

how to install this plugin ?
1° download FG ScreenClipper at viewtopic.php?p=506077#p506077
2° put this plugin in the Lib folder of the main script
3° insert "#Include SM_MoveClip.ahk" in the INCLUDE SECTION (footers) of the main script ---> RUN_ScreenCLip.ahk

Internal default shortcuts:
Press arrow keys or Ctrl + arrow keys to move the clip image by 10 or 1 pixel

Note: you can always change the keyboard shortcut by the one you like, taking care not to conflict with the shortcuts of other plugins

File Name: SM_MoveClip.ahk

Code: Select all

/*--------------------------------------------------------------------------------------------------------------------
[Plugin] Move Clip (by Speedmaster)
File Name : SM_MoveClip.ahk
version: 1.0
topic: https://www.autohotkey.com/boards/viewtopic.php?p=506077#p506077
Help:
how to install this plugin ?
1° download FG ScreenClipper at https://www.autohotkey.com/boards/viewtopic.php?p=506077#p506077
2° put this plugin in the Lib folder of the main script
3° insert "#Include SM_MoveClip.ahk" in the INCLUDE SECTION (footers) of the main script ---> RUN_ScreenCLip.ahk

Note this plugin has internal default shortcuts (see below) that you can change 
or migrate in the #ifwinactive section of the main run script
*/---------------------------------------------------------------------------------------------------------------------


; DEFAULT SHORTCUTS ---------------------------------------------------

; Press arrow keys or Ctrl + arrow keys to move the clip by 10 or 1 pixel

#IfWinActive, ScreenClipperWindow ahk_class AutoHotkeyGUI
right::
	wingetpos x, y,,, A
	x += 10
	winmove, A,,%x%, %y%
	return
left::
	wingetpos x, y,,, A
	x -= 10
	winmove, A,,%x%, %y%
	return
Up::
	wingetpos x, y,,, A
	y -= 10
	winmove, A,,%x%, %y%
	return
Down::
	wingetpos x, y,,, A
	y += 10
	winmove, A,,%x%, %y%
	return
^right::
	wingetpos x, y,,, A
	x += 1
	winmove, A,,%x%, %y%
	return
^left::
	wingetpos x, y,,, A
	x -= 1
	winmove, A,,%x%, %y%
	return
^Up::
	wingetpos x, y,,, A
	y -= 1
	winmove, A,,%x%, %y%
	return
^Down::
	wingetpos x, y,,, A
	y += 1
	winmove, A,,%x%, %y%
	return
#IfWinActive
Cheers

User avatar
SpeedMaster
Posts: 494
Joined: 12 Nov 2016, 16:09

Re: Screen clipping

Post by SpeedMaster » 14 Mar 2023, 15:50

SpeedMaster wrote:
11 Mar 2023, 13:34
The recent updates caused too many script crashes (on win 7) due to the fact that the Gdip_Startup() and Gdip_Shutdown() functions of Gdip_all.ahk library are not very reliable. :think:
Starting and closing gdip with the ImagePut.ahklibrary solved the problem. ;)
So I updated the previous plugins so that they close gdip using only with ImagePut. :thumbup:

New updates: Cheers

Avastgard
Posts: 133
Joined: 30 Sep 2016, 21:54

Re: Screen clipping

Post by Avastgard » 16 Mar 2023, 09:52

Hi, @SpeedMaster!

I tried all of your plugins and most of them work great. However, I had some problems using some of them:
  • JL_Shrink.ahk: Double clicking does not shrink image. Using v. 1.0
  • SM_Grayscale.ahk: Pressing G exits the script. Using v. 1.5
Improvement suggestions:
  • SM_AlwaysOnBottom.ahk: Allow to send up with PGUP
Ideas for new plugins:
  • Basic drawing on clipped image with mouse cursor
  • Adjusting clipped image transparency with mousewheel
  • Allowing clickthrough clipped image

User avatar
SpeedMaster
Posts: 494
Joined: 12 Nov 2016, 16:09

Re: Screen clipping

Post by SpeedMaster » 16 Mar 2023, 20:18

Hello,

@Avastgard Thanks for the feedback and suggestions !
Avastgard wrote:
16 Mar 2023, 09:52
  • JL_Shrink.ahk: Double clicking does not shrink image. Using v. 1.0
Probably because it was not inserted correctly in the list of plugins. For it to work it must be in the auto-executable part of the script, i.e. in the headers section of the plugins.

For example this arrangement should work:
Spoiler

but not this one:
Spoiler
Avastgard wrote:
16 Mar 2023, 09:52
  • SM_Grayscale.ahk: Pressing G exits the script. Using v. 1.5
This is probably because you are using the U64 version of AHK. The script is not fully compatible with the U64 version of AHK.
Fortunately there is a bugfix (from Joe Glines https://www.autohotkey.com/boards/viewtopic.php?p=114216#p114216) I had removed it because I thought it was no longer necessary when using Gdip_all.
I made a new update of the header (FG_Header.ahk) and put the bugfix back in it. See below.
Avastgard wrote:
16 Mar 2023, 09:52
  • SM_AlwaysOnBottom.ahk: Allow to send up with PGUP
Good idea and easy to implement.
New update for the plugin. see below. :arrow:
https://www.autohotkey.com/boards/viewtopic.php?f=6&t=12088&p=509493#p509493
Avastgard wrote:
16 Mar 2023, 09:52
Ideas for new plugins:
  • Basic drawing on clipped image with mouse cursor
  • Adjusting clipped image transparency with mousewheel
  • Allowing clickthrough clipped image
  • Basic drawing: this is more difficult to implement. I coded a plugin (beta version) with which you can draw some shapes. I'll post it as soon as I finish testing it.
  • Transparency: @ needforspeed I managed to adapt your code https://www.autohotkey.com/boards/viewtopic.php?p=176909#p176909 for setting transparency to make a plugin from it.
    I don't really see any use for it and the other plugins don't work with it. But hey, just for fun... I post it anyway. :) See below.
    The advantage to have plugins is that you can deactivate one of it as soon as it bugs you. 8-)
  • clickthrough: For that I have to make a ghost window. I don't really see any use for it and I don't know if it's easy to implement. I'll see what I can do or maybe someone else... (everyone is free to post a plugin :thumbup: )
Regards

User avatar
SpeedMaster
Posts: 494
Joined: 12 Nov 2016, 16:09

Re: Screen clipping

Post by SpeedMaster » 16 Mar 2023, 20:20

New update for the main files : V1.6 :arrow: viewtopic.php?f=6&t=12088&start=240#p506077
  • added empty folder (Images - Screen Clipper) in the starting package.
  • FG_Header.ahk: V1.6 :arrow: added Joe Glines bugfix to force using AHK U32 instead of AHK U64 version in FG_Header.ahk file.
New update for plugin Cheers
Last edited by SpeedMaster on 17 Mar 2023, 05:50, edited 1 time in total.

User avatar
SpeedMaster
Posts: 494
Joined: 12 Nov 2016, 16:09

Re: Screen clipping

Post by SpeedMaster » 16 Mar 2023, 20:24

[PLUGIN] Transparency v1.1

Usage:
Press Shift + Mouse Wheel to adjust transparency of the selected clip image.

how to install this plugin ?
1° download FG ScreenClipper at viewtopic.php?p=506077#p506077
2° put this plugin in the Lib folder of the main script
3° insert "#Include SM_Trans.ahk" in the INCLUDE SECTION (footers) of the main script ---> RUN_ScreenCLip.ahk

Internal default shortcuts:
Press Shift + Mouse Wheel to adjust transparency of the selected clip image.

Function: SM_MakeTrans(tdir:= 1)
(tdir= 1 ) make more transparent
(tdir= -1 ) make less transparent

Note: this plugin is not compatible with others plugins. Use plugin SM_Duplicate to restore the clip image.
this plugin use a cached image file from the cache folder (a_scriptdir\temp)
you can change the location of the cache folder in the Fg_header.ahk file.

File Name: SM_Trans.ahk

Code: Select all

/*--------------------------------------------------------------------------------------------------------------------
[Plugin] transparency  (by Speedmaster)
File Name : SM_Trans.ahk
version: 1.1 2023 04 23
topic: https://www.autohotkey.com/boards/viewtopic.php?p=506077#p506077
Help:
how to install this plugin ?
1° download FG ScreenClipper at https://www.autohotkey.com/boards/viewtopic.php?p=506077#p506077
2° put this plugin in the Lib folder of the main RUN script
3° insert "#Include SM_Trans.ahk" in the INCLUDE SECTION (footers) of the main RUN script ---> RUN_ScreenCLip.ahk

Note this plugin has internal default shortcuts (see below) that you can change 
or migrate in the #ifwinactive section of the main run script
*/---------------------------------------------------------------------------------------------------------------------

; DEFAULT SHORTCUTS ---------------------------------------------------
; Help: tdir=1 make more transparent  tdir=-1 make less transparent
#IfWinActive, ScreenClipperWindow ahk_class AutoHotkeyGUI
+Wheelup::tooltip, % SM_MakeTrans(1)
+WheelDown::tooltip, % SM_MakeTrans(-1)

~shift up::
tooltip
return

#IfWinActive
;--------------------------------------------------------------


;-------- FUNCTIONS TO SET TRANSPARENCY ---------------------

SM_MakeTrans(tdir:="1"){
	global cachefolder
WinGet, Transparent, Transparent, A
if !(transparent)
	SM_Trans(255)   

WinGet, Transparent, Transparent, A
(transparent)&&(transparent>25)&&(tdir>0)&&transparent -= (transparent*10)//100
(transparent)&&(transparent<250)&&(tdir<0)&&transparent += (transparent*10)//100
(transparent>250)&&(transparent:=255)
winset, Transparent, % transparent
return % (transparent*100)//255 " `%"
}

SM_Trans(level:=126){
WinGet, Hwnd, ID, A
	WinGetPos, X, Y, W, H,  ahk_id %Hwnd%
	if DeleteBorders
		 X+=3, Y+=3, W-=6, H-=6

    MaxGuis := SCW_Reg("MaxGuis"), i := SCW_Reg("StartAfter")		
	Loop % MaxGuis {
		if (SCW_Reg("G" ++i "#HWND") = hwnd) {
			currentgui := i
			break
		}
	}	
		
(!CacheFolder)&&CacheFolder:="temp"   ;default name for the cache folder if it has not been set up
IfNotExist, %CacheFolder%
   FileCreateDir, %CacheFolder%
	if (ErrorLevel){
		CacheFolder:=A_temp
	}		
		
img:=CacheFolder "\" currentgui ".png"
WinGet,List_Class_NN,ControlList,A
	if !(List_Class_NN)
	{
		pToken := Gdip_Startup()
		pBitmap := Gdip_BitmapFromScreen(X "|" Y "|" W "|" H)
		FileName := currentgui ".PNG"
		Gdip_SaveBitmapToFile(pBitmap, CacheFolder "\" FileName)
		Gdip_DisposeImage(pBitmap)
		Gdip_Shutdown(pToken)
		Gui,Color, teal
		WinSet,Transcolor, teal %level%
		Gui %currentgui%: Margin,0,0
		Gui %currentgui%: Add,Pic,x0 y0, % CacheFolder "\" currentgui ".PNG"
		gui %currentgui%: show
	}

}
Cheers
Last edited by SpeedMaster on 23 Apr 2023, 13:25, edited 1 time in total.

InterestingHmm
Posts: 3
Joined: 06 Apr 2023, 11:14

Re: Screen clipping

Post by InterestingHmm » 06 Apr 2023, 11:40

Does FG Screen Clipper (Plugin Edition) not work with AutoHotkey 2.0.2?

User avatar
SpeedMaster
Posts: 494
Joined: 12 Nov 2016, 16:09

Re: Screen clipping

Post by SpeedMaster » 09 Apr 2023, 08:44

@InterestingHmm
No it doesn't work with version 2.
For version 2 there is a clone you can find it here: viewtopic.php?f=83&t=115622
For version 2 I have provided only one plugin (the resizer). viewtopic.php?p=515617#p515617

Avastgard
Posts: 133
Joined: 30 Sep 2016, 21:54

Re: Screen clipping

Post by Avastgard » 11 Apr 2023, 20:52

SpeedMaster wrote:
16 Mar 2023, 20:18

[*]Basic drawing: this is more difficult to implement. I coded a plugin (beta version) with which you can draw some shapes. I'll post it as soon as I finish testing it.
Hey, @SpeedMaster, any news on that basic drawing plugin?

User avatar
SpeedMaster
Posts: 494
Joined: 12 Nov 2016, 16:09

Re: Screen clipping

Post by SpeedMaster » 12 Apr 2023, 06:57

Avastgard wrote:
11 Apr 2023, 20:52
Hey, @SpeedMaster, any news on that basic drawing plugin?
I had forgotten about this one because it was not very easy to use and sometimes unstable.
But as promised I post it anyway. :D

User avatar
SpeedMaster
Posts: 494
Joined: 12 Nov 2016, 16:09

Re: Screen clipping

Post by SpeedMaster » 12 Apr 2023, 07:00

[PLUGIN] Draw Shapes v. 2023 04 15 .002

Usage:
Press P to activate basic drawing mode.

how to install this plugin ?
1° download FG ScreenClipper at viewtopic.php?p=506077#p506077
2° put this plugin "SM_DrawShape.ahk" in the Lib folder of the main script (RUN_ScreenCLip.ahk)
3° insert this line "#Include SM_DrawShape.ahk" in the INCLUDE SECTION (footer) of the main script ---> RUN_ScreenCLip.ahk

Internal default shortcuts:

Press " P " to activate the pen and start drawing mode. Press " P " again to save current drawing and close drawing mode.
Press Ctrl + " P " to abort current drawing and close drawing mode.

when drawing mode is activated:
Press Ctrl + left mouse to draw a rectangle
Press Ctrl + right mouse to draw a filed rectangle
Press Shift + left mouse for free hand drawing
Press Shift + right mouse to draw a line
Press Alt + left mouse to draw an arrow
Press Alt + right mouse to draw a double head arrow
Rotate the Wheel mouse to switch between colors

Note: Don't forget to close the drawing mode as soon as you finish drawing. (press the P key again to save and close)

File Name: SM_DrawShape.ahk

Code: Select all

/* ;--------------------------------------------------------------------------------------------------------------------
[Plugin] Draw Shapes (by Speedmaster)
File Name : SM_DrawShape.ahk
version: 2023 04 15 .002
topic: https://www.autohotkey.com/boards/viewtopic.php?p=506077#p506077
Help:
how to install this plugin ?
1° download FG ScreenClipper at https://www.autohotkey.com/boards/viewtopic.php?p=506077#p506077
2° put this plugin "SM_DrawShape.ahk" in the Lib folder of the main script (RUN_ScreenCLip.ahk)
3° insert this line "#Include SM_DrawShape.ahk" in the INCLUDE SECTION (footer) of the main script ---> RUN_ScreenCLip.ahk

--------------------
Help for shortcuts:
--------------------
Press " P " to activate the pen and start drawing mode. Press " P " again to save current drawing and close drawing mode.
Press  Ctrl + " P " to abort current drawing and close drawing mode.

when drawing mode is activated:
Press  Ctrl + left mouse to draw a rectangle
Press  Ctrl + right mouse to draw a filed rectangle
Press Shift + left mouse for free hand drawing
Press Shift + right mouse to draw a line
Press   Alt + left mouse to draw an arrow
Press   Alt + right mouse to draw a double head arrow
Rotate the  Wheel mouse to switch between colors

*/ ;---------------------------------------------------------------------------------------------------------------------

SetBatchLines -1
SetMouseDelay -1 

; DEFAULT SHORTCUTS ---------------------------------------------------
#IfWinActive, ScreenClipperWindow ahk_class AutoHotkeyGUI
p::                          ; activate the pen or save current drawing
tdrawshape:=!tdrawshape
#IfWinActive

if (!tdrawshape) {
	SM_FixLines()
return
}
else if (tdrawshape) {
coordmode, mouse, screen
MaxGuis := SCW_Reg("MaxGuis"), i := SCW_Reg("StartAfter")		
	Loop % MaxGuis {
		if (SCW_Reg("G" ++i "#HWND") = hwnd) {
			currentgui := i
			break
		}
	}

if (!currentgui) {
	msgbox, not current gui found
	return	
}
	imageput.gdiplusstartup()	

Gui, gdraw: -Caption +E0x80000  +LastFound +AlwaysOnTop +ToolWindow ;+OwnDialogs 
Gui, gdraw: Show, NA
;if !hwnd7
hwnd7 := WinExist() 
;---------------------------------------------------- Gdip stuff ----------------------------------------------
Width := A_ScreenWidth, Height := A_ScreenHeight

hbm := CreateDIBSection(Width, Height)  ;screen
hdc := CreateCompatibleDC()             ;screen
obm := SelectObject(hdc, hbm)           ;screen
hbm2 := CreateDIBSection(Width, Height) 
hdc2 := CreateCompatibleDC()            
obm2 := SelectObject(hdc2, hbm2)        
G := Gdip_GraphicsFromHDC(hdc)
G2 := Gdip_GraphicsFromHDC(hdc2)
Gdip_SetSmoothingMode(G, 4)
Gdip_SetSmoothingMode(G2, 4)
;------------------------------------------------  create  pencil and brush ------------------------------------

pPen := Gdip_CreatePen("0xFFFF0000" , 5) 
pBrush := Gdip_BrushCreateSolid("0xFFFF0000")

tooltip, Drawing mode activated 
sleep, 1000
tooltip

;------------------------------------------------  pencils with rounded caps ------------------------------------
Gdip_SetStartCap(pPen, 2)
Gdip_SetEndCap(pPen, 2)

}

Gdip_SetStartCap(pPen, cap=2)
{
	return DllCall("gdiplus\GdipSetPenStartCap", "UPtr", pPen, "Uint", cap)
}

Gdip_SetEndCap(pPen, cap=2)
{
	return DllCall("gdiplus\GdipSetPenEndCap", "UPtr", pPen, "Uint", cap)
}

return

;----------------------------------------------------  draw shapes  -----------------------------------------------------

#IfWinActive, ScreenClipperWindow ahk_class AutoHotkeyGUI

!lbutton::
!Rbutton::
^Rbutton::
^Lbutton::
+Lbutton::
+Rbutton::

#IfWinActive

if !tdrawshape
	return

MaxGuis := SCW_Reg("MaxGuis"), i := SCW_Reg("StartAfter")		
	Loop % MaxGuis {
		if (SCW_Reg("G" ++i "#HWND") = WinExist()) {
			currentgui := i
			break
		}
	}

if (!currentgui)
	return


Gui %currentgui%: -AlwaysOnTop

CoordMode, Mouse, Screen
MouseGetPos, x1, y1
;BitBlt(hdc3, 0, 0, Width, Height, hdc, 0, 0) 

if (a_thishotkey="!Lbutton") 
while (getKeyState("Alt", "P")  && getkeystate("Lbutton", "P"))
{
MouseGetPos, x2, y2
 Gdip_GraphicsClear(G2)
 BitBlt(hdc2, 0, 0, Width, Height, hdc, 0, 0)
 gdip_DrawArrow(G2,pPen,x2,y2,x1,y1,30,205,0)
 UpdateLayeredWindow(hwnd7, hdc2, 0, 0, Width, Height)
 double:=0
}
if (a_thishotkey="!Rbutton") 
while (getKeyState("Alt", "P"))  && getkeystate("Rbutton", "P")
{
 MouseGetPos, x2, y2
 Gdip_GraphicsClear(G2)
 BitBlt(hdc2, 0, 0, Width, Height, hdc, 0, 0)
 gdip_DrawArrow(G2,pPen,x1,y1,x2,y2,30,205,1)            ; (Graphic,pen,EndPosX,EndPosY,StartPosX,StartPosY,headLength,degreeA:=205, double:=false)
 UpdateLayeredWindow(hwnd7, hdc2, 0, 0, Width, Height)
 double:=1
}

if (a_thishotkey="+Lbutton") {
while getKeyState("LButton", "P")
{
    MouseGetPos, x2, y2
	sleep, 10
    MouseGetPos, x1, y1
    Gdip_DrawLine(G2, pPen, x1, y1, x2, y2)
	if x3
    Gdip_DrawLine(G2, pPen, x3, y3, x1, y1)	
    BitBlt(hdc, 0, 0, Width, Height, hdc2, 0, 0)	
	x3:=x1, y3:=y1
    UpdateLayeredWindow(hwnd7, hdc2, 0, 0, Width, Height)
}
x1:=X2:=x3:=y3:=y1:=y2:=""
}


if (a_thishotkey="+Rbutton") {
while (getKeyState("shift", "P"))  && getkeystate("Rbutton", "P")
{
	MouseGetPos, x2, y2
	Gdip_GraphicsClear(G2)
	BitBlt(hdc2, 0, 0, Width, Height, hdc, 0, 0)
	Gdip_DrawLine(G2, pPen, x1, y1, x2, y2)	
	UpdateLayeredWindow(hwnd7, hdc2, 0, 0, Width, Height)
}
}

if (a_thishotkey="^Lbutton") 
while (getKeyState("control", "P"))  && getkeystate("Lbutton", "P")
{
 MouseGetPos, x2, y2
 Gdip_GraphicsClear(G2)
 BitBlt(hdc2, 0, 0, Width, Height, hdc, 0, 0)
 Gdip_DrawRectangle(G2, pPen, min(x1,x2), min(y1,y2), abs(x2-x1), abs(y2-y1))  
 UpdateLayeredWindow(hwnd7, hdc2, 0, 0, Width, Height)
 double:=1
}

if (a_thishotkey="^Rbutton") 
while (getKeyState("control", "P"))  && getkeystate("Rbutton", "P")
{
 MouseGetPos, x2, y2
 Gdip_GraphicsClear(G2)
 BitBlt(hdc2, 0, 0, Width, Height, hdc, 0, 0)
 Gdip_FillRectangle(G2, pBrush, min(x1,x2), min(y1,y2), abs(x2-x1), abs(y2-y1))
 UpdateLayeredWindow(hwnd7, hdc2, 0, 0, Width, Height)
 double:=1
}

BitBlt(hdc, 0, 0, Width, Height, hdc2, 0, 0) ;copy buffer to screen
UpdateLayeredWindow(hwnd7, hdc, 0, 0, Width, Height) ; now draw on screen

return

#IfWinActive, ScreenClipperWindow ahk_class AutoHotkeyGUI
wheelup::
wheeldown::
if (tdrawshape) {
(!nextcolor)&&nextcolor:=1 
++nextcolor
(nextcolor=5)&&nextcolor:=1

if (nextcolor=1) {
pPen := Gdip_CreatePen("0xFFFF0000" , 5)
pBrush := Gdip_BrushCreateSolid("0xFFFF0000")
tooltip Red
sleep, 400
}
else if (nextcolor=2) {
pPen := Gdip_CreatePen("0xFF008000" , 5)
pBrush := Gdip_BrushCreateSolid("0xFF008000")
tooltip Green
sleep, 400
}
else if (nextcolor=3) {
pPen := Gdip_CreatePen("0xFF0000FF" , 5) 
pBrush := Gdip_BrushCreateSolid("0xFF0000FF")
tooltip Blue
sleep, 400
}
else if (nextcolor=4) {
pPen := Gdip_CreatePen("0xFF111111" , 5) 
pBrush := Gdip_BrushCreateSolid("0xFF111111")
tooltip Black
sleep, 400
}

Gdip_SetStartCap(pPen, 2)
Gdip_SetEndCap(pPen, 2)
tooltip
}
return

;arbort current drawing and clear the screen
^p::
	;imageput.gdiplusstartup()
	if !tdrawshape
	return

    Gdip_GraphicsClear(G)  
    BitBlt(hdc2, 0, 0, Width, Height, hdc, 0, 0) 
   ; BitBlt(hdc3, 0, 0, Width, Height, hdc, 0, 0) 
    UpdateLayeredWindow(hwnd7, hdc, 0, 0, Width, Height)  
	
	SelectObject(hdc, obm)
	DeleteObject(hbm)
	DeleteDC(hdc)
	Gdip_DeleteGraphics(G)

	SelectObject(hdc2, obm2)
	DeleteObject(hbm2)
	DeleteDC(hdc2)
	Gdip_DeleteGraphics(G2)

	Gdip_DisposeImage(pBitmap3)

	imageput.gdiplusShutdown()
	Gui, gdraw: Hide

	tdrawshape:=false
return    


#IfWinActive


SM_FixLines(){
 global 

WinGet, Hwnd, ID, A
MaxGuis := SCW_Reg("MaxGuis"), i := SCW_Reg("StartAfter")		
	Loop % MaxGuis {
		if (SCW_Reg("G" ++i "#HWND") = WinExist()) {
			currentgui := i
			break
		}
	}

if !(currentgui) {
msgbox, 	curent gui not found 2
	return
}
	WinGetPos , OutX, OutY, OutWidth, OutHeight, A
	OutX:=OutX+3, OutY:=OutY+3, OutWidth:=OutWidth-6, OutHeight:=OutHeight-6
	Area := OutX "|" OutY "|" OutWidth "|" OutHeight
	StringSplit, v, Area, |
	if (v3 < 10 and v4 < 10)   ; too small area
		return
	pBitmap := Gdip_BitmapFromScreen(Area)
	SCW_CreateLayeredWinMod(currentgui,pBitmap,v1,v2, SCW_Reg("DrawCloseButton"))
	
 Gdip_GraphicsClear(G) 
    BitBlt(hdc2, 0, 0, Width, Height, hdc, 0, 0) 
    BitBlt(hdc3, 0, 0, Width, Height, hdc, 0, 0) 
    UpdateLayeredWindow(hwnd7, hdc, 0, 0, Width, Height) 

	imageput.gdiplusShutdown()	
    
}	

return

; draw arrow function converted to ahk by speedmaster
; https://stackoverflow.com/questions/26804679/how-can-i-draw-arrows-on-a-canvas-with-mouse	
gdip_DrawArrow(Graphic,pen,EndPosX,EndPosY,StartPosX,StartPosY,headLength,degreeA:=205, double:=false) {
	Static PI := 4 * ATan(1)
	degreeB:=360-degreeA
	dx:=EndPosX-StartPosX
	dy:=EndPosY-StartPosY
	angle_atan2:=atan(dy/dx)+4*atan((dx<0)*((dy>0)-(dy<0)))
	(headLength)?headLength:headLength:=50
	degreesInRadiansA:=degreeA*PI/180
	degreesInRadiansB:=degreeB*PI/180 
	RadXA:=round(EndPosX+headLength*cos(angle_atan2+degreesInRadiansA))
	RadYA:=round(EndPosY+headLength*sin(angle_atan2+degreesInRadiansA))
	RadXB:=round(EndPosX+headLength*cos(angle_atan2+degreesInRadiansB))
	RadYB:=round(EndPosY+headLength*sin(angle_atan2+degreesInRadiansB))
	Gdip_DrawLine(Graphic, Pen, EndPosX, EndPosY, RadXA, RadYA) ; arrow head side left
	Gdip_DrawLine(Graphic, Pen, EndPosX, EndPosY, RadXB, RadYB) ; arrow head side right

if (double) {
	RadXA2:=round(StartPosX+headLength*-cos(angle_atan2+degreesInRadiansA))
	RadYA2:=round(StartPosY+headLength*-sin(angle_atan2+degreesInRadiansA))
	RadXB2:=round(StartPosX+headLength*-cos(angle_atan2+degreesInRadiansB))
	RadYB2:=round(StartPosY+headLength*-sin(angle_atan2+degreesInRadiansB))	
	Gdip_DrawLine(Graphic, Pen, StartPosX, StartPosY, RadXA2, RadYA2) ; arrow head side left
	Gdip_DrawLine(Graphic, Pen, StartPosX, StartPosY, RadXB2, RadYB2) ; arrow head side right
}	
    Gdip_DrawLine(Graphic, Pen, StartPosX, StartPosY, EndPosX, EndPosY) ; line
}
return

Cheers
Last edited by SpeedMaster on 15 Apr 2023, 12:25, edited 2 times in total.

Avastgard
Posts: 133
Joined: 30 Sep 2016, 21:54

Re: Screen clipping

Post by Avastgard » 12 Apr 2023, 13:12

SpeedMaster wrote:
12 Apr 2023, 07:00
[PLUGIN] Draw Shapes V. 2023 04 12 .002

Usage:
Press P to activate basic drawing mode.

how to install this plugin ?
1° download FG ScreenClipper at viewtopic.php?p=506077#p506077
2° put this plugin "SM_DrawShape.ahk" in the Lib folder of the main script (RUN_ScreenCLip.ahk)
3° insert this line "#Include SM_DrawShape.ahk" in the INCLUDE SECTION (footer) of the main script ---> RUN_ScreenCLip.ahk

Internal default shortcuts:

Press " P " to activate the pen and start drawing mode. Press " P " again to save current drawing and close drawing mode.
Press Ctrl + " P " to abort current drawing and close drawing mode.

when drawing mode is activated:
Press Ctrl + left mouse to draw a rectangle
Press Ctrl + right mouse to draw a filed rectangle
Press Shift + left mouse to draw a line
Press Alt + left mouse to draw an arrow
Press Alt + right mouse to draw a double head arrow
Rotate the Wheel mouse to switch between colors

Note: Don't forget to close the drawing mode as soon as you finish drawing. (press the P key again to save and close)

File Name: SM_DrawShape.ahk

Code: Select all

/* ;--------------------------------------------------------------------------------------------------------------------
[Plugin] Draw Shapes (by Speedmaster)
File Name : SM_DrawShape.ahk
version: 2023 04 12 .002
topic: https://www.autohotkey.com/boards/viewtopic.php?p=506077#p506077
Help:
how to install this plugin ?
1° download FG ScreenClipper at https://www.autohotkey.com/boards/viewtopic.php?p=506077#p506077
2° put this plugin "SM_DrawShape.ahk" in the Lib folder of the main script (RUN_ScreenCLip.ahk)
3° insert this line "#Include SM_DrawShape.ahk" in the INCLUDE SECTION (footer) of the main script ---> RUN_ScreenCLip.ahk

--------------------
Help for shortcuts:
--------------------
Press " P " to activate the pen and start drawing mode. Press " P " again to save current drawing and close drawing mode.
Press  Ctrl + " P " to abort current drawing and close drawing mode.

when drawing mode is activated:
Press  Ctrl + left mouse to draw a rectangle
Press  Ctrl + right mouse to draw a filed rectangle
Press Shift + left mouse to draw a line
Press   Alt + left mouse to draw an arrow
Press   Alt + right mouse to draw a double head arrow
Rotate the  Wheel mouse to switch between colors

*/ ;---------------------------------------------------------------------------------------------------------------------

SetBatchLines -1
SetMouseDelay -1 

; DEFAULT SHORTCUTS ---------------------------------------------------
#IfWinActive, ScreenClipperWindow ahk_class AutoHotkeyGUI
p::                          ; activate the pen or save current drawing
tdrawshape:=!tdrawshape
#IfWinActive

if (!tdrawshape) {
	SM_FixLines()
return
}
else if (tdrawshape) {
coordmode, mouse, screen
MaxGuis := SCW_Reg("MaxGuis"), i := SCW_Reg("StartAfter")		
	Loop % MaxGuis {
		if (SCW_Reg("G" ++i "#HWND") = hwnd) {
			currentgui := i
			break
		}
	}

if (!currentgui) {
	msgbox, not current gui found
	return	
}
	imageput.gdiplusstartup()	

Gui, 1: -Caption +E0x80000  +LastFound +AlwaysOnTop +ToolWindow +OwnDialogs 
Gui, 1: Show, NA
if !hwnd7
hwnd7 := WinExist() 
;---------------------------------------------------- Gdip stuff ----------------------------------------------
Width := A_ScreenWidth, Height := A_ScreenHeight

hbm := CreateDIBSection(Width, Height)  ;screen
hdc := CreateCompatibleDC()             ;screen
obm := SelectObject(hdc, hbm)           ;screen
hbm2 := CreateDIBSection(Width, Height) 
hdc2 := CreateCompatibleDC()            
obm2 := SelectObject(hdc2, hbm2)        
G := Gdip_GraphicsFromHDC(hdc)
G2 := Gdip_GraphicsFromHDC(hdc2)
Gdip_SetSmoothingMode(G, 4)
Gdip_SetSmoothingMode(G2, 4)
;------------------------------------------------  create  pencil and brush ------------------------------------

pPen := Gdip_CreatePen("0xFFFF0000" , 5) 
pBrush := Gdip_BrushCreateSolid("0xFFFF0000")

tooltip, Drawing mode activated `n ctrl >> rectangle `n shift >> line `n alt >> arrow
sleep, 3000
tooltip

;------------------------------------------------  pencils with rounded caps ------------------------------------
Gdip_SetStartCap(pPen, 2)
Gdip_SetEndCap(pPen, 2)

}

Gdip_SetStartCap(pPen, cap=2)
{
	return DllCall("gdiplus\GdipSetPenStartCap", "UPtr", pPen, "Uint", cap)
}

Gdip_SetEndCap(pPen, cap=2)
{
	return DllCall("gdiplus\GdipSetPenEndCap", "UPtr", pPen, "Uint", cap)
}

return

;----------------------------------------------------  draw shapes  -----------------------------------------------------

#IfWinActive, ScreenClipperWindow ahk_class AutoHotkeyGUI
!lbutton::
!Rbutton::
^Rbutton::
^Lbutton::
+Lbutton::

#IfWinActive

MaxGuis := SCW_Reg("MaxGuis"), i := SCW_Reg("StartAfter")		
	Loop % MaxGuis {
		if (SCW_Reg("G" ++i "#HWND") = WinExist()) {
			currentgui := i
			break
		}
	}

if (!currentgui)
	return


Gui %currentgui%: -AlwaysOnTop

CoordMode, Mouse, Screen
MouseGetPos, x1, y1
BitBlt(hdc3, 0, 0, Width, Height, hdc, 0, 0) 


if (a_thishotkey="!Lbutton") 
while (getKeyState("Alt", "P")  && getkeystate("Lbutton", "P"))
{
MouseGetPos, x2, y2
 Gdip_GraphicsClear(G2)
 BitBlt(hdc2, 0, 0, Width, Height, hdc, 0, 0)
 gdip_DrawArrow(G2,pPen,x2,y2,x1,y1,30,205,0)
 UpdateLayeredWindow(hwnd7, hdc2, 0, 0, Width, Height)
 double:=0
}
if (a_thishotkey="!Rbutton") 
while (getKeyState("Alt", "P"))  && getkeystate("Rbutton", "P")
{
 MouseGetPos, x2, y2
 Gdip_GraphicsClear(G2)
 BitBlt(hdc2, 0, 0, Width, Height, hdc, 0, 0)
 gdip_DrawArrow(G2,pPen,x1,y1,x2,y2,30,205,1)            ; (Graphic,pen,EndPosX,EndPosY,StartPosX,StartPosY,headLength,degreeA:=205, double:=false)
 UpdateLayeredWindow(hwnd7, hdc2, 0, 0, Width, Height)
 double:=1
}

if (a_thishotkey="+Lbutton") {

while getKeyState("LButton", "P")
{
    MouseGetPos, x2, y2
    Gdip_GraphicsClear(G2)
    BitBlt(hdc2, 0, 0, Width, Height, hdc, 0, 0)
    Gdip_DrawLine(G2, pPen, x1, y1, x2, y2)
    UpdateLayeredWindow(hwnd7, hdc2, 0, 0, Width, Height)
}
}

if (a_thishotkey="^Lbutton") 
while (getKeyState("control", "P"))  && getkeystate("Lbutton", "P")
{
 MouseGetPos, x2, y2
 Gdip_GraphicsClear(G2)
 BitBlt(hdc2, 0, 0, Width, Height, hdc, 0, 0)
 Gdip_DrawRectangle(G2, pPen, min(x1,x2), min(y1,y2), abs(x2-x1), abs(y2-y1))  
 UpdateLayeredWindow(hwnd7, hdc2, 0, 0, Width, Height)
 double:=1
}

if (a_thishotkey="^Rbutton") 
while (getKeyState("control", "P"))  && getkeystate("Rbutton", "P")
{
 MouseGetPos, x2, y2
 Gdip_GraphicsClear(G2)
 BitBlt(hdc2, 0, 0, Width, Height, hdc, 0, 0)
 Gdip_FillRectangle(G2, pBrush, min(x1,x2), min(y1,y2), abs(x2-x1), abs(y2-y1))
 UpdateLayeredWindow(hwnd7, hdc2, 0, 0, Width, Height)
 double:=1
}

BitBlt(hdc, 0, 0, Width, Height, hdc2, 0, 0) ;copy buffer to screen
UpdateLayeredWindow(hwnd7, hdc, 0, 0, Width, Height) ; now draw on screen

return

#IfWinActive, ScreenClipperWindow ahk_class AutoHotkeyGUI
wheelup::
wheeldown::
if (tdrawshape) {
(!nextcolor)&&nextcolor:=1 
++nextcolor
(nextcolor=5)&&nextcolor:=1

if (nextcolor=1) {
pPen := Gdip_CreatePen("0xFFFF0000" , 5)
pBrush := Gdip_BrushCreateSolid("0xFFFF0000")
tooltip Red
sleep, 400
}
else if (nextcolor=2) {
pPen := Gdip_CreatePen("0xFF008000" , 5)
pBrush := Gdip_BrushCreateSolid("0xFF008000")
tooltip Green
sleep, 400
}
else if (nextcolor=3) {
pPen := Gdip_CreatePen("0xFF0000FF" , 5) 
pBrush := Gdip_BrushCreateSolid("0xFF0000FF")
tooltip Blue
sleep, 400
}
else if (nextcolor=4) {
pPen := Gdip_CreatePen("0xFF111111" , 5) 
pBrush := Gdip_BrushCreateSolid("0xFF111111")
tooltip Black
sleep, 400
}

Gdip_SetStartCap(pPen, 2)
Gdip_SetEndCap(pPen, 2)
tooltip
}
return

;arbort current drawing and clear the screen
^p::
	imageput.gdiplusstartup()

    Gdip_GraphicsClear(G)  
    BitBlt(hdc2, 0, 0, Width, Height, hdc, 0, 0) 
    BitBlt(hdc3, 0, 0, Width, Height, hdc, 0, 0) 
    UpdateLayeredWindow(hwnd7, hdc, 0, 0, Width, Height)  
	
	SelectObject(hdc, obm)
	DeleteObject(hbm)
	DeleteDC(hdc)
	Gdip_DeleteGraphics(G)

	SelectObject(hdc2, obm2)
	DeleteObject(hbm2)
	DeleteDC(hdc2)
	Gdip_DeleteGraphics(G2)

	Gdip_DisposeImage(pBitmap3)

	imageput.gdiplusShutdown()

	tdrawshape:=false
return    


#IfWinActive


SM_FixLines(){
 global 

WinGet, Hwnd, ID, A
MaxGuis := SCW_Reg("MaxGuis"), i := SCW_Reg("StartAfter")		
	Loop % MaxGuis {
		if (SCW_Reg("G" ++i "#HWND") = WinExist()) {
			currentgui := i
			break
		}
	}

if !(currentgui) {
msgbox, 	curent gui not found 2
	return
}
	WinGetPos , OutX, OutY, OutWidth, OutHeight, A
	OutX:=OutX+3, OutY:=OutY+3, OutWidth:=OutWidth-6, OutHeight:=OutHeight-6
	Area := OutX "|" OutY "|" OutWidth "|" OutHeight
	StringSplit, v, Area, |
	if (v3 < 10 and v4 < 10)   ; too small area
		return
	pBitmap := Gdip_BitmapFromScreen(Area)
	SCW_CreateLayeredWinMod(currentgui,pBitmap,v1,v2, SCW_Reg("DrawCloseButton"))
	
 Gdip_GraphicsClear(G) 
    BitBlt(hdc2, 0, 0, Width, Height, hdc, 0, 0) 
    BitBlt(hdc3, 0, 0, Width, Height, hdc, 0, 0) 
    UpdateLayeredWindow(hwnd7, hdc, 0, 0, Width, Height) 

	imageput.gdiplusShutdown()	
    
}	

return

; draw arrow function converted to ahk by speedmaster
; https://stackoverflow.com/questions/26804679/how-can-i-draw-arrows-on-a-canvas-with-mouse	
gdip_DrawArrow(Graphic,pen,EndPosX,EndPosY,StartPosX,StartPosY,headLength,degreeA:=205, double:=false) {
	Static PI := 4 * ATan(1)
	degreeB:=360-degreeA
	dx:=EndPosX-StartPosX
	dy:=EndPosY-StartPosY
	angle_atan2:=atan(dy/dx)+4*atan((dx<0)*((dy>0)-(dy<0)))
	(headLength)?headLength:headLength:=50
	degreesInRadiansA:=degreeA*PI/180
	degreesInRadiansB:=degreeB*PI/180 
	RadXA:=round(EndPosX+headLength*cos(angle_atan2+degreesInRadiansA))
	RadYA:=round(EndPosY+headLength*sin(angle_atan2+degreesInRadiansA))
	RadXB:=round(EndPosX+headLength*cos(angle_atan2+degreesInRadiansB))
	RadYB:=round(EndPosY+headLength*sin(angle_atan2+degreesInRadiansB))
	Gdip_DrawLine(Graphic, Pen, EndPosX, EndPosY, RadXA, RadYA) ; arrow head side left
	Gdip_DrawLine(Graphic, Pen, EndPosX, EndPosY, RadXB, RadYB) ; arrow head side right

if (double) {
	RadXA2:=round(StartPosX+headLength*-cos(angle_atan2+degreesInRadiansA))
	RadYA2:=round(StartPosY+headLength*-sin(angle_atan2+degreesInRadiansA))
	RadXB2:=round(StartPosX+headLength*-cos(angle_atan2+degreesInRadiansB))
	RadYB2:=round(StartPosY+headLength*-sin(angle_atan2+degreesInRadiansB))	
	Gdip_DrawLine(Graphic, Pen, StartPosX, StartPosY, RadXA2, RadYA2) ; arrow head side left
	Gdip_DrawLine(Graphic, Pen, StartPosX, StartPosY, RadXB2, RadYB2) ; arrow head side right
}	
    Gdip_DrawLine(Graphic, Pen, StartPosX, StartPosY, EndPosX, EndPosY) ; line
}
return

Cheers

@SpeedMaster, this is AWESOME! This will help me a lot taking screenshots for making tutorials, thank you so much for this!

User avatar
SpeedMaster
Posts: 494
Joined: 12 Nov 2016, 16:09

Re: Screen clipping

Post by SpeedMaster » 15 Apr 2023, 10:07

New update for Draw Shape plugin: V. 2023 04 15 :arrow: viewtopic.php?f=6&t=12088&p=517218#p517218
  • Added free hand drawing (Press Shift + Left mouse) 8-)
  • Shortcut to draw a line is moved to Shift + Right mouse
Regards

Post Reply

Return to “Scripts and Functions (v1)”