Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

[module/script] ScreenClip2Win


  • Please log in to reply
13 replies to this topic
Learning one
  • Members
  • 1483 posts
  • Last active: Jan 02 2016 02:30 PM
  • Joined: 04 Apr 2009

[module/script] ScreenClip2Win
- no globals
- compatible with both AHK_L and AHK Basic
- requires Gdip.ahk by Tic

It will create always on top windows from screen clippings. Click in upper right corner to close win. Click and drag to move it.

Downloads:
- ScreenClip2Win - creates layered windows from screen clippings. Prefix: SCW_
- ScreenClip2Win 2 - creates normal windows from screen clippings. Prefix: SCW2_
Note: 2. version is not better than 1. They are equaly good, just using different methods to achieve same goal.

Example script:

^Lbutton::SCW_ScreenClip2Win() ; click & drag to select area to clip

#IfWinActive, ScreenClippingWindow ahk_class AutoHotkeyGUI
^c::SCW_Win2Clipboard() ; copy selected win to clipboard
#IfWinActive

#Include Gdip.ahk ; by Tic
#Include ScreenClip2Win.ahk ; by Learning one


HotKeyIt
  • Moderators
  • 7439 posts
  • Last active: Jun 22 2016 09:14 PM
  • Joined: 18 Jun 2008
Nice, well done and thanks for sharing :)

EDIT:
Is it possible to have a context menu "Copy to Clipboard"?

EDIT:
Just noticed:
;	does not work for layered windows
SCW_Win2Clipboard() {
	ActiveWinID := WinExist("A")
	pBitmap := Gdip_BitmapFromHWND(ActiveWinID)
	Gdip_SetBitmapToClipboard(pBitmap)
}
Simple workaround:
Menu,CopyToClipBoard,Add,Copy To Clipboard,CopyToClipBoard
^Lbutton::SCW_ScreenClip2Win()   ; click & drag
81GuiContextMenu:
82GuiContextMenu:
83GuiContextMenu:
84GuiContextMenu:
85GuiContextMenu:
86GuiContextMenu:
Menu,CopyToClipBoard,Show
Return
CopyToClipBoard:
Send !{PrintScreen}
Return


Learning one
  • Members
  • 1483 posts
  • Last active: Jan 02 2016 02:30 PM
  • Joined: 04 Apr 2009
Thanks. :) I uploaded new version.
Now SCW_Win2Clipboard() works and by default, it removes borders. To keep borders, specify SCW_Win2Clipboard(1)

Learning one
  • Members
  • 1483 posts
  • Last active: Jan 02 2016 02:30 PM
  • Joined: 04 Apr 2009
Here is alternative version which creates normal (not layered) windows from screen clippings. SCW2_ prefix.
;===Description========================================================================
/*
[module/script] ScreenClip2Win
Author:		Learning one
Thanks:		Tic, HotKeyIt

Creates always on top windows from screen clippings. Click in upper right corner to close win. Click and drag to move it.
Uses Gdip.ahk by Tic.


;=== Example script ===
^Lbutton::SCW2_ScreenClip2Win()	; click & drag to select area to clip

#IfWinActive, ScreenClippingWindow ahk_class AutoHotkeyGUI
^c::SCW2_Win2Clipboard()		; copy selected win to clipboard
#IfWinActive

#Include Gdip.ahk		; by Tic
#Include ScreenClip2Win.ahk		; by Learning one



;=== Short documentation ===
SCW2_ScreenClip2Win() 			; creates always on top window from screen clipping. Click and drag to select area.
SCW2_DestroyAllClipWins() 		; destroys all screen clipping windows.
SCW2_Win2Clipboard()			; copies window to clipboard. By default, removes borders. To keep borders, specify "SCW2_Win2Clipboard(1)"
SCW2_SetUp(Options="")			; you can change some default options in Auto-execute part of script. Syntax: "<option>.<value>"
	StartAfter - module will start to consume GUIs for screen clipping windows after specified GUI number. Default: 80
	MaxGuis - maximum number of screen clipping windows. Default: 6
	GuiColor - Default: black. It's actually just 1 pixel thick border around screen clipping.
	AutoMonitorWM_LBUTTONDOWN - on/off automatic monitoring of WM_LBUTTONDOWN message. Default: 1 (on)
	SelColor - selection color. Default: Yellow
	SelTrans - selection transparency. Default: 80
	
	Example:	SCW2_SetUp("MaxGuis.30 StartAfter.50 SelColor.Red")
	

;=== Avoid OnMessage(0x201, "WM_LBUTTONDOWN") collision example===
Gui, Show, w200 h200
SCW2_SetUp("AutoMonitorWM_LBUTTONDOWN.0")	; turn off auto monitoring WM_LBUTTONDOWN
OnMessage(0x201, "WM_LBUTTONDOWN")	; manualy monitor WM_LBUTTONDOWN
Return

^Lbutton::SCW2_ScreenClip2Win()	; click & drag
Esc::ExitApp

#Include Gdip.ahk		; by Tic
#Include ScreenClip2Win.ahk		; by Learning one
WM_LBUTTONDOWN() {
	if SCW2_LBUTTONDOWN()	; LBUTTONDOWN on module's screen clipping windows - isolate - it's module's buissines
	return
	else	; LBUTTONDOWN on other windows created by script
	MsgBox,,, You clicked on script's window not created by this module,1
}
*/


;===Functions==========================================================================
SCW2_Version() {
	return 2.00
}

SCW2_DestroyAllClipWins() {
	MaxGuis := SCW2_Reg("MaxGuis"), StartAfter := SCW2_Reg("StartAfter")
	Loop, %MaxGuis%
	{
		StartAfter++
		Gui %StartAfter%: Destroy
	}
}

SCW2_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 GuiColor,StartAfter,MaxGuis,AutoMonitorWM_LBUTTONDOWN,SelColor,SelTrans
			%var% := val
		}
	}
	SCW2_Default(GuiColor,"Black")
	SCW2_Default(StartAfter,80), SCW2_Default(MaxGuis,6)
	SCW2_Default(AutoMonitorWM_LBUTTONDOWN,1), SCW2_Default(SelColor,"Yellow"), SCW2_Default(SelTrans,80)
	
	SCW2_Reg("GuiColor", GuiColor)
	SCW2_Reg("MaxGuis", MaxGuis), SCW2_Reg("StartAfter", StartAfter), SCW2_Reg("SelColor", SelColor), SCW2_Reg("SelTrans",SelTrans)
	SCW2_Reg("WasSetUp", 1)
	if AutoMonitorWM_LBUTTONDOWN
	OnMessage(0x201, "SCW2_LBUTTONDOWN")
}

SCW2_ScreenClip2Win() {
	static c
	if !(SCW2_Reg("WasSetUp"))
	SCW2_SetUp()

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

	GuiNum := StartAfter + c
	Area := SCW2_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)
	SCW2_CreatePictureWin(GuiNum,pBitmap,v1,v2)
	Gdip_Shutdown("pToken")
}

SCW2_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
	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
}

SCW2_CreatePictureWin(GuiNum,pBitmap,x,y) {
	static CloseButton := 16
	GuiColor := SCW2_Reg("GuiColor")
	Gui %GuiNum%: -Border +LastFound +ToolWindow +AlwaysOnTop +OwnDialogs
	hwnd := WinExist()
	Gui %GuiNum%:Color, %GuiColor%
	Gdip_GetDimensions(pBitmap, Width, Height)
	Gui, %GuiNum%:Add, Picture, x1 y1 w%Width% h%Height% 0xE HwndScreenClippingHwnd
	hBitmap := Gdip_CreateHBITMAPFromBitmap(pBitmap), SetImage(ScreenClippingHwnd, hBitmap), DeleteObject(hBitmap), Gdip_DisposeImage(pBitmap)
	
	WinX := x-4, WinY := y-4
	WinW := Width+2, WinH := Height+2
	Gui %GuiNum%: Show, x%WinX% y%WinY% w%WinW% h%WinH% Na, ScreenClippingWindow
	
	SCW2_Reg("G" GuiNum "#HWND", hwnd)
	SCW2_Reg("G" GuiNum "#XClose", WinW+4-CloseButton)
	SCW2_Reg("G" GuiNum "#YClose", CloseButton+4)
	Return hwnd
}

SCW2_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 := SCW2_Reg("G" A_Gui "#XClose"), YClose := SCW2_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 
	}
}

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

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

SCW2_Win2Clipboard(KeepBorders=0) {
	pToken := Gdip_Startup()

	ActiveWinID := WinExist("A")
	pBitmap := Gdip_BitmapFromHWND(ActiveWinID)
	if !KeepBorders
	{
		Gdip_GetDimensions(pBitmap, w, h)
		pBitmap2 := SCW2_CropImage(pBitmap, 4, 4, w-8, h-8)
		Gdip_SetBitmapToClipboard(pBitmap2)
		Gdip_DisposeImage(pBitmap), Gdip_DisposeImage(pBitmap2)
	}
	else
	Gdip_SetBitmapToClipboard(pBitmap), Gdip_DisposeImage(pBitmap)
	Gdip_Shutdown("pToken")
}

SCW2_CropImage(pBitmap, x, y, w, h) {
   pBitmap2 := Gdip_CreateBitmap(w, h), G2 := Gdip_GraphicsFromImage(pBitmap2)
   Gdip_DrawImage(G2, pBitmap, 0, 0, w, h, x, y, w, h)
   Gdip_DeleteGraphics(G2)
   return pBitmap2
}


sumon
  • Moderators
  • 1317 posts
  • Last active: Dec 05 2016 10:14 PM
  • Joined: 18 May 2010
Does not work to me, unless I misunderstand it. I have GDIP library, run the script and try to Ctrl+Leftclick -> Drag to select an area to clip (?). Anyway, it does nothing.

From what I understand it seems like a cool and useful idea. What am I doing wrong?

Learning one
  • Members
  • 1483 posts
  • Last active: Jan 02 2016 02:30 PM
  • Joined: 04 Apr 2009
Copy & paste code below and adapt path to Gdip.ahk
#Include Gdip.ahk		; by Tic (adapt path)

^Lbutton::SCW_ScreenClip2Win()	; click & drag to select area to clip

#IfWinActive, ScreenClippingWindow ahk_class AutoHotkeyGUI
^c::SCW_Win2Clipboard()		; copy selected win to clipboard
#IfWinActive





;=======================
; [module] ScreenClip2Win 
;=======================

;===Description========================================================================
/*
[module/script] ScreenClip2Win
Author:		Learning one
Thanks:		Tic, HotKeyIt

Creates always on top layered windows from screen clippings. Click in upper right corner to close win. Click and drag to move it.
Uses Gdip.ahk by Tic.


;=== Example script ===
^Lbutton::SCW_ScreenClip2Win()	; click & drag to select area to clip

#IfWinActive, ScreenClippingWindow ahk_class AutoHotkeyGUI
^c::SCW_Win2Clipboard()		; copy selected win to clipboard
#IfWinActive

#Include Gdip.ahk		; by Tic
#Include ScreenClip2Win.ahk		; by Learning one



;=== Short documentation ===
SCW_ScreenClip2Win() 			; creates always on top window from screen clipping. Click and drag to select area.
SCW_DestroyAllClipWins() 		; destroys all screen clipping windows.
SCW_Win2Clipboard()				; copies window to clipboard. By default, removes borders. To keep borders, specify "SCW_Win2Clipboard(1)"
SCW_SetUp(Options="")			; you can change some default options in Auto-execute part of script. Syntax: "<option>.<value>"
	StartAfter - module will start to consume GUIs for screen clipping windows after specified GUI number. Default: 80
	MaxGuis - maximum number of screen clipping windows. Default: 6
	BorderAColor - Default: ff6666ff (ARGB format)
	BorderBColor - Default: ffffffff (ARGB format)
	DrawCloseButton - on/off draw "Close Button" on screen clipping windows. Default: 0 (off)
	AutoMonitorWM_LBUTTONDOWN - on/off automatic monitoring of WM_LBUTTONDOWN message. Default: 1 (on)
	SelColor - selection color. Default: Yellow
	SelTrans - selection transparency. Default: 80
	
	Example:	SCW_SetUp("MaxGuis.30 StartAfter.50 BorderAColor.ff000000 BorderBColor.ffffff00")
	

;=== Avoid OnMessage(0x201, "WM_LBUTTONDOWN") collision example===
Gui, Show, w200 h200
SCW_SetUp("AutoMonitorWM_LBUTTONDOWN.0")	; turn off auto monitoring WM_LBUTTONDOWN
OnMessage(0x201, "WM_LBUTTONDOWN")	; manualy monitor WM_LBUTTONDOWN
Return

^Lbutton::SCW_ScreenClip2Win()	; click & drag
Esc::ExitApp

#Include Gdip.ahk		; by Tic
#Include ScreenClip2Win.ahk		; by Learning one
WM_LBUTTONDOWN() {
	if SCW_LBUTTONDOWN()	; LBUTTONDOWN on module's screen clipping windows - isolate - it's module's buissines
	return
	else	; LBUTTONDOWN on other windows created by script
	MsgBox,,, You clicked on script's window not created by this module,1
}
*/


;===Functions==========================================================================
SCW_Version() {
	return 1.02
}

SCW_DestroyAllClipWins() {
	MaxGuis := SCW_Reg("MaxGuis"), StartAfter := SCW_Reg("StartAfter")
	Loop, %MaxGuis%
	{
		StartAfter++
		Gui %StartAfter%: Destroy
	}
}

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
		}
	}
	
	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_ScreenClip2Win() {
	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_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
	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 
}

SCW_Win2Clipboard(KeepBorders=0) {
	/*	;	does not work for layered windows
	ActiveWinID := WinExist("A")
	pBitmap := Gdip_BitmapFromHWND(ActiveWinID)
	Gdip_SetBitmapToClipboard(pBitmap)
	*/
	Send, !{PrintScreen} ; Active Win's client area to Clipboard
	if !KeepBorders
	{
		pToken := Gdip_Startup()
		pBitmap := Gdip_CreateBitmapFromClipboard()
		Gdip_GetDimensions(pBitmap, w, h)
		pBitmap2 := SCW_CropImage(pBitmap, 3, 3, w-6, h-6)
		Gdip_SetBitmapToClipboard(pBitmap2)
		Gdip_DisposeImage(pBitmap), Gdip_DisposeImage(pBitmap2)
		Gdip_Shutdown("pToken")
	}
}

SCW_CropImage(pBitmap, x, y, w, h) {
   pBitmap2 := Gdip_CreateBitmap(w, h), G2 := Gdip_GraphicsFromImage(pBitmap2)
   Gdip_DrawImage(G2, pBitmap, 0, 0, w, h, x, y, w, h)
   Gdip_DeleteGraphics(G2)
   return pBitmap2
}
Do you got it working now?

DmitryMainichev
  • Members
  • 20 posts
  • Last active: Oct 11 2014 07:51 PM
  • Joined: 15 Jan 2008
It works for me right.

sumon
  • Moderators
  • 1317 posts
  • Last active: Dec 05 2016 10:14 PM
  • Joined: 18 May 2010
I use GDIP in the Std Lib. Anyway, the below code does work perfectly fine. I must be illusionary, or you fixed it. The functionability of capturing several clips seems pretty impressive, although there's no real "user-end" to the script right now. Impressive nevertheless, and it works.

Thanks :)

musketball
  • Members
  • 17 posts
  • Last active: Aug 16 2013 07:16 PM
  • Joined: 07 Mar 2011
Can you re-post ScreenClip2Win? The download link does not work.

I use Screen Clipping with Radial Menu a lot, and I almost always end up pasting the captured image to MS Paint so I can look at it while working in another window. ScreenClip2Win seems like the perfect tool for this.

I tried adding my own code, but of course it did not work at all:
THpostGUI(aRect) {
StringSplit, rt, aRect, `,, %A_Space%%A_Tab%
   nL := rt1
   nT := rt2
   nW := rt3 - rt1
   nH := rt4 - rt2

Gui, Add, Picture, h%nH% w%nW%, %clipboard%
Gui, Show
}

Proud User of Radial Menu

Learning one
  • Members
  • 1483 posts
  • Last active: Jan 02 2016 02:30 PM
  • Joined: 04 Apr 2009
Here are temporary links, until polyehtene fixes autohotkey.net;
ScreenClip2Win.ahk
ScreenClip2Win 2.ahk

My Website • Recommended: AutoHotkey Unicode 32-bit • Join DropBox, Copy


musketball
  • Members
  • 17 posts
  • Last active: Aug 16 2013 07:16 PM
  • Joined: 07 Mar 2011
I can't get anything displayed when I run the test script. The yellow window is drawn, and I inserted Msgboxes to verify that the ScreenClip2Win and Win2Clipboard functions are being called, but the GUI never shows on my screen. Additionally, I can't seem to paste the contents of the clipboard, if there are any. Really hoping to get this going because it would save me time at work. Any ideas?

Thanks.
Proud User of Radial Menu

Learning one
  • Members
  • 1483 posts
  • Last active: Jan 02 2016 02:30 PM
  • Joined: 04 Apr 2009
You are probably using 64-bit AHK with 32-bit Gdip.ahk lib. Run this code and post results;
MsgBox % Clipboard := GetAHKVersion()

GetAHKVersion() {
if (A_PtrSize = "")
return "AutoHotkey" A_Space A_AhkVersion
a := "AutoHotkey_L", b := (A_IsUnicode = 1) ? "Unicode" : "ANSI", c := (A_PtrSize = 8) ? "64-bit" : "32-bit"
return a A_Space b A_Space c A_Space A_AhkVersion
}

My Website • Recommended: AutoHotkey Unicode 32-bit • Join DropBox, Copy


musketball
  • Members
  • 17 posts
  • Last active: Aug 16 2013 07:16 PM
  • Joined: 07 Mar 2011
Ah, you are correct. I changed to 32-bit and the script works wonderfully. Thank you.
Proud User of Radial Menu

Joe Glines
  • Members
  • 118 posts
  • Last active: Jan 24 2016 03:08 PM
  • Joined: 23 Dec 2009

This is one script which a ton of colleagues enjoy but they are on win7/win8 and I'd like to keep it all 64 bit if possible. Is there a 64-bit Gdip.ahk?   I searched the forum but did not find anything other than one mention saying "it was not ready yet"


Automating the mundane 1 script at a time...
https://www.linkedin.com/in/joeglines
The-Automator