Hallo Zusammen,
für mein Thema "Button / Icons aus DB bzw. Array erstellen", bei dem ich unser IT Helpdesk Tool auf den neuen Stand bringe, benötige ich noch ein angepasstes "Screenshot Tool", bei dem der Screenshot per Mausauswahl (markierter Bereich) gespeichert wird. Im engl. Forum bin ich da auch fündig geworden und habe mir folgenden Quellcode angepasst.
Meine Frage dazu , passt das so oder kann man hier optimieren?
AutoIt
#include <GuiConstantsEx.au3>
#include <WindowsConstants.au3>
#Include <ScreenCapture.au3>
#Include <Misc.au3>
Global $iX1, $iY1, $iX2, $iY2, $aPos, $sMsg, $jpg_Path
;--- Create GUI ---
$hMain_GUI = GUICreate("Screenshot-Tool", 240, 50)
$hRect_Button = GUICtrlCreateButton("NEU", 10, 10, 80, 25)
GUISetState(@SW_SHOW)
While 1
$iMsg = GUIGetMsg()
Switch $iMsg
Case $GUI_EVENT_CLOSE
Exit
Case $hRect_Button
$jpg_Path = @ScriptDir & "\Rect.jpg"
If FileExists($jpg_Path) Then FileDelete($jpg_Path)
GUISetState(@SW_HIDE, $hMain_GUI)
Mark_Rect()
; Capture selected area
_ScreenCapture_Capture($jpg_Path, $iX1, $iY1, $iX2, $iY2, False)
GUISetState(@SW_SHOW, $hMain_GUI)
_Display_image() ; Display image
EndSwitch
WEnd
Func _Display_image()
; Display image
$hscreen_GUI = GUICreate("Image Vorschau ...", $iX2 - $iX1 + 1, $iY2 - $iY1 + 1, 100, 100)
$hPic = GUICtrlCreatePic(@ScriptDir & "\Rect.jpg", 0, 0, $iX2 - $iX1 + 1, $iY2 - $iY1 + 1)
GUISetState(@SW_SHOW)
While 1
$iMsg = GUIGetMsg()
Switch $iMsg
Case $GUI_EVENT_CLOSE
GUIDelete($hscreen_GUI)
ExitLoop
EndSwitch
WEnd
EndFunc
Func Mark_Rect()
Local $aMouse_Pos, $hMask, $hMaster_Mask, $iTemp
Local $UserDLL = DllOpen("user32.dll")
; Create transparent GUI with Cross cursor
$hCross_GUI = GUICreate("Screenshot", @DesktopWidth, @DesktopHeight - 20, 0, 0, $WS_POPUP, $WS_EX_TOPMOST)
WinSetTrans($hCross_GUI, "", 8)
GUISetState(@SW_SHOW, $hCross_GUI)
GUISetCursor(3, 1, $hCross_GUI)
Global $hRectangle_GUI = GUICreate("", @DesktopWidth, @DesktopHeight, 0, 0, $WS_POPUP, $WS_EX_TOOLWINDOW + $WS_EX_TOPMOST)
GUISetBkColor(0xFF0000)
; Wait until mouse button pressed
While Not _IsPressed("01", $UserDLL)
Sleep(10)
WEnd
; Get first mouse position
$aMouse_Pos = MouseGetPos()
$iX1 = $aMouse_Pos[0]
$iY1 = $aMouse_Pos[1]
; Draw rectangle while mouse button pressed
While _IsPressed("01", $UserDLL)
$aMouse_Pos = MouseGetPos()
$hMaster_Mask = _WinAPI_CreateRectRgn(0, 0, 0, 0)
$hMask = _WinAPI_CreateRectRgn($iX1, $aMouse_Pos[1], $aMouse_Pos[0], $aMouse_Pos[1] + 1) ; Bottom of rectangle
_WinAPI_CombineRgn($hMaster_Mask, $hMask, $hMaster_Mask, 2)
_WinAPI_DeleteObject($hMask)
$hMask = _WinAPI_CreateRectRgn($iX1, $iY1, $iX1 + 1, $aMouse_Pos[1]) ; Left of rectangle
_WinAPI_CombineRgn($hMaster_Mask, $hMask, $hMaster_Mask, 2)
_WinAPI_DeleteObject($hMask)
$hMask = _WinAPI_CreateRectRgn($iX1 + 1, $iY1 + 1, $aMouse_Pos[0], $iY1) ; Top of rectangle
_WinAPI_CombineRgn($hMaster_Mask, $hMask, $hMaster_Mask, 2)
_WinAPI_DeleteObject($hMask)
$hMask = _WinAPI_CreateRectRgn($aMouse_Pos[0], $iY1, $aMouse_Pos[0] + 1, $aMouse_Pos[1]) ; Right of rectangle
_WinAPI_CombineRgn($hMaster_Mask, $hMask, $hMaster_Mask, 2)
_WinAPI_DeleteObject($hMask)
; Set overall region
_WinAPI_SetWindowRgn($hRectangle_GUI, $hMaster_Mask)
If WinGetState($hRectangle_GUI) < 15 Then GUISetState()
Sleep(10)
WEnd
; Get second mouse position
$iX2 = $aMouse_Pos[0]
$iY2 = $aMouse_Pos[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($hRectangle_GUI)
GUIDelete($hCross_GUI)
DllClose($UserDLL)
EndFunc ;==>Mark_Rect
Alles anzeigen
Danke
Gruß gmmg