FMS Posted June 10, 2011 Share Posted June 10, 2011 (edited) Hi all,I'm making a complex script (4me ) for learning reasons from 2 scripts in this forum .(thnx 2 Melba and UEZ and others )I'm not shure iff mine aprouch is the right one and maybe some poeple have pointers how to do it better because i've missed something or din't see:DFor this script u need GDIplus and animate includes ....The idea of this script is a simple one....just making a screenshot whit a hotkey or a button in a GDI GUI (or how it's colled:D)EDIT:and a hotkey for removing the GDI GUI but still working script in the backgroundand a animated taskbaricon....(there are some problems i can't explain- buttons in GDI doesnt work:S)beside that is the main question: what do u think of this script ? maybe u can make me learn something expandcollapse popup#include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #Include <Animate.au3> #Include <ScreenCapture.au3> #Include <Misc.au3> #include <GDIPlus.au3> Global $hGUI, $hImage, $hGraphic, $hImage Global Const $SC_DRAGMOVE = 0xF012 Global $GuiMsg Global $Show = False Global $HelpGUI = GUICreate("Help Gui", 500, 200) Global $iX1, $iY1, $iX2, $iY2, $aPos, $sMsg, $sBMP_Path, $i global $hBitmap_GUI HotKeySet("!z", "ShowGUI") HotKeySet("!x", "ExitPT") HotKeySet("!c", "Snip") _Animate_LoadFromFile(@ScriptDir & '\Images\flag.png') _Animate_SetDelay(80) _Animate_ShowIcon() _Animate_Start() _GDIPlus_Startup() ; Load PNG image $hImage = _GDIPlus_ImageLoadFromFile("Images\Exclamation.png") $iWidth = _GDIPlus_ImageGetWidth($hImage) $iHeight = _GDIPlus_ImageGetHeight($hImage) ; Create GUI $hMain_GUI = GUICreate("Show PNG", $iWidth, $iHeight, -1, -1, $WS_POPUP, $WS_EX_LAYERED + $WS_EX_TOPMOST);hGUI=HmainGUI $hGUI_child = GUICreate("", $iWidth, $iHeight, 0, 0, $WS_POPUP, $WS_EX_LAYERED + $WS_EX_TOPMOST + $WS_EX_MDICHILD, $hMain_GUI);hGUI=HmainGUI $hRect_Button = GUICtrlCreateButton("Snip", $iWidth * 2 / 3, $iHeight * 2 / 3, 40, 40);Hbutton=Hrectbutton GUISetBkColor(0xFFFFFF, $hGUI_child) GUISetState(@SW_SHOW, $hMain_GUI) GUISetState(@SW_SHOW, $hGUI_child) SetTransparentBitmap($hMain_GUI, $hImage) _WinAPI_SetLayeredWindowAttributes($hGUI_child, 0xFFFFFF, 0xff) $hGraphic = _GDIPlus_GraphicsCreateFromHWND($hGUI_child) _GDIPlus_GraphicsSetSmoothingMode($hGraphic, 2) DllCall($ghGDIPDll, "uint", "GdipSetTextRenderingHint", "handle", $hGraphic, "int", 4) _GDIPlus_GraphicsDrawString($hGraphic, "GDI+ Full Transparency", 0, $iHeight / 2 - 20, "Arial", 24) GUIRegisterMsg($WM_LBUTTONDOWN, "_WM_LBUTTONDOWN") While 1 $nMsg = GUIGetMsg(1) Switch $nMsg[1] Case $hMain_GUI Switch $nMsg[0] Case $GUI_EVENT_CLOSE GUIRegisterMsg($WM_LBUTTONDOWN, "") _GDIPlus_ImageDispose($hImage) _GDIPlus_GraphicsDispose($hGraphic) _GDIPlus_Shutdown() GUIDelete($hMain_GUI) ExitLoop Case $hRect_Button Snip() EndSwitch Case else Switch $nMsg[0] Case $GUI_EVENT_CLOSE GUIdelete($nMsg[1]) EndSwitch EndSwitch WEnd Func _WM_LBUTTONDOWN($hWnd, $iMsg, $wParam, $lParam) _SendMessage($hMain_GUI, $WM_SYSCOMMAND, $SC_DRAGMOVE, 0) EndFunc ;==>_WM_LBUTTONDOWN Func SetTransparentBitmap($hGUI, $hImage, $iOpacity = 0xFF) Local $hScrDC, $hMemDC, $hBitmap, $hOld, $pSize, $tSize, $pSource, $tSource, $pBlend, $tBlend $hScrDC = _WinAPI_GetDC(0) $hMemDC = _WinAPI_CreateCompatibleDC($hScrDC) $hBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImage) $hOld = _WinAPI_SelectObject($hMemDC, $hBitmap) $tSize = DllStructCreate($tagSIZE) $pSize = DllStructGetPtr($tSize) DllStructSetData($tSize, "X", _GDIPlus_ImageGetWidth($hImage)) DllStructSetData($tSize, "Y", _GDIPlus_ImageGetHeight($hImage)) $tSource = DllStructCreate($tagPOINT) $pSource = DllStructGetPtr($tSource) $tBlend = DllStructCreate($tagBLENDFUNCTION) $pBlend = DllStructGetPtr($tBlend) DllStructSetData($tBlend, "Alpha", $iOpacity) DllStructSetData($tBlend, "Format", 1) _WinAPI_UpdateLayeredWindow($hGUI, $hMemDC, 0, $pSize, $hMemDC, $pSource, 0, $pBlend, $ULW_ALPHA) _WinAPI_ReleaseDC(0, $hScrDC) _WinAPI_SelectObject($hMemDC, $hOld) _WinAPI_DeleteObject($hBitmap) _WinAPI_DeleteDC($hMemDC) EndFunc ;==>SetTransparentBitmap Func ShowGUI() $Show = Not $Show GUISetState($Show, $hMain_GUI) EndFunc Func ExitPT() Exit EndFunc Func Snip() GUISetState(@SW_HIDE, $hMain_GUI) Mark_Rect() $sBMP_Path = "" $i = 0 Do $i += 1 $sBMP_Path = @SCriptDir & "\File" & StringFormat("%02s", $i) & ".bmp" Until Not FileExists($sBMP_Path) _ScreenCapture_Capture($sBMP_Path, $iX1, $iY1, $iX2, $iY2, False) $hBitmap_GUI = GUICreate("Selected Rectangle", $iX2 - $iX1 + 1, $iY2 - $iY1 + 1, 100, 100) $hPic = GUICtrlCreatePic($sBMP_Path, 0, 0, $iX2 - $iX1 + 1, $iY2 - $iY1 + 1) GUISetState() EndFunc Func Mark_Rect() Local $aMouse_Pos, $hMask, $hMaster_Mask, $iTemp Local $UserDLL = DllOpen("user32.dll") Global $hRectangle_GUI = GUICreate("", @DesktopWidth, @DesktopHeight, 0, 0, $WS_POPUP, $WS_EX_TOOLWINDOW + $WS_EX_TOPMOST) _GUICreateInvRect($hRectangle_GUI, 0, 0, 1, 1) GUISetBkColor(0) WinSetTrans($hRectangle_GUI, "", 50) GUISetState(@SW_SHOW, $hRectangle_GUI) GUISetCursor(3, 1, $hRectangle_GUI) ; 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() ; Set in correct order if required If $aMouse_Pos[0] < $iX1 Then $iX_Pos = $aMouse_Pos[0] $iWidth = $iX1 - $aMouse_Pos[0] Else $iX_Pos = $iX1 $iWidth = $aMouse_Pos[0] - $iX1 EndIf If $aMouse_Pos[1] < $iY1 Then $iY_Pos = $aMouse_Pos[1] $iHeight = $iY1 - $aMouse_Pos[1] Else $iY_Pos = $iY1 $iHeight = $aMouse_Pos[1] - $iY1 EndIf _GUICreateInvRect($hRectangle_GUI, $iX_Pos, $iY_Pos, $iWidth, $iHeight) 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) DllClose($UserDLL) EndFunc Func _GUICreateInvRect($hWnd, $iX, $iY, $iW, $iH) $hMask_1 = _WinAPI_CreateRectRgn(0, 0, @DesktopWidth, $iY) $hMask_2 = _WinAPI_CreateRectRgn(0, 0, $iX, @DesktopHeight) $hMask_3 = _WinAPI_CreateRectRgn($iX + $iW, 0, @DesktopWidth, @DesktopHeight) $hMask_4 = _WinAPI_CreateRectRgn(0, $iY + $iH, @DesktopWidth, @DesktopHeight) _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 Edited June 10, 2011 by FMS as finishing touch god created the dutch 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