molitar Posted September 5, 2023 Share Posted September 5, 2023 How do I load image to pic control on form? ExampleClip() ;Save image to file GDIPlus_ImageSaveToFile($hImage, @ScriptDir & "\Capture1.jpg") $Pic1 = The image save to file created from the Global $hImage = _GDIPlus_BitmapCreateFromHBITMAP($hBitmap) works great but now how do I load this $hImage to the Pic control? Link to comment Share on other sites More sharing options...
Andreik Posted September 5, 2023 Share Posted September 5, 2023 GUICtrlSetImage($PicControl, $ImagePath) But if you already have a handle to the image you don't necessarily need to save it to the disk. When the words fail... music speaks. Link to comment Share on other sites More sharing options...
molitar Posted September 5, 2023 Author Share Posted September 5, 2023 (edited) Yes that was for another button to save file to image but now I want a button to capture to the actual clipboard which works great as I can paste the image into paint but I want it to show the captured image on the form itself. The problem is that I can not figure out how to load it to the form control created with GUICtrlSetImage($Pic1, $hImage) If I try to create form again the form is already created so it's not going to load the image. This is where I am having trouble is how to load the image into the pic control and have it show the picture. The problem is it does not show any error so I expected that it did load but no image is displayed in the form. Still a blank image square. Edited September 5, 2023 by molitar Link to comment Share on other sites More sharing options...
Andreik Posted September 5, 2023 Share Posted September 5, 2023 I don't get your issue if you don't post some reproducing code. It's like a guessing game. $hMain = GUICreate('My GUI', 400, 400) ; You could load the image here $cPic = GUICtrlCreatePic('', 144, 72, 100, 100, 0x00800000) ; WS_BORDER GUISetState() ; but for the sake of example ; let's load it later GUICtrlSetImage($cPic, 'mypic.jpg') Do Until GUIGetMsg() = -3 Isn't this code working for you? And why exactly do you need GUI_SS_DEFAULT_PIC on picture control? When the words fail... music speaks. Link to comment Share on other sites More sharing options...
molitar Posted September 5, 2023 Author Share Posted September 5, 2023 (edited) #include-once #include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #Region ### START Koda GUI section ### Form=c:\users\4477724\desktop\autoit\includes\main.kxf $Main = GUICreate("Main", 615, 437, 192, 124) Global $Button1 = GUICtrlCreateButton("Button1", 56, 72, 75, 25) Global $Button2 = GUICtrlCreateButton("Button2", 288, 72, 75, 25) Global $Pic1 = GUICtrlCreatePic("", 144, 72, 100, 100, BitOR($GUI_SS_DEFAULT_PIC,$WS_BORDER)) Global $Pic2 = GUICtrlCreatePic("", 376, 72, 100, 100, BitOR($GUI_SS_DEFAULT_PIC,$WS_BORDER)) $Label1 = GUICtrlCreateLabel("Screen Change Detector", 132, 2, 351, 40) GUICtrlSetFont(-1, 23, 800, 0, "MS Sans Serif") GUICtrlSetColor(-1, 0x800000) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### #include "C:\Users\4477724\Desktop\AutoIT\includes\SimpleCaptureTool.au3" Local $X1 = 0, $Y1 = 0, $X2 = 0, $Y2 = 0 Global $hImage While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $Button1 ExampleClip() ;Save image to file _GDIPlus_ImageSaveToFile($hImage, @ScriptDir & "\Capture1.jpg") Case $Button2 ExampleClip() ;Display Image in Picture Control GUICtrlSetImage($Pic1, $hImage) <----- No Image displays on form. EndSwitch WEnd Edited September 5, 2023 by molitar Link to comment Share on other sites More sharing options...
Andreik Posted September 5, 2023 Share Posted September 5, 2023 (edited) #include "C:\Users\4477724\Desktop\AutoIT\includes\SimpleCaptureTool.au3" And it's supposed that we all have SimpleCaptureTool.au3 on our computers? Anyway, probably the image it doesn't show because of GUI_SS_DEFAULT_PIC on picture control. I will ask you again, why do you need this style on picture control? Also you use _GDIPlus_ImageSaveToFile() but GDI+ header is not present or the library initialized (at least in main script). So anything it's possible. PS: and please use code tags when you post code on forum, it's more easy to read Edited September 5, 2023 by Andreik When the words fail... music speaks. Link to comment Share on other sites More sharing options...
molitar Posted September 5, 2023 Author Share Posted September 5, 2023 OK the simplecapturetool is a code from another user here so I am just calling the functions from. expandcollapse popup; By FireFox, 2014 ; Version : 1.4 #include-once #include <WindowsConstants.au3> #include <Misc.au3> #include <WinAPI.au3> #include <ScreenCapture.au3> #include <ClipBoard.au3> #include <ColorConstants.au3> #include <Constants.au3> ; Settings Global $_fShowMousePos = True, $_fShowRectSize = True, $_fHideDesktop = False, $_fHideTaskBar = False, $giGDIPRef, $Capture = 0 Local $hGUICapt ;If HotKeySet("{HOME}", "ExampleClip") = 0 Then ; MsgBox($MB_SYSTEMMODAL, "", "Could not set the hotkey !") ; Exit 1 ;EndIf ;HotKeySet("^+{3}", "ExampleClip") ;for Windows under a MacBook lacking of a PrintScreen key (yes... me) ;While 1 ; Sleep(10000) ;10 sec ;WEnd Func ExampleClip() Global $iX1 = 0, $iY1 = 0, $iX2 = 0, $iY2 = 0 Local $hGUICapture = 0 Mark_Rect($hGUICapture, $iX1, $iY1, $iX2, $iY2) Local $hBitmap = _ScreenCapture_CaptureWnd("", $hGUICapture, $iX1, $iY1, $iX2, $iY2, False) Global $hImage = _GDIPlus_BitmapCreateFromHBITMAP($hBitmap) GUIDelete($hGUICapture) Local $fOpenCb = _ClipBoard_Open(0) If Not $fOpenCb Then MsgBox($MB_SYSTEMMODAL, "", "Could not open the clipboard !") Return False EndIf _ClipBoard_Empty() Local $hBitmap3 = _WinAPI_CopyImage($hBitmap, 0, 0, 0, BitOR($LR_COPYDELETEORG, $LR_COPYRETURNORG)) ;Save image to file ;_GDIPlus_ImageSaveToFile($hImage, @ScriptDir & "\Capture.jpg") _WinAPI_DeleteObject($hBitmap) _ClipBoard_SetDataEx($hBitmap3, $CF_BITMAP) _ClipBoard_Close() _WinAPI_DeleteObject($hBitmap3) $Capture = 1 EndFunc ;==>ExampleClip Func Mark_Rect(ByRef $hGUICapture, ByRef $iX1, ByRef $iY1, ByRef $iX2, ByRef $iY2) Local $iX_Pos = 0, $iY_Pos = 0, $iTemp = 0, $iWidth = 0, $iHeight = 0 Local $hMask_1 = 0 Local $hWnd = WinGetHandle("[TITLE:Program Manager;CLASS:Progman]") Local $aWgp = WinGetPos($hWnd) If $_fHideDesktop Then ControlHide($hWnd, "", "[CLASS:SysListView32; INSTANCE:1]") EndIf If $_fHideTaskBar Then WinSetState("[CLASS:Shell_TrayWnd]", "", @SW_HIDE) WinSetState("[CLASS:Button]", "", @SW_HIDE) EndIf Local $hBitmap = _ScreenCapture_Capture("", $aWgp[0], $aWgp[1], $aWgp[2], $aWgp[3]) Local $aSize[2] = [$aWgp[2], $aWgp[3]] $aWgp = 0 $hGUICapture = GUICreate("", $aSize[0], $aSize[1], 0, 0, $WS_POPUP, BitOR($WS_EX_TOOLWINDOW, $WS_EX_APPWINDOW, $WS_EX_TOPMOST)) GUISetCursor($IDC_CROSS, 1, $hGUICapture) If $giGDIPRef = 0 Then _GDIPlus_Startup() EndIf Local $hGraphic = _GDIPlus_GraphicsCreateFromHWND($hGUICapture) Local $hImage = _GDIPlus_BitmapCreateFromHBITMAP($hBitmap) _WinAPI_DeleteObject($hBitmap) WinSetTrans($hGUICapture, "", 0) GUISetState(@SW_SHOWNOACTIVATE, $hGUICapture) _GDIPlus_GraphicsDrawImage($hGraphic, $hImage, 0, 0) _GDIPlus_GraphicsDispose($hGraphic) _GDIPlus_ImageDispose($hImage) If $giGDIPRef > 1 Then _GDIPlus_Shutdown() EndIf WinSetTrans($hGUICapture, "", 255) If $_fHideTaskBar Then WinSetState("[CLASS:Button]", "", @SW_SHOWNOACTIVATE) WinSetState("[CLASS:Shell_TrayWnd]", "", @SW_SHOWNOACTIVATE) EndIf If $_fHideDesktop Then ControlShow($hWnd, "", "[CLASS:SysListView32; INSTANCE:1]") EndIf Local $hGUIRect = GUICreate("", $aSize[0], $aSize[1], 0, 0, $WS_POPUP, BitOR($WS_EX_TOOLWINDOW, $WS_EX_TOPMOST)) GUISetBkColor($COLOR_BLACK) GUISetCursor($IDC_CROSS, 1, $hGUIRect) _GUICreateInvRect($hGUIRect, $aSize, $hMask_1, 0, 0, 1, 1) WinSetTrans($hGUIRect, "", 75) GUISetState(@SW_SHOWNOACTIVATE, $hGUIRect) Local $hUserDLL = DllOpen("user32.dll") Local $aMgp = 0 Local $fExitLoop = False ; Wait until mouse button pressed While Not _IsPressed("01", $hUserDLL) And Not $fExitLoop If $_fShowMousePos Then $aMgp = MouseGetPos() ToolTip("x: " & $aMgp[0] & ", y: " & $aMgp[1], _ $aMgp[0] + ($aMgp[0] > 100 ? -95 : 10), _ $aMgp[1] + ($aMgp[1] > 50 ? -35 : 10)) EndIf Sleep(10) If _IsPressed("1B", $hUserDLL) Then $fExitLoop = True WEnd If $_fShowMousePos Then ToolTip("") EndIf ; Get first mouse position $aMgp = MouseGetPos() $iX1 = $aMgp[0] $iY1 = $aMgp[1] ; Draw rectangle while mouse button pressed While _IsPressed("01", $hUserDLL) And Not $fExitLoop $aMgp = MouseGetPos() ; Set in correct order if required If $aMgp[0] < $iX1 Then $iX_Pos = $aMgp[0] $iWidth = $iX1 - $aMgp[0] Else $iX_Pos = $iX1 $iWidth = $aMgp[0] - $iX1 EndIf If $aMgp[1] < $iY1 Then $iY_Pos = $aMgp[1] $iHeight = $iY1 - $aMgp[1] Else $iY_Pos = $iY1 $iHeight = $aMgp[1] - $iY1 EndIf _GUICreateInvRect($hGUIRect, $aSize, $hMask_1, $iX_Pos, $iY_Pos, $iWidth, $iHeight) If $_fShowRectSize Then ToolTip("w: " & Abs($aMgp[0] - $iX1) & ", h: " & Abs($aMgp[1] - $iY1), _ $aMgp[0] + ((($aMgp[0] > $aSize[0] - 100 Or ($aMgp[0] - $iX1 < 0 And $aMgp[1] - $iY1 < 0)) And $aMgp[0] > 100) ? -95 : 10), _ $aMgp[1] + ((($aMgp[1] > $aSize[1] - 40 Or ($aMgp[0] - $iX1 < 0 And $aMgp[1] - $iY1 < 0)) And $aMgp[1] > 40) ? -35 : 10)) EndIf Sleep(10) If _IsPressed("1B", $hUserDLL) Then $fExitLoop = True WEnd If $_fShowRectSize Then ToolTip("") EndIf _WinAPI_DeleteObject($hMask_1) ; Get second mouse position $iX2 = $aMgp[0] $iY2 = $aMgp[1] ; Set in correct order if required If $iX2 < $iX1 Then $iTemp = $iX1 $iX1 = $iX2 $iX2 = $iTemp EndIf If $iY2 < $iY1 Then $iTemp = $iY1 $iY1 = $iY2 $iY2 = $iTemp EndIf GUIDelete($hGUIRect) DllClose($hUserDLL) EndFunc ;==>Mark_Rect Func _GUICreateInvRect($hWnd, $aSize, ByRef $hMask_1, $iX, $iY, $iW, $iH) Local $hMask_2 = 0, $hMask_3 = 0, $hMask_4 = 0 $hMask_1 = _WinAPI_CreateRectRgn(0, 0, $aSize[0], $iY) $hMask_2 = _WinAPI_CreateRectRgn(0, 0, $iX, $aSize[1]) $hMask_3 = _WinAPI_CreateRectRgn($iX + $iW, 0, $aSize[0], $aSize[1]) $hMask_4 = _WinAPI_CreateRectRgn(0, $iY + $iH, $aSize[0], $aSize[1]) _WinAPI_CombineRgn($hMask_1, $hMask_1, $hMask_2, 2) _WinAPI_CombineRgn($hMask_1, $hMask_1, $hMask_3, 2) _WinAPI_CombineRgn($hMask_1, $hMask_1, $hMask_4, 2) _WinAPI_DeleteObject($hMask_2) _WinAPI_DeleteObject($hMask_3) _WinAPI_DeleteObject($hMask_4) _WinAPI_SetWindowRgn($hWnd, $hMask_1, 1) EndFunc ;==>_GUICreateInvRect The command for save as file to drive works fine. I want to load the captured image to the form so user knows that they actually captured what they wanted. So it's for confirmation. expandcollapse popup#include-once #include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #Region ### START Koda GUI section ### Form=c:\users\4477724\desktop\autoit\includes\main.kxf $Main = GUICreate("Main", 615, 437, 192, 124) Global $Button1 = GUICtrlCreateButton("Button1", 56, 72, 75, 25) Global $Button2 = GUICtrlCreateButton("Button2", 288, 72, 75, 25) Global $Pic1 = GUICtrlCreatePic("", 144, 72, 100, 100, BitOR($GUI_SS_DEFAULT_PIC,$WS_BORDER)) Global $Pic2 = GUICtrlCreatePic("", 376, 72, 100, 100, BitOR($GUI_SS_DEFAULT_PIC,$WS_BORDER)) $Label1 = GUICtrlCreateLabel("Screen Change Detector", 132, 2, 351, 40) GUICtrlSetFont(-1, 23, 800, 0, "MS Sans Serif") GUICtrlSetColor(-1, 0x800000) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### #include "C:\Users\4477724\Desktop\AutoIT\includes\SimpleCaptureTool.au3" Local $X1 = 0, $Y1 = 0, $X2 = 0, $Y2 = 0 Global $hImage While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $Button1 ExampleClip() ;Save image to file _GDIPlus_ImageSaveToFile($hImage, @ScriptDir & "\Capture1.jpg") Case $Button2 ExampleClip() ;Display Image in Picture Control GUICtrlSetImage($Pic1, $hImage) EndSwitch WEnd I know when I developed in Delphi coding if you made a change to the form you called a refresh to the control but I see nothing like that for AutoIT forms. Link to comment Share on other sites More sharing options...
Andreik Posted September 5, 2023 Share Posted September 5, 2023 You can't just pass a handle to GUICtrlSetImage(). You need something like this: $hHBITMAP = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImage) _WinAPI_DeleteObject(GUICtrlSendMsg($Pic1, 0x0172, 0, $hHBITMAP)) ; STM_SETIMAGE = 0x0172 _WinAPI_DeleteObject($hHBITMAP) But probably you need also to resize your bitmap according to your control size. When the words fail... music speaks. Link to comment Share on other sites More sharing options...
ioa747 Posted September 6, 2023 Share Posted September 6, 2023 (edited) I made the SimpleCaptureTool.au3 even simpler, and easier to understand, for a beginner (and for me) put both in a folder, and do a test. If you have any questions, you can post them here MainScript.au3 expandcollapse popup; https://www.autoitscript.com/forum/topic/210785-function-called-from-an-include-the-main-script-does-not-continue/?do=findComment&comment=1523939 #include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #include "MoreSimpleCaptureTool.au3" ;~ Press {HOME} to start Capture If HotKeySet("{HOME}", "MSCT_CaptureToClip") = 0 Then MsgBox($MB_SYSTEMMODAL, "exit Code", "Could not set the {HOME} hotkey !") Exit 1 EndIf #Region ### START Koda GUI section ### Form=c:\users\4477724\desktop\autoit\includes\main.kxf $Main = GUICreate("main", 615, 437, 192, 124) Global $Button1 = GUICtrlCreateButton("Button1", 56, 72, 75, 25) Global $Button2 = GUICtrlCreateButton("Button2", 288, 72, 75, 25) Global $Pic1 = GUICtrlCreatePic("", 144, 72, 100, 100, BitOR($GUI_SS_DEFAULT_PIC, $WS_BORDER)) Global $Pic2 = GUICtrlCreatePic("", 376, 72, 100, 100, BitOR($GUI_SS_DEFAULT_PIC, $WS_BORDER)) $Label1 = GUICtrlCreateLabel("Screen Change Detector", 132, 2, 351, 40) GUICtrlSetFont(-1, 23, 800, 0, "MS Sans Serif") GUICtrlSetColor(-1, 0x800000) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### Global $MyPic While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $Button1 ;Save image to file $MyPic = MSCT_Capture(@ScriptDir & "\Capture1.jpg") GUICtrlSetImage($Pic1, $MyPic) ShellExecute($MyPic) Case $Button2 $MyPic = MSCT_Capture() ;Display Image in Picture Control GUICtrlSetImage($Pic2, $MyPic) EndSwitch WEnd MoreSimpleCaptureTool.au3 expandcollapse popup#include-once #include <ScreenCapture.au3> #include <WindowsConstants.au3> #include <Clipboard.au3> #include <Misc.au3> ; #INDEX# ======================================================================================================================= ; Title .........: MoreSimpleCaptureTool (MSCT) ; AutoIt Version : 3.3.16.1 ; Language ......: English ; Description ...: Tool for capturing region of DeskTop ; Author(s) .....: ioa747 ; =============================================================================================================================== ;---------------------------------------------------------------------------------------- Func MSCT_CaptureToClip() Local $ClipBak = ClipGet() ;BackUp ClipBoard ClipPut("<empty>") Local $Path = MSCT_Capture() _PicToClip($Path) If ClipGet() = "<empty>" Then ClipPut($ClipBak) ;Restore ClipBoard BackUp Return SetError(1, 1, 0) Else TrayTip("", "Image saved to ClipBoard", 1, 1) EndIf EndFunc ;==>MSCT_CaptureToClip ;---------------------------------------------------------------------------------------- Func MSCT_Capture($FilePath = Default) If FileExists(@ScriptDir & "\Default.jpg") Then FileDelete(@ScriptDir & "\Default.jpg") If $FilePath = Default Then $FilePath = @ScriptDir & "\Default.jpg" ; make Capture gui Local $hGUICapture = GUICreate("Capture_gui", 200, 200, 1, 1, $WS_POPUP, BitOR($WS_EX_TOOLWINDOW, $WS_EX_TOPMOST)) GUISetBkColor("0xFFFF00") ; $COLOR_YELLOW WinSetTrans($hGUICapture, "", 50) ; make mouse block gui Local $block_gui = GUICreate("block_gui", @DesktopWidth, @DesktopHeight, -1, -1, $WS_POPUP, BitOR($WS_EX_TOOLWINDOW, $WS_EX_TOPMOST)) WinSetTrans($block_gui, "", 1) GUISetState(@SW_SHOW, $block_gui) GUISetCursor(3, 1, $block_gui) Local $aMPos, $aRecPos[4], $Status = 0 While Sleep(50) $aMPos = MouseGetPos() ToolTip("x: " & $aMPos[0] & ", y: " & $aMPos[1], $aMPos[0] + ($aMPos[0] > 100 ? -95 : 10), $aMPos[1] + ($aMPos[1] > 50 ? -35 : 10)) ; whait Left_mouse_button _IsPressed If _IsPressed("01") Then $Status = 1 $aMPos = MouseGetPos() $aRecPos[0] = $aMPos[0] $aRecPos[1] = $aMPos[1] ; Wait until key is released. While _IsPressed("01") Sleep(50) $aMPos = MouseGetPos() $aRecPos[2] = $aMPos[0] $aRecPos[3] = $aMPos[1] ToolTip("x: " & $aMPos[0] & ", y: " & $aMPos[1], $aMPos[0] + ($aMPos[0] > 100 ? -95 : 10), $aMPos[1] + ($aMPos[1] > 50 ? -35 : 10)) ; show Capture gui GUISetState(@SW_SHOW, $hGUICapture) WinMove($hGUICapture, "", $aRecPos[0], $aRecPos[1], $aRecPos[2] - $aRecPos[0], $aRecPos[3] - $aRecPos[1]) WEnd EndIf If $Status = 1 Then ExitLoop WEnd WinSetTrans($hGUICapture, "", 0) WinSetTrans($block_gui, "", 0) ToolTip("") ; Capture window _ScreenCapture_CaptureWnd($FilePath, $hGUICapture) GUIDelete($hGUICapture) GUIDelete($block_gui) Return $FilePath EndFunc ;==>MSCT_Capture ;---------------------------------------------------------------------------------------- Func _PicToClip($Path) ; put image to clipboard (Thanks to @Nine) _GDIPlus_Startup() Local $hImage = _GDIPlus_ImageLoadFromFile($Path) Local $hBitmap1 = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImage) _GDIPlus_ImageDispose($hImage) Local $hBitmap2 = _WinAPI_CopyImage($hBitmap1, $IMAGE_BITMAP, 0, 0, $LR_COPYDELETEORG + $LR_COPYRETURNORG) _WinAPI_DeleteObject($hBitmap1) _GDIPlus_Shutdown() _ClipBoard_Open(0) _ClipBoard_Empty() _ClipBoard_SetDataEx($hBitmap2, $CF_BITMAP) _ClipBoard_Close() _WinAPI_DeleteObject($hBitmap2) EndFunc ;==>_PicToClip ;---------------------------------------------------------------------------------------- Edited September 6, 2023 by ioa747 UpDate I know that I know nothing Link to comment Share on other sites More sharing options...
molitar Posted September 6, 2023 Author Share Posted September 6, 2023 (edited) 2 hours ago, ioa747 said: I made the SimpleCaptureTool.au3 even simpler, and easier to understand, for a beginner (and for me) put both in a folder, and do a test. If you have any questions, you can post them here ioa747 thank it's much cleaner but the cursor + is not working on multiple monitors so I added the wiki function for multiple monitors. At first it appeared to be working but I found a strange quirk when I moved the x coordinate past 2800 the + cursor disappeared and it showed as normal cursor but move it back under x 2800 coordinate and it goes back to the + cursor. x = 0 - 2800 (cursor appears correctly as the +) X = 2801 - 3060 (cursor reverts back to default mouse cursor so can't tell your still in capture mode though it is) #include-once #include <ScreenCapture.au3> #include <WindowsConstants.au3> #include <Clipboard.au3> #include <Misc.au3> ; #INDEX# ======================================================================================================================= ; Title .........: MoreSimpleCaptureTool (MSCT) ; AutoIt Version : 3.3.16.1 ; Language ......: English ; Description ...: Tool for capturing region of DeskTop ; Author(s) .....: ioa747 ; =============================================================================================================================== Global $aTSR = _GetTotalScreenResolution() ConsoleWrite("Total Screen Resolution" & @CRLF & "Width = " & $aTSR[0] & @CRLF & "Height = " & $aTSR[1]) ;Original code by Larry. ;Edited by BrettF Func _GetTotalScreenResolution() Local $aRet[2] Global Const $SM_VIRTUALWIDTH = 78 Global Const $SM_VIRTUALHEIGHT = 79 $VirtualDesktopWidth = DllCall("user32.dll", "int", "GetSystemMetrics", "int", $SM_VIRTUALWIDTH) $aRet[0] = $VirtualDesktopWidth[0] $VirtualDesktopHeight = DllCall("user32.dll", "int", "GetSystemMetrics", "int", $SM_VIRTUALHEIGHT) $aRet[1] = $VirtualDesktopHeight[0] Return $aRet EndFunc ;==>_GetTotalScreenResolution Changed this line from ; make mouse block gui Local $block_gui = GUICreate("block_gui", @DesktopWidth, @DesktopHeight, -1, -1, $WS_POPUP, BitOR($WS_EX_TOOLWINDOW, $WS_EX_TOPMOST)) To this ; make mouse block gui Local $block_gui = GUICreate("block_gui", $aTSR[0], $aTSR[1], -1, -1, $WS_POPUP, BitOR($WS_EX_TOOLWINDOW, $WS_EX_TOPMOST)) #include-once #include <ScreenCapture.au3> #include <WindowsConstants.au3> #include <Clipboard.au3> #include <Misc.au3> ; #INDEX# ======================================================================================================================= ; Title .........: MoreSimpleCaptureTool (MSCT) ; AutoIt Version : 3.3.16.1 ; Language ......: English ; Description ...: Tool for capturing region of DeskTop ; Author(s) .....: ioa747 ; =============================================================================================================================== Global $aTSR = _GetTotalScreenResolution() ConsoleWrite("Total Screen Resolution" & @CRLF & "Width = " & $aTSR[0] & @CRLF & "Height = " & $aTSR[1]) ;Original code by Larry. ;Edited by BrettF Func _GetTotalScreenResolution() Local $aRet[2] Global Const $SM_VIRTUALWIDTH = 78 Global Const $SM_VIRTUALHEIGHT = 79 $VirtualDesktopWidth = DllCall("user32.dll", "int", "GetSystemMetrics", "int", $SM_VIRTUALWIDTH) $aRet[0] = $VirtualDesktopWidth[0] $VirtualDesktopHeight = DllCall("user32.dll", "int", "GetSystemMetrics", "int", $SM_VIRTUALHEIGHT) $aRet[1] = $VirtualDesktopHeight[0] Return $aRet EndFunc ;==>_GetTotalScreenResolution Edited September 6, 2023 by molitar Link to comment Share on other sites More sharing options...
ioa747 Posted September 6, 2023 Share Posted September 6, 2023 , to make it work on multiple monitors, need more work, and especially if the extra monitor doesn't have 100% dip scale take a look here, if you draw any conclusion I'll try it, see if I can make it, when I have some time I know that I know nothing Link to comment Share on other sites More sharing options...
molitar Posted September 6, 2023 Author Share Posted September 6, 2023 Thanks for now I just added this to the mainscript.au3. Global $DesktopWidth = $aTSR[0] + 1921, $DesktopHeight = $aTSR[1] Global $DesktopWidth = $aTSR[0] + 1921, $DesktopHeight = $aTSR[1] This now allows me to scroll all the way across it does not affect the screen capture at all just affects the $block_gui. This will tide me over for now until you get a chance to clean it up. Thank you. Link to comment Share on other sites More sharing options...
ioa747 Posted September 7, 2023 Share Posted September 7, 2023 22 hours ago, molitar said: Thanks for now I just added this to the mainscript.au3. Global $DesktopWidth = $aTSR[0] + 1921, $DesktopHeight = $aTSR[1] and how does that help? since I don't see any use of $DesktopWidth or $DesktopHeight anywhere I know that I know nothing Link to comment Share on other sites More sharing options...
molitar Posted September 7, 2023 Author Share Posted September 7, 2023 I replaced these $aTSR[0] and $aTSR[1] with $DesktopWidth and $DesktopHeight. This way when get fixed version of script I can just remove the added 1921 to the x coordinates. Link to comment Share on other sites More sharing options...
Solution ioa747 Posted September 7, 2023 Solution Share Posted September 7, 2023 (edited) First of all I changed the name because it's not that simple anymore, but works on multi monitors, the mouse works normally, and the tooltip goes to its place Example.au3 expandcollapse popup; https://www.autoitscript.com/forum/topic/210785-function-called-from-an-include-the-main-script-does-not-continue/?do=findComment&comment=1523939 #include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #include "SnippingTool.au3" ; * <- ;~ Press {HOME} to start Capture If HotKeySet("{HOME}", "SNIP_CaptureToClip") = 0 Then MsgBox($MB_SYSTEMMODAL, "exit Code", "Could not set the {HOME} hotkey !") Exit 1 EndIf #Region ### START Koda GUI section ### Form=c:\users\4477724\desktop\autoit\includes\main.kxf $Main = GUICreate("main", 615, 437, 192, 124) Global $Button1 = GUICtrlCreateButton("Button1", 56, 72, 75, 25) Global $Button2 = GUICtrlCreateButton("Button2", 288, 72, 75, 25) Global $Pic1 = GUICtrlCreatePic("", 144, 72, 100, 100, BitOR($GUI_SS_DEFAULT_PIC, $WS_BORDER)) Global $Pic2 = GUICtrlCreatePic("", 376, 72, 100, 100, BitOR($GUI_SS_DEFAULT_PIC, $WS_BORDER)) $Label1 = GUICtrlCreateLabel("Screen Change Detector", 132, 2, 351, 40) GUICtrlSetFont(-1, 23, 800, 0, "MS Sans Serif") GUICtrlSetColor(-1, 0x800000) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### Global $MyPic While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $Button1 ;Save image to file $MyPic = SNIP_Capture(@ScriptDir & "\Capture1.jpg") If $MyPic Then GUICtrlSetImage($Pic1, $MyPic) ShellExecute($MyPic) EndIf Case $Button2 $MyPic = SNIP_Capture() ;Display Image in Picture Control GUICtrlSetImage($Pic2, $MyPic) EndSwitch WEnd SnippingTool.au3 expandcollapse popup; https://www.autoitscript.com/forum/topic/210786-how-to-load-a-saved-image-variable-to-pic-on-form/#comment-1524040 ;~ #AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 -w 7 #include-once #include <ScreenCapture.au3> #include <WindowsConstants.au3> #include <Clipboard.au3> #include <Misc.au3> #include <WinAPIIcons.au3> ; #INDEX# ======================================================================================================================= ; Title .........: SnippingTool.au3 (SNIP) ; AutoIt Version : 3.3.16.1 ; Language ......: English ; Description ...: Tool for capturing region of DeskTop ; Author(s) .....: ioa747 ; =============================================================================================================================== #AutoIt3Wrapper_UseX64=n DllCall("user32.dll", "bool", "SetProcessDpiAwarenessContext", "int", -4) ; -4=PerMonitorAwareV2 ;---------------------------------------------------------------------------------------- Func SNIP_CaptureToClip() Local $ClipBak = ClipGet() ;BackUp ClipBoard ClipPut("<empty>") Local $Path = SNIP_Capture() _PicToClip($Path) If ClipGet() = "<empty>" Then ClipPut($ClipBak) ;Restore ClipBoard BackUp Return SetError(1, 1, 0) Else TrayTip("", "Image saved to ClipBoard", 1, 1) EndIf EndFunc ;==>SNIP_CaptureToClip ;---------------------------------------------------------------------------------------- Func SNIP_Capture($FilePath = Default) If FileExists(@ScriptDir & "\Default.jpg") Then FileDelete(@ScriptDir & "\Default.jpg") If $FilePath = Default Then $FilePath = @ScriptDir & "\Default.jpg" ; make Capture gui Local $hGUICapture = GUICreate("Capture_gui", 200, 200, 1, 1, $WS_POPUP, BitOR($WS_EX_TOOLWINDOW, $WS_EX_TOPMOST)) GUISetBkColor("0xFFFF00", $hGUICapture) ; $COLOR_YELLOW WinSetTrans($hGUICapture, "", 50) ; make mouse block gui Local $block_gui = GUICreate("block_gui", 100, 100, -1, -1, $WS_POPUP, BitOR($WS_EX_TOOLWINDOW, $WS_EX_TOPMOST)) WinSetTrans($block_gui, "", 1) GUISetState(@SW_SHOW, $block_gui) GUISetCursor($MCID_CROSS, 1, $block_gui) Local $aRecPos[4], $aMPos[2], $aTipPos[4], $tPos, $iX, $iY Local $iDeskWidth, $iDeskHeight, $iDeskLeft, $iDeskTop Local $sDevice, $sCurDevice, $Status = 0 Local $hDLL = DllOpen("user32.dll") ;Put Option to 0 to prevents gui from close Opt("GUICloseOnESC", 0) ;1=ESC closes, 0=ESC won't close While Sleep(50) ; get mouse coordinates $tPos = _WinAPI_GetMousePos() $aMPos[0] = DllStructGetData($tPos, 1) $aMPos[1] = DllStructGetData($tPos, 2) ; get $hMonitor from previously defined Mouse coordinates Local $hMonitor = _WinAPI_MonitorFromPoint($tPos) ; get monitor $aData appropriate for previously defined coordinates Local $aData = _WinAPI_GetMonitorInfo($hMonitor) If Not @error Then $sDevice = $aData[3] $iDeskLeft = DllStructGetData($aData[0], 1) $iDeskTop = DllStructGetData($aData[0], 2) $iDeskWidth = DllStructGetData($aData[0], 3) $iDeskHeight = DllStructGetData($aData[0], 4) EndIf ; Keep ToolTip on screen If $aMPos[0] > ($iDeskWidth - ($aTipPos[2] * 1.5)) Then $iX = $aMPos[0] - ($aTipPos[2] * 1.5) Else $iX = $aMPos[0] + ($aTipPos[2] * 0.5) EndIf If $aMPos[1] > ($iDeskHeight - ($aTipPos[3] * 1.5)) Then $iY = $aMPos[1] - ($aTipPos[3] * 1.5) Else $iY = $aMPos[1] + ($aTipPos[3] * 0.5) EndIf ToolTip("x: " & $aMPos[0] & ", y: " & $aMPos[1], $iX, $iY) $aTipPos = WinGetPos("[TITLE:x:; CLASS:tooltips_class32]") ;move the $block_gui to active monitor If $sCurDevice <> $sDevice Then $sCurDevice = $sDevice ;ConsoleWrite("- $sCurDevice=" & $sCurDevice & @CRLF) WinMove($block_gui, "", $iDeskLeft, $iDeskTop, $iDeskWidth, $iDeskHeight) EndIf ; whait Left_mouse_button _IsPressed If _IsPressed("01", $hDLL) Then $Status = 1 $aMPos = MouseGetPos() $aRecPos[0] = $aMPos[0] $aRecPos[1] = $aMPos[1] ; Wait until key is released. While _IsPressed("01", $hDLL) Sleep(50) $aMPos = MouseGetPos() $aRecPos[2] = $aMPos[0] $aRecPos[3] = $aMPos[1] ; Keep ToolTip on screen If $aMPos[0] > ($iDeskWidth - ($aTipPos[2] * 1.5)) Then $iX = $aMPos[0] - ($aTipPos[2] * 1.5) Else $iX = $aMPos[0] + ($aTipPos[2] * 0.5) EndIf If $aMPos[1] > ($iDeskHeight - ($aTipPos[3] * 1.5)) Then $iY = $aMPos[1] - ($aTipPos[3] * 1.5) Else $iY = $aMPos[1] + ($aTipPos[3] * 0.5) EndIf ToolTip("x: " & $aMPos[0] & ", y: " & $aMPos[1], $iX, $iY) $aTipPos = WinGetPos("[TITLE:x:; CLASS:tooltips_class32]") ; show Capture gui GUISetState(@SW_SHOW, $hGUICapture) WinMove($hGUICapture, "", $aRecPos[0], $aRecPos[1], $aRecPos[2] - $aRecPos[0], $aRecPos[3] - $aRecPos[1]) WEnd ElseIf _IsPressed("1B", $hDLL) Then ;1B=ESC key - emergency exit ToolTip("") GUIDelete($hGUICapture) GUIDelete($block_gui) DllClose($hDLL) ;Put Option back to 1 Opt("GUICloseOnESC", 1) ;1=ESC closes, 0=ESC won't close Return SetError(1, 1, 0) EndIf If $Status = 1 Then ExitLoop WEnd WinSetTrans($hGUICapture, "", 0) WinSetTrans($block_gui, "", 0) ToolTip("") DllClose($hDLL) ;Put Option back to 1 Opt("GUICloseOnESC", 1) ;1=ESC closes, 0=ESC won't close ;move the mouse out of pic $aMPos = MouseGetPos() MouseMove($aMPos[0] + 10, $aMPos[1] + 10) ; Capture window _ScreenCapture_CaptureWnd($FilePath, $hGUICapture) GUIDelete($hGUICapture) GUIDelete($block_gui) Return $FilePath EndFunc ;==>SNIP_Capture ;---------------------------------------------------------------------------------------- Func _PicToClip($Path) ; put image to clipboard (Thanks to @Nine) _GDIPlus_Startup() Local $hImage = _GDIPlus_ImageLoadFromFile($Path) Local $hBitmap1 = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImage) _GDIPlus_ImageDispose($hImage) Local $hBitmap2 = _WinAPI_CopyImage($hBitmap1, $IMAGE_BITMAP, 0, 0, $LR_COPYDELETEORG + $LR_COPYRETURNORG) _WinAPI_DeleteObject($hBitmap1) _GDIPlus_Shutdown() _ClipBoard_Open(0) _ClipBoard_Empty() _ClipBoard_SetDataEx($hBitmap2, $CF_BITMAP) _ClipBoard_Close() _WinAPI_DeleteObject($hBitmap2) EndFunc ;==>_PicToClip ;---------------------------------------------------------------------------------------- Edited September 9, 2023 by ioa747 UpDate I know that I know nothing Link to comment Share on other sites More sharing options...
molitar Posted September 19, 2023 Author Share Posted September 19, 2023 I'll test this when I get a chance been really busy at work right now due to some changes going on. Link to comment Share on other sites More sharing options...
molitar Posted September 20, 2023 Author Share Posted September 20, 2023 Thanks the new script worked great across 3 monitors. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now