Leaderboard
Popular Content
Showing content with the highest reputation on 11/30/2018 in all areas
-
Here another example to mark the desktop to get the marked region for capturing. This example is not perfect and not very fast (room for improvements). ;Coded by UEZ build 2020-08-07 beta ;Code cleanup up mLipok ; ;Short instruction: mark area on your desktop and press return key to capture. #include <APISysConstants.au3> #include <Array.au3> ;#include <GDIPlus.au3> #include <GUIConstantsEx.au3> #include <ScreenCapture.au3> #include <WinAPIGdi.au3> #include <WinAPISysWin.au3> #include <WindowsConstants.au3> ; enum _PROCESS_DPI_AWARENESS -> https://msdn.microsoft.com/en-us/library/windows/desktop/dn280512(v=vs.85).aspx Global Enum $DPI_AWARENESS_INVALID = -1, $PROCESS_DPI_UNAWARE = 0, $PROCESS_SYSTEM_DPI_AWARE, $PROCESS_PER_MONITOR_DPI_AWARE ;https://docs.microsoft.com/en-us/windows/desktop/hidpi/dpi-awareness-context Global Enum $Context_UnawareGdiScaled = -5, $Context_PerMonitorAwareV2, $Context_PerMonitorAware, $Context_SystemAware, $Context_Unaware _WinAPI_SetProcessDpiAwarenessContext($Context_PerMonitorAware) Global $__g_hGUI_MarkArea, $__g_hGUI_Bg, $__g_iLabel_TL, $__g_iLabel_TM, $__g_iLabel_TR, $__g_iLabel_LM, $__g_iLabel_RM, $__g_iLabel_BL, $__g_iLabel_BM, _ $__g_iLabel_BR, $__g_iOldCursor, $__g_iW, $__g_iH, $__g_iColor_ResizeDots = 0xFFFFFF, $__g_iBorder = 4, $__g_bSelectionDone = False Global $aRect = _GDIPlus_MarkScreenRegionAnimated() Global $hImage_Capture = _ScreenCapture_Capture(@TempDir & "\Test.png", $aRect[0], $aRect[1], $aRect[0] + $aRect[2] - 1, $aRect[1] + $aRect[3] - 1, False) ShellExecute(@TempDir & "\Test.png") ;_ArrayDisplay($aRect, "Marked area coordinates") Func _GDIPlus_MarkScreenRegionAnimated($bAnim = True) _GDIPlus_Startup() Local Const $hFullScreen = WinGetHandle("[TITLE:Program Manager;CLASS:Progman]") Local Const $aFullScreen = WinGetPos($hFullScreen) $__g_hGUI_Bg = GUICreate("", $aFullScreen[2], $aFullScreen[3], $aFullScreen[0], $aFullScreen[1], BitOR($WS_CLIPCHILDREN, $WS_POPUP), $WS_EX_TOPMOST) ;to avoid cursor flickering and for proper control read WinSetTrans($__g_hGUI_Bg, "", 0x01) $__g_hGUI_MarkArea = GUICreate("", 1, 1, -1, -1, $bAnim ? $WS_POPUP : BitOR($WS_POPUP, $WS_BORDER), BitOR($WS_EX_TOPMOST, $WS_EX_LAYERED), $__g_hGUI_Bg) GUISetBkColor(0xABCDEF, $__g_hGUI_MarkArea) If Not $bAnim Then $__g_iColor_ResizeDots = 0xFF0000 $__g_iLabel_TL = GUICtrlCreateLabel("", 0, 0, $__g_iBorder, $__g_iBorder) ;top left GUICtrlSetResizing(-1, $GUI_DOCKSIZE) GUICtrlSetBkColor(-1, $__g_iColor_ResizeDots) $__g_iLabel_TM = GUICtrlCreateLabel("", 0, 0, $__g_iBorder, $__g_iBorder) ;top mid GUICtrlSetResizing(-1, $GUI_DOCKSIZE) GUICtrlSetBkColor(-1, $__g_iColor_ResizeDots) $__g_iLabel_TR = GUICtrlCreateLabel("", 0, 0, $__g_iBorder, $__g_iBorder) ;top right GUICtrlSetResizing(-1, $GUI_DOCKSIZE) GUICtrlSetBkColor(-1, $__g_iColor_ResizeDots) $__g_iLabel_LM = GUICtrlCreateLabel("", 0, 0, $__g_iBorder, $__g_iBorder) ;left mid GUICtrlSetResizing(-1, $GUI_DOCKSIZE) GUICtrlSetBkColor(-1, $__g_iColor_ResizeDots) $__g_iLabel_RM = GUICtrlCreateLabel("", 0, 0, $__g_iBorder, $__g_iBorder) ;right mid GUICtrlSetResizing(-1, $GUI_DOCKSIZE) GUICtrlSetBkColor(-1, $__g_iColor_ResizeDots) $__g_iLabel_BL = GUICtrlCreateLabel("", 0, 0, $__g_iBorder, $__g_iBorder) ;bottom left GUICtrlSetResizing(-1, $GUI_DOCKSIZE) GUICtrlSetBkColor(-1, $__g_iColor_ResizeDots) $__g_iLabel_BM = GUICtrlCreateLabel("", 0, 0, $__g_iBorder, $__g_iBorder) ;bottom mid GUICtrlSetResizing(-1, $GUI_DOCKSIZE) GUICtrlSetBkColor(-1, $__g_iColor_ResizeDots) $__g_iLabel_BR = GUICtrlCreateLabel("", 0, 0, $__g_iBorder, $__g_iBorder) ;bottom right GUICtrlSetResizing(-1, $GUI_DOCKSIZE) GUICtrlSetBkColor(-1, $__g_iColor_ResizeDots) GUISetState(@SW_SHOWNA, $__g_hGUI_Bg) GUISetState(@SW_SHOW, $__g_hGUI_MarkArea) $__g_iOldCursor = MouseGetCursor() GUISetCursor(3, 1, $__g_hGUI_Bg) GUISetCursor(3, 1, $__g_hGUI_MarkArea) _WinAPI_SetLayeredWindowAttributes($__g_hGUI_MarkArea, 0xABCDEF, 0xF0) Local $aMPos, $aPrevMPos[2] = [MouseGetPos(0) + 1, MouseGetPos(1) + 1], $iID, $aCI, $iX, $iY, $aOldWinPos, $aOldMPos, $bMoved Local $aGUIStartPos, $iKey_Exit = GUICtrlCreateButton("", $aFullScreen[0] - 10, $aFullScreen[1] - 10, 1, 1), $aAccelKeys[1][2] = [["{ENTER}", $iKey_Exit]] GUISetAccelerators($aAccelKeys, $__g_hGUI_Bg) GUISetAccelerators($aAccelKeys, $__g_hGUI_MarkArea) #forceref $bMoved Do Switch GUIGetMsg() Case $GUI_EVENT_CLOSE, $iKey_Exit If $bAnim Then GUIRegisterMsg($WM_TIMER, "") DllCall("user32.dll", "bool", "KillTimer", "hwnd", $__g_hGUI_MarkArea, "uint_ptr", $iID) GUIRegisterMsg($WM_ERASEBKGND, "") EndIf _GDIPlus_Shutdown() Local $aResult = WinGetPos($__g_hGUI_MarkArea) $aResult[2] = WinGetClientSize($__g_hGUI_MarkArea)[0] $aResult[3] = WinGetClientSize($__g_hGUI_MarkArea)[1] GUIDelete($__g_hGUI_MarkArea) GUIDelete($__g_hGUI_Bg) If Not $__g_bSelectionDone Then $aResult = 0 Return $aResult EndSwitch $aMPos = MouseGetPos() If ($aMPos[0] <> $aPrevMPos[0] Or $aMPos[1] <> $aPrevMPos[1]) And (Not $__g_bSelectionDone) Then WinMove($__g_hGUI_MarkArea, "", $aMPos[0], $aMPos[1]) $aPrevMPos = $aMPos EndIf $aCI = GUIGetCursorInfo($__g_hGUI_MarkArea) If $aCI[2] And (Not $__g_bSelectionDone) Then $aGUIStartPos = WinGetPos($__g_hGUI_MarkArea) If $bAnim Then GUIRegisterMsg($WM_ERASEBKGND, "WM_ERASEBKGND") GUIRegisterMsg($WM_TIMER, "PlayBorderAnim") $iID = DllCall("User32.dll", "uint_ptr", "SetTimer", "hwnd", $__g_hGUI_MarkArea, "uint_ptr", 1, "uint", 50, "ptr", 0)[0] EndIf While $aCI[2] * Sleep(10) $aCI = GUIGetCursorInfo($__g_hGUI_MarkArea) $aMPos = MouseGetPos() $__g_iW = Abs($aMPos[0] - $aGUIStartPos[0]) + 1 $__g_iH = Abs($aMPos[1] - $aGUIStartPos[1]) + 1 If $aMPos[0] < $aGUIStartPos[0] Then $iX = $aMPos[0] Else $iX = $aGUIStartPos[0] EndIf If $aMPos[1] < $aGUIStartPos[1] Then $iY = $aMPos[1] Else $iY = $aGUIStartPos[1] EndIf WinMove($__g_hGUI_MarkArea, "", $iX, $iY, $__g_iW, $__g_iH) UpdateCtrlPos($bAnim) WEnd $__g_bSelectionDone = True GUISetCursor(3, 1, $__g_hGUI_MarkArea) ElseIf $aCI[3] And $__g_bSelectionDone Then $aGUIStartPos = WinGetPos($__g_hGUI_MarkArea) If _WinAPI_PtInRectEx(MouseGetPos(0), MouseGetPos(1), $aGUIStartPos[0], $aGUIStartPos[1], $aGUIStartPos[0] + $aGUIStartPos[2], $aGUIStartPos[1] + $aGUIStartPos[3]) Then $aMPos = MouseGetPos() $aGUIStartPos = WinGetPos($__g_hGUI_MarkArea) While $aCI[3] * Sleep(10) $aCI = GUIGetCursorInfo($__g_hGUI_MarkArea) WinMove($__g_hGUI_MarkArea, "", $aGUIStartPos[0] - ($aMPos[0] - MouseGetPos(0)), $aGUIStartPos[1] - ($aMPos[1] - MouseGetPos(1)), $__g_iW, $__g_iH) GUISetCursor(0, 1, $__g_hGUI_Bg) GUISetCursor(0, 1, $__g_hGUI_MarkArea) WEnd GUISetCursor(3, 1, $__g_hGUI_Bg) GUISetCursor(3, 1, $__g_hGUI_MarkArea) EndIf EndIf If $__g_bSelectionDone Then $aCI = GUIGetCursorInfo($__g_hGUI_MarkArea) If @error Then ContinueLoop Switch $aCI[4] Case $__g_iLabel_TL GUISetCursor(12, 1, $__g_hGUI_MarkArea) If $aCI[2] Then $aOldWinPos = WinGetPos($__g_hGUI_MarkArea) $aOldMPos = MouseGetPos() While $aCI[2] * Sleep(10) $aCI = GUIGetCursorInfo($__g_hGUI_MarkArea) WinMove($__g_hGUI_MarkArea, "", MouseGetPos(0), MouseGetPos(1), $aOldWinPos[2] + ($aOldMPos[0] - MouseGetPos(0)), $aOldWinPos[3] + ($aOldMPos[1] - MouseGetPos(1))) WEnd UpdateCtrlPos($bAnim) EndIf Case $__g_iLabel_BR GUISetCursor(12, 1, $__g_hGUI_MarkArea) If $aCI[2] Then $aOldWinPos = WinGetPos($__g_hGUI_MarkArea) $aOldMPos = MouseGetPos() While $aCI[2] * Sleep(10) $aCI = GUIGetCursorInfo($__g_hGUI_MarkArea) WinMove($__g_hGUI_MarkArea, "", $aOldWinPos[0], $aOldWinPos[1], $aOldWinPos[2] - ($aOldMPos[0] - MouseGetPos(0)), $aOldWinPos[3] - ($aOldMPos[1] - MouseGetPos(1))) WEnd UpdateCtrlPos($bAnim) EndIf Case $__g_iLabel_TR GUISetCursor(10, 1, $__g_hGUI_MarkArea) If $aCI[2] Then $aOldWinPos = WinGetPos($__g_hGUI_MarkArea) $aOldMPos = MouseGetPos() While $aCI[2] * Sleep(10) $aCI = GUIGetCursorInfo($__g_hGUI_MarkArea) WinMove($__g_hGUI_MarkArea, "", $aOldWinPos[0], MouseGetPos(1), $aOldWinPos[2] - ($aOldMPos[0] - MouseGetPos(0)), $aOldWinPos[3] + ($aOldMPos[1] - MouseGetPos(1))) WEnd UpdateCtrlPos($bAnim) EndIf Case $__g_iLabel_BL GUISetCursor(10, 1, $__g_hGUI_MarkArea) If $aCI[2] Then $aOldWinPos = WinGetPos($__g_hGUI_MarkArea) $aOldMPos = MouseGetPos() While $aCI[2] * Sleep(10) $aCI = GUIGetCursorInfo($__g_hGUI_MarkArea) WinMove($__g_hGUI_MarkArea, "", MouseGetPos(0), $aOldWinPos[1], $aOldWinPos[2] + ($aOldMPos[0] - MouseGetPos(0)), $aOldWinPos[3] - ($aOldMPos[1] - MouseGetPos(1))) WEnd UpdateCtrlPos($bAnim) EndIf Case $__g_iLabel_LM GUISetCursor(13, 1, $__g_hGUI_MarkArea) If $aCI[2] Then $aOldWinPos = WinGetPos($__g_hGUI_MarkArea) $aOldMPos = MouseGetPos() While $aCI[2] * Sleep(10) $aCI = GUIGetCursorInfo($__g_hGUI_MarkArea) WinMove($__g_hGUI_MarkArea, "", MouseGetPos(0), $aOldWinPos[1], $aOldWinPos[2] + ($aOldMPos[0] - MouseGetPos(0)), $aOldWinPos[3]) WEnd UpdateCtrlPos($bAnim) EndIf Case $__g_iLabel_RM GUISetCursor(13, 1, $__g_hGUI_MarkArea) If $aCI[2] Then $aOldWinPos = WinGetPos($__g_hGUI_MarkArea) $aOldMPos = MouseGetPos() While $aCI[2] * Sleep(10) $aCI = GUIGetCursorInfo($__g_hGUI_MarkArea) WinMove($__g_hGUI_MarkArea, "", $aOldWinPos[0], $aOldWinPos[1], $aOldWinPos[2] - ($aOldMPos[0] - MouseGetPos(0)), $aOldWinPos[3]) WEnd UpdateCtrlPos($bAnim) EndIf Case $__g_iLabel_TM GUISetCursor(11, 1, $__g_hGUI_MarkArea) If $aCI[2] Then $aOldWinPos = WinGetPos($__g_hGUI_MarkArea) $aOldMPos = MouseGetPos() While $aCI[2] * Sleep(10) $aCI = GUIGetCursorInfo($__g_hGUI_MarkArea) WinMove($__g_hGUI_MarkArea, "", $aOldWinPos[0], MouseGetPos(1), $aOldWinPos[2], $aOldWinPos[3] + ($aOldMPos[1] - MouseGetPos(1))) WEnd UpdateCtrlPos($bAnim) EndIf Case $__g_iLabel_BM GUISetCursor(11, 1, $__g_hGUI_MarkArea) If $aCI[2] Then $aOldWinPos = WinGetPos($__g_hGUI_MarkArea) $aOldMPos = MouseGetPos() While $aCI[2] * Sleep(10) $aCI = GUIGetCursorInfo($__g_hGUI_MarkArea) WinMove($__g_hGUI_MarkArea, "", $aOldWinPos[0], $aOldWinPos[1], $aOldWinPos[2], $aOldWinPos[3] - ($aOldMPos[1] - MouseGetPos(1))) WEnd UpdateCtrlPos($bAnim) EndIf Case Else GUISetCursor(3, 1, $__g_hGUI_MarkArea) EndSwitch EndIf Until False EndFunc ;==>_GDIPlus_MarkScreenRegionAnimated Func UpdateCtrlPos($bAnim = True) Local Const $aGUIStartPos = WinGetPos($__g_hGUI_MarkArea) If $__g_bSelectionDone And $bAnim Then GUIRegisterMsg($WM_TIMER, "") $__g_iW = $aGUIStartPos[2] $__g_iH = $aGUIStartPos[3] ControlMove($__g_hGUI_MarkArea, "", $__g_iLabel_TL, 0, 0, $__g_iBorder, $__g_iBorder) ControlMove($__g_hGUI_MarkArea, "", $__g_iLabel_TM, ($__g_iW - $__g_iBorder) / 2, 0, $__g_iBorder, $__g_iBorder) ControlMove($__g_hGUI_MarkArea, "", $__g_iLabel_TR, ($__g_iW - $__g_iBorder - $__g_iBorder / 2), 0, $__g_iBorder, $__g_iBorder) ControlMove($__g_hGUI_MarkArea, "", $__g_iLabel_LM, 0, ($__g_iH - $__g_iBorder) / 2, $__g_iBorder, $__g_iBorder) ControlMove($__g_hGUI_MarkArea, "", $__g_iLabel_RM, ($__g_iW - $__g_iBorder - $__g_iBorder / 2), ($__g_iH - $__g_iBorder) / 2, $__g_iBorder, $__g_iBorder) ControlMove($__g_hGUI_MarkArea, "", $__g_iLabel_BL, 0, ($__g_iH - $__g_iBorder - $__g_iBorder / 2), $__g_iBorder, $__g_iBorder) ControlMove($__g_hGUI_MarkArea, "", $__g_iLabel_BM, ($__g_iW - $__g_iBorder) / 2, ($__g_iH - $__g_iBorder - $__g_iBorder / 2), $__g_iBorder, $__g_iBorder) ControlMove($__g_hGUI_MarkArea, "", $__g_iLabel_BR, ($__g_iW - $__g_iBorder - $__g_iBorder / 2), ($__g_iH - $__g_iBorder - $__g_iBorder / 2), $__g_iBorder, $__g_iBorder) If $__g_bSelectionDone And $bAnim Then GUIRegisterMsg($WM_TIMER, "PlayBorderAnim") EndFunc ;==>UpdateCtrlPos Func PlayBorderAnim() Local $aWinPos = WinGetClientSize($__g_hGUI_MarkArea), $iW = $aWinPos[0], $iH = $aWinPos[1] Local Static $fOffset = 0 Local Const $iSize = $__g_iBorder / 2 Local Const $hDC = _WinAPI_GetDC($__g_hGUI_MarkArea) Local Const $hHBitmap = _WinAPI_CreateCompatibleBitmap($hDC, $iW, $iH) Local Const $hDC_backbuffer = _WinAPI_CreateCompatibleDC($hDC) Local Const $DC_obj = _WinAPI_SelectObject($hDC_backbuffer, $hHBitmap) Local Const $hCanvas = _GDIPlus_GraphicsCreateFromHDC($hDC_backbuffer) Local Const $hPen = _GDIPlus_PenCreate(0xFF0178D7, $iSize), $hPen2 = _GDIPlus_PenCreate(0xFFFFFFFF, $iSize), _ $hBrush = _GDIPlus_BrushCreateSolid(0xFF000000 + $__g_iColor_ResizeDots), $hPen3 = _GDIPlus_PenCreate(0xFF000000) _GDIPlus_PenSetDashStyle($hPen, $GDIP_DASHSTYLEDASHDOT) _GDIPlus_GraphicsClear($hCanvas, 0xFFABCDEF) ;for faster performance direct dll calls DllCall($__g_hGDIPDll, "int", "GdipDrawRectangle", "handle", $hCanvas, "handle", $hPen2, "float", 1 + $iSize, "float", 1 + $iSize, "float", $iW - 2 * $iSize - 2, "float", $iH - 2 * $iSize - 2) DllCall($__g_hGDIPDll, "int", "GdipSetPenDashOffset", "handle", $hPen, "float", $fOffset) DllCall($__g_hGDIPDll, "int", "GdipDrawRectangle", "handle", $hCanvas, "handle", $hPen, "float", 1 + $iSize, "float", 1 + $iSize, "float", $iW - 2 * $iSize - 2, "float", $iH - 2 * $iSize - 2) DllCall($__g_hGDIPDll, "int", "GdipFillRectangle", "handle", $hCanvas, "handle", $hBrush, "float", 0, "float", 0, "float", $__g_iBorder + 1, "float", $__g_iBorder + 1) DllCall($__g_hGDIPDll, "int", "GdipDrawRectangle", "handle", $hCanvas, "handle", $hPen3, "float", 0, "float", 0, "float", $__g_iBorder + 1, "float", $__g_iBorder + 1) DllCall($__g_hGDIPDll, "int", "GdipFillRectangle", "handle", $hCanvas, "handle", $hBrush, "float", ($iW - $__g_iBorder) / 2, "float", 0, "float", $__g_iBorder + 1, "float", $__g_iBorder + 1) DllCall($__g_hGDIPDll, "int", "GdipDrawRectangle", "handle", $hCanvas, "handle", $hPen3, "float", ($iW - $__g_iBorder) / 2, "float", 0, "float", $__g_iBorder + 1, "float", $__g_iBorder + 1) DllCall($__g_hGDIPDll, "int", "GdipFillRectangle", "handle", $hCanvas, "handle", $hBrush, "float", ($iW - $__g_iBorder) - 2, "float", 0, "float", $__g_iBorder + 1, "float", $__g_iBorder + 1) DllCall($__g_hGDIPDll, "int", "GdipDrawRectangle", "handle", $hCanvas, "handle", $hPen3, "float", ($iW - $__g_iBorder) - 2, "float", 0, "float", $__g_iBorder + 1, "float", $__g_iBorder + 1) DllCall($__g_hGDIPDll, "int", "GdipFillRectangle", "handle", $hCanvas, "handle", $hBrush, "float", 0, "float", ($iH - $__g_iBorder) / 2, "float", $__g_iBorder + 1, "float", $__g_iBorder + 1) DllCall($__g_hGDIPDll, "int", "GdipDrawRectangle", "handle", $hCanvas, "handle", $hPen3, "float", 0, "float", ($iH - $__g_iBorder) / 2, "float", $__g_iBorder + 1, "float", $__g_iBorder + 1) DllCall($__g_hGDIPDll, "int", "GdipFillRectangle", "handle", $hCanvas, "handle", $hBrush, "float", ($iW - $__g_iBorder) - 2, "float", ($iH - $__g_iBorder) / 2, "float", $__g_iBorder + 1, "float", $__g_iBorder + 1) DllCall($__g_hGDIPDll, "int", "GdipDrawRectangle", "handle", $hCanvas, "handle", $hPen3, "float", ($iW - $__g_iBorder) - 2, "float", ($iH - $__g_iBorder) / 2, "float", $__g_iBorder + 1, "float", $__g_iBorder + 1) DllCall($__g_hGDIPDll, "int", "GdipFillRectangle", "handle", $hCanvas, "handle", $hBrush, "float", 0, "float", ($iH - $__g_iBorder) - 2, "float", $__g_iBorder + 1, "float", $__g_iBorder + 1) DllCall($__g_hGDIPDll, "int", "GdipDrawRectangle", "handle", $hCanvas, "handle", $hPen3, "float", 0, "float", ($iH - $__g_iBorder) - 2, "float", $__g_iBorder + 1, "float", $__g_iBorder + 1) DllCall($__g_hGDIPDll, "int", "GdipFillRectangle", "handle", $hCanvas, "handle", $hBrush, "float", ($iW - $__g_iBorder) / 2, "float", ($iH - $__g_iBorder) - 2, "float", $__g_iBorder + 1, "float", $__g_iBorder + 1) DllCall($__g_hGDIPDll, "int", "GdipDrawRectangle", "handle", $hCanvas, "handle", $hPen3, "float", ($iW - $__g_iBorder) / 2, "float", ($iH - $__g_iBorder) - 2, "float", $__g_iBorder + 1, "float", $__g_iBorder + 1) DllCall($__g_hGDIPDll, "int", "GdipFillRectangle", "handle", $hCanvas, "handle", $hBrush, "float", ($iW - $__g_iBorder) - 2, "float", ($iH - $__g_iBorder) - 2, "float", $__g_iBorder + 1, "float", $__g_iBorder + 1) DllCall($__g_hGDIPDll, "int", "GdipDrawRectangle", "handle", $hCanvas, "handle", $hPen3, "float", ($iW - $__g_iBorder) - 2, "float", ($iH - $__g_iBorder) - 2, "float", $__g_iBorder + 1, "float", $__g_iBorder + 1) _WinAPI_BitBlt($hDC, 0, 0, $iW, $iH, $hDC_backbuffer, 0, 0, $SRCCOPY) $fOffset += 0.5 _GDIPlus_GraphicsDispose($hCanvas) _WinAPI_SelectObject($hDC_backbuffer, $DC_obj) _WinAPI_DeleteDC($hDC_backbuffer) _WinAPI_DeleteObject($hHBitmap) _WinAPI_ReleaseDC($__g_hGUI_MarkArea, $hDC) _GDIPlus_PenDispose($hPen) _GDIPlus_PenDispose($hPen2) _GDIPlus_PenDispose($hPen3) _GDIPlus_BrushDispose($hBrush) EndFunc ;==>PlayBorderAnim Func WM_ERASEBKGND($hWnd, $iMsgm, $wParam, $lParam) ;suppress repainting to avoid flickering but causes some other side effects #forceref $iMsgm, $wParam, $lParam, $hWnd Local Const $hBrush = _WinAPI_CreateSolidBrush(0xEFCDAB) ;BGR format ;~ _WinAPI_RedrawWindow($__g_hGUI_MarkArea, 0, 0, BitOR($RDW_NOERASE, $RDW_NOCHILDREN, $RDW_NOFRAME, $RDW_VALIDATE)) _WinAPI_SetClassLongEx($__g_hGUI_MarkArea, $GCL_HBRBACKGROUND, $hBrush) _WinAPI_DeleteObject($hBrush) Return 0 EndFunc ;==>WM_ERASEBKGND ;https://docs.microsoft.com/en-us/windows/desktop/api/winuser/nf-winuser-setprocessdpiawarenesscontext Func _WinAPI_SetProcessDpiAwarenessContext($DPIAwareContext = $Context_PerMonitorAware, $hGUI = 0, $iMode = 3) ;https://docs.microsoft.com/en-us/windows/desktop/api/winuser/nf-winuser-setprocessdpiawarenesscontext $DPIAwareContext = ($DPIAwareContext < -5) ? -5 : ($DPIAwareContext > -1) ? -1 : $DPIAwareContext $iMode = ($iMode < 1) ? 1 : ($iMode > 3) ? 3 : $iMode Switch $iMode Case 1 Local $hDC = _WinAPI_GetDC($hGUI) Local $aResult1 = DllCall("user32.dll", "ptr", "GetDpiFromDpiAwarenessContext", "ptr", $hDC) If @error Or Not IsArray($aResult1) Then Return SetError(11, 0, 0) _WinAPI_ReleaseDC(0, $hDC) Local $aResult = DllCall("user32.dll", "Bool", "SetProcessDpiAwarenessContext", "int", $aResult1[0] + $DPIAwareContext) If @error Or Not IsArray($aResult) Then Return SetError(12, 0, 0) Case 2 ;~ If Not $hGUI Then $hGUI = WinGetHandle(AutoItWinGetTitle()) Local $aResult2 = DllCall("user32.dll", "int", "GetWindowDpiAwarenessContext", "ptr", $hGUI) If @error Or Not IsArray($aResult2) Then Return SetError(21, 0, 0) Local $aResult = DllCall("user32.dll", "Bool", "SetProcessDpiAwarenessContext", "int", $aResult2[0] + $DPIAwareContext) If @error Or Not IsArray($aResult) Then Return SetError(22, 0, 0) Case 3 Local $aResult31 = DllCall("user32.dll", "ptr", "GetThreadDpiAwarenessContext") If @error Or Not IsArray($aResult31) Then Return SetError(31, 0, 0) Local $aResult32 = DllCall("user32.dll", "ptr", "GetAwarenessFromDpiAwarenessContext", "ptr", $aResult31[0]) If @error Or Not IsArray($aResult32) Then Return SetError(32, 0, 0) Local $aResult = DllCall("user32.dll", "Bool", "SetThreadDpiAwarenessContext", "int", $aResult32[0] + $DPIAwareContext) If @error Or Not IsArray($aResult) Then Return SetError(33, 0, 0) EndSwitch Return 1 EndFunc ;==>_WinAPI_SetProcessDpiAwarenessContext Just press the lmb and move your mouse. When lmb is released you can adjust the size of the window by dragging the white rectangle to any direction. Rmb will move the marked area. Press ESC to get the coordinates of the marked region. If you have any improvements, please post it here. Tested on Win10 x64 only.2 points
-
There are others on this board who could be much better experts - but I did a fair amount of research on protecting/password protecting a script a while back when I completed a project that took triple digit hours to complete. The short answer is, there isn't. Here is the best & easiest solution I found: Store a MD5 Hash of the expected PW. You can add a Salt to it, but it has to be the same every time, to the PW before Hash. For me, I had a unique 3 digit # at every computer (500+) that I sent it to, so I pre-compiled all 500 Hashes and salt (each salt was unique!, yay for rainbow table protection!) and store them in the script. I had the luxury of being the Admin on all machines as well, this wasn't a "public" script, but something that I did want to protect, and protect non-IT users from using. Prompt for a password on program open (or cmd line run). Hash+Salt that, then compare to your Pre-compiled value. If they match, program continues. If they don't it fails. It is TRIVIAL, and I mean 100% cakewalk to remove any solution to protecting your program through some means of authentication prior to use. NO METHOD will prevent this from someone that wants to use your program & is semi-competent. The best you can do, is protect your passwords (or in my case, licenses keys) from being stolen, and a hash+salt can do this. UNLESS a rainbow table exists for it, which is why a random salt (8 char or so + symbols) is used. If you'd like my auth code, I can post it this weekend perhaps, if you don't get anywhere.2 points
-
[UDF] Gmail API - Emails automation with AutoIt!
coffeeturtle reacted to Ascer for a topic
1. Description. Automate communication with Gmail API using oAuth 2.0 security. 2. Requirements. Google Gmail account. Finished Authorization process. Look here 3. Possibilities. ;======================================================================================================================== ; Date: 2018-02-12, 11:46 ; ; Bug Fixs: 2018-02-17, 7:31 -> Fixed problems with adding items to array and minor bugs. ; ; Description: UDF for using Gmail API interface. This UDF requires oAuth.au3 and Gmail account. ; ; Function(s): ; gmailUsersGetProfile() -> Information about your account. ; gmailUsersLabelsList() -> Get all available labels ids. ex. "INBOX", "UNREAD" ; gmailUsersLabelsGet() -> Get information about specific label id. ; gmailUsersMessagesBatchDelete() -> Delete many messages emails by id. ; gmailUsersMessagesBatchModify() -> Set status for many messages ex. "INBOX", "UNREAD" ; gmailUsersMessagesDelete() -> Totaly delete email from ur account. ; gmailUsersMessagesGet() -> Get all information about specific email. ; gmailUsersMessagesList() -> Get list of last ~100 emails. ; gmailUsersMessagesModify() -> Modify single message. ; gmailUsersMessagesTrash() -> Put email in trash. ; gmailUsersMessagesUntrash() -> Restore email from trash. ; gmailUsersMessagesSend() -> Send email to single or group recipients. ; gmailUsersMessagesAttachmentsGet() -> Download attachment by id. ; ; Author(s): Ascer ;======================================================================================================================== 4. Downloads. oAuth.au3 Gmail API.au3 5. Examples. Sending emails1 point -
WebDriver UDF - Help & Support
truong2301 reacted to Danp2 for a topic
Neither do I. But I put in the effort to research the W3C standards, and then write code based on this knowledge. This is something you could do as well. There's lots of information available on this forum. If you can't find it here, search Google and then translate to work with Autoit. Put in some effort, show us the resulting code, and then I'm sure that we can help you as needed from there.1 point -
Could RegExp be used here ?
FrancescoDiMuro reacted to JLogan3o13 for a topic
@pixelsearch in reading through this thread let me say that you are not alone in avoiding regex; it still makes my eyes bleed to this day. As to the friendliness of the forum, I would say that you have gotten great suggestions from Marc and mikell - focus on those. Unfortunately you have some folks as you saw above that seem intent only on proving what an ass they can be without adding anything of value to the forum; these you have to ignore As to this probably being one of the longest posts on the forum, not even close. Look in the Chat section for some meandering word walls that should really be broken up into chapters1 point -
How can I send a variable with a shortcut, to a autoit executable created app?
TheXman reacted to JLogan3o13 for a topic
I do understand; everyone here was on "Day 1" at some point. The ones who succeed, however, are those that spend the time learning. That is why we operate on the "teach a man to fish" motto; simply being handed the code often does more harm than good for new scripters. Hopefully you will study the code and use it to learn more about the language.1 point -
Well I was bored and so wrote something simple up, to show you how you can create 3 shortcuts on the desktop named Option1, Option2 and Option3 Option1 Runs Notepad Option2 Runs Wordpad Option3 Delete the three shortcuts You should be able to modify the code to suit, as JLogan3o13 mentioned the forum would like to see you write something first and we can give you help as required, but I have some spare time so have given you a working example. Please remember read AutoIt Helpfile, it includes a large variety of examples you can test and base your own scripts on. If FileExists(@DesktopDir & "\Option1.lnk") = 0 Then FileCreateShortcut(@ScriptFullPath, @DesktopDir & "\Option1.lnk", "", "-Option1") If FileExists(@DesktopDir & "\Option2.lnk") = 0 Then FileCreateShortcut(@ScriptFullPath, @DesktopDir & "\Option2.lnk", "", "-Option2") If FileExists(@DesktopDir & "\Option3.lnk") = 0 Then FileCreateShortcut(@ScriptFullPath, @DesktopDir & "\Option3.lnk", "", "-Option3") If $CmdLine[0] >= 1 Then Switch $CmdLine[1] Case "-Option1" ShellExecute(@WindowsDir & "\Notepad.exe") Case "-Option2" ShellExecute("Wordpad.exe") Case "-Option3" FileDelete(@DesktopDir & "\Option1.lnk") FileDelete(@DesktopDir & "\Option2.lnk") FileDelete(@DesktopDir & "\Option3.lnk") EndSwitch EndIf1 point
-
How can I send a variable with a shortcut, to a autoit executable created app?
sosimple reacted to JLogan3o13 for a topic
@sosimple did even you look at $CmdLine as was suggested? It does precisely what you are looking for, and has an example in the help file. This forum is dedicated to helping people who want to improve their own scripts; it is not somewhere where you put in a request and someone barfs up the code for you. You need to show some effort if you would like assistance.1 point -
Oracle SQL developer 18.2 automation - (Moved)
Miclotr reacted to Earthshine for a topic
well, you haven't told me much of anything that you need to do. it looks like you have some learning to do. I would try the IUIAutomation, run simplespy.au3 and do what it tells you, you will end up with usable code you can learn from1 point -
Look at $CmdLineRaw and $CmdLine in the Help File which explains how to handle switches.1 point
-
You could just use a toggle example: #include <ButtonConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #include <MsgBoxConstants.au3> #AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 ; remember that when the above is enabled all variables declared within the Program region must be Global. #Region - Main Body (or at least I'd like it to be!) Opt("GUIOnEventMode", 1) Global $Form1, $idInput1, $idInput2, $Button2, $sFN, $sLN, $bResult = False _DisplayForm() ; display agreement form ; next step in program (if I can get back here) MsgBox($MB_SYSTEMMODAL, "Results", "returned to main body") Exit #EndRegion - Main Body #Region - Functions Func _DisplayForm() $Form1 = GUICreate("Form1", 679, 438, 192, 124) ; ask firstname $idInput1 = GUICtrlCreateInput("", 56, 360, 169, 21) ; ask lastname $idInput2 = GUICtrlCreateInput("", 240, 360, 177, 21) ; add labels GUICtrlCreateLabel("Enter first name", 56, 336, 77, 17) GUICtrlCreateLabel("Enter last name", 240, 336, 77, 17) GUICtrlCreateLabel("I agree", 480, 336, 37, 17) ; checkbox for agreement GUICtrlCreateCheckbox("Checkbox1", 456, 336, 17, 17) GUICtrlSetOnEvent(-1, "Checkbox1Click") ; allow bail out GUICtrlCreateButton("Cancel", 464, 368, 73, 33) GUICtrlSetOnEvent(-1, "_CancelPressed") ; OK available only if checkbox checked $Button2 = GUICtrlCreateButton("Okay", 560, 368, 81, 33) GUICtrlSetOnEvent(-1, "_OKPressed") GUICtrlSetState($Button2, $GUI_DISABLE) GUISetState(@SW_SHOW) While $bResult = False Sleep(100) WEnd GUIDelete($Form1) EndFunc ;==>_DisplayForm Func _CancelPressed() MsgBox($MB_SYSTEMMODAL, "Results", "Cancel pressed") Exit ; if no agreement then exit EndFunc ;==>_CancelPressed Func _OKPressed() ; THIS IS THE FUNCTION FROM WHICH I NEED TO RETURN TO MAIN BODY $sFN = GUICtrlRead($idInput1) $sLN = GUICtrlRead($idInput2) MsgBox($MB_SYSTEMMODAL, "Results", "firstname: " & $sFN & @CRLF & "lastname: " & $sLN) $bResult = True ; HOW DO I RETURN TO THE MAIN PROGRAM BODY? ; Return just takes me back to _DisplayForm instead of the main prog ; Setting a variable here and checking for it in _DisplayForm's While/WEnd loop doesn't work either EndFunc ;==>_OKPressed Func Checkbox1Click() GUICtrlSetState($Button2, $GUI_ENABLE) EndFunc ;==>Checkbox1Click #EndRegion - Functions1 point
-
_GDIPlus_MarkScreenRegionAnimated build 2020-08-07 beta
Stormgrade reacted to UEZ for a topic
@Stormgrade: done -> see post#1. Return key exits selection, too.1 point -
Oracle SQL developer 18.2 automation - (Moved)
Miclotr reacted to JLogan3o13 for a topic
Moved to the appropriate forum, as the Developer General Discussion forum very clearly states: Moderation Team1 point -
Problem with text scaling multiple GUI
Daemante2018 reacted to Melba23 for a topic
careca & anyone else reading, I have explained the "numbering" of AutoIt ControlIDs many times - here is a good example which should make it all clear. M231 point -
How to protect password in script
Tralveller reacted to RTFC for a topic
CodeCrypter with keyID=1 provides password-based encryption, although a combination with target machine-specific features would be more secure. Please consult the FAQ and remarks in source headers for more info.1 point -
Seems the max. length is 255 characters. Here you find a way to bypass this limitation: https://stackoverflow.com/questions/19533877/error-string-parameter-too-long-at-microsoft-office-interop-word-find-execute Or an explanation by MS: https://social.msdn.microsoft.com/Forums/vstudio/en-US/9c50450e-9579-4e89-8e9c-8c84c8319d0b/find-and-replace-for-strings-over-255-charaters-in-word?forum=vsto1 point
-
AutoIt uses the GetLastInputInfo function to determine idle time in that function. It's got nothing to do with how Windows determines idle time, so that link doesn't apply here.1 point
-
Comparison of logging UDFs
FrancescoDiMuro reacted to Danyfirex for a topic
Hello. Both UDFs allow you to setup output log file path. by default is the script directory. Saludos1 point -
SplashText over taskbar
badcoder123 reacted to BigDaddyO for a topic
After a lot of reading, it came down to the Z-Order being reset every time a topmost window is selected. So, I just needed to run the WinSetOnTop() function for my splashtext every time I update the text. ;Create the progress screen $aPOS = ControlGetPos("[CLASS:Shell_TrayWnd]", "", "[CLASS:MSTaskListWClass; INSTANCE:1]") if @error Then MsgBox(0, "Error", "Unable to find System Tray to build the progress screen") Exit EndIf $sMessage = "StatusBar - Starting..." SplashTextOn("SysTrayStatus", $sMessage, 340, 25, ($aPOS[0] + $aPOS[2]) - 350, @DesktopHeight - $aPOS[3] + Round(($aPOS[3] - 25) / 2, 2), 37, "Ariel", 8) WinSetOnTop("SysTrayStatus", "", 1) ;Set this as one of the Topmost windows ConsoleWrite("Initial State = " & WinGetState("SysTrayStatus", "") & @CRLF) ;initial is 3 ;Loop for 30 seconds, updating the text every 1 second For $i = 1 to 30 sleep(900) ControlSetText("SysTrayStatus", "", "Static1", "Running loop " & $i & " of 30") ConsoleWrite($i & " State = " & WinGetState("SysTrayStatus", "") & @CRLF) ;always = 3 WinSetOnTop("SysTrayStatus", "", 1) ;reset this to the top Z-Order of Topmost windows in case someone clicks the taskbar Next1 point -
Problem with text scaling multiple GUI
Daemante2018 reacted to Melba23 for a topic
Daemante2018, This happens because the WM_SIZE handler is currently coded to change the font in every control that has been created up to the $iLast_Control dummy. So resizing any GUI in the script will cause every control up to that point in the script to undergo a font change. What you need to do is to limit the controls to change to those within the resizeable GUI - like this: ; Set resize mode for controls Opt("GUIResizeMode", $GUI_DOCKAUTO) Local $iGUIInitSize = 343 $SecondG = GUICreate("Second GUI", $iGUIInitSize, 611, -1, -1, BitOR($GUI_SS_DEFAULT_GUI, $WS_SIZEBOX, $WS_THICKFRAME), BitOR($WS_EX_TOPMOST, $WS_EX_WINDOWEDGE)) GUISetFont(12, 400, 0, "MS Sans Serif") GUISetBkColor(0xFFFFFF) $iFirstControl = GUICtrlCreateDummy() ; Start of control list <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< $SELECTOPTION = GUICtrlCreateCombo("Select OPTION", 8, 16, 121, 25, BitOR($CBS_DROPDOWN, $CBS_AUTOHSCROLL)) GUICtrlSetData(-1, "Option1|Options2") GUICtrlSetFont(-1, 12, 0, 0, "MS Sans Serif") GUICtrlSetCursor(-1, 0) $OPTIONLIST = GUICtrlCreateList("", 8, 64, 325, 524, BitOR($LBS_NOSEL, $WS_VSCROLL)) GUICtrlSetFont(-1, 12, 0, 0, "MS Sans Serif") $iLast_Control = GUICtrlCreateDummy() ; End of control list <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< GUISetState(@SW_HIDE) GUIRegisterMsg($WM_SIZE, "_WM_SIZE") and then change the handler code as follows: ; Reset font size for all controls on main GUI For $i = $iFirstControl To $iLast_Control GUICtrlSetFont($i, $iFontSize) Next Now only the controls in the Second GUI will have their font adjusted. M231 point -
Sowieso. When calling _OL_Open there is a feature to click away such messages. Please check parameters $bOL_WarningClick, $sWarningProgram, $iWinCheckTime and $iCtrlCheckTime. An example program (_OL_Warnings.au3) is provided, but needs to be modified if the window title or window text have changed (which is true for a german version of Outlook as all the code has been written for an english version). More details can be found in the wiki.1 point
-
Retrieving useable data from JSON
jantograaf reacted to TheXman for a topic
On a side note, in general, you may run into problems processing an array like this. If you don't encounter an "Index out of bounds" exception, you may end up in an endless loop or worse depending on the function calls. ;Start a loop to retrieve the study date of each study... While 1 $study_date = json_get($object,'[' & $i & '].date') If @error Then FileWriteLine($logfile,"Study-Date retrieval error") ExitLoop EndIf $i = $i + 1 WEnd Below, in the hidden content, you will see an example that shows 2 different ways of processing your array. One example uses a ForNext and the other uses a ForEach. The ForEach would most likely be used only if you wanted to process all of the items in an array. However, you could always set a condition in which you exited the loop. If you want to use an endless loop to process an array, then you should test to make sure the index is not out of bounds before referencing any array item. i.e. If $i < Ubounds($aSomeArray) Then <do process> Else ExitLoop.1 point -
Retrieving useable data from JSON
jantograaf reacted to TheXman for a topic
I'm not sure if you noticed, but if you click "reveal hidden contents", in my first post, I suggested a solution.1 point -
1 point
-
Retrieving useable data from JSON
jantograaf reacted to TheXman for a topic
Lookup and use the json_dump() function, in the json.au3 UDF file, to get a better idea of the naming scheme used to reference individual items.1 point -
Finally found how to do it ! #include <Constants.au3> #include <WinAPISysWin.au3> #include <WinAPIError.au3> #include <WinAPIConv.au3> _Main () Func _Main () Local $ctrl_handle Run ("notepad.exe") Local $hWnd = WinWaitActive ("[CLASS:Notepad]", "") Local $tPoint = DllStructCreate($tagPOINT) DllStructSetData($tPoint, "X", 500) DllStructSetData($tPoint, "Y", 500) _WinAPI_ScreenToClient ($hWnd, $tPoint) MsgBox (0,"Test",DllStructgetData($tPoint, "X") & "/" & DllStructGetData($tPoint, "Y")) Local $thWnd = $hWnd While True $ctrl_handle = _WinAPI_ChildWindowFromPointEx ($hWnd, $tPOINT) if not $ctrl_handle then MsgBox (0,"Error","Failure in finding the child window") Exit endif if $ctrl_handle = $thWnd then ExitLoop $thWnd = $ctrl_handle Wend MsgBox (0,"Handle", $thWnd) _MouseClickPlus($thWnd, "right", DllStructgetData($tPoint, "X"), DllStructGetData($tPoint, "Y"), 1) $tPoint = 0 EndFunc Func _MouseClickPlus($hWnd, $sButton = 'left', $vX = '', $vY = '', $iClicks = 1) Local $MK_LBUTTON = 0x0001 Local $WM_LBUTTONDOWN = 0x0201 Local $WM_LBUTTONUP = 0x0202 Local $MK_RBUTTON = 0x0002 Local $WM_RBUTTONDOWN = 0x0204 Local $WM_RBUTTONUP = 0x0205 Local $WM_MOUSEMOVE = 0x0200 If $sButton = 'left' Then $Button = $MK_LBUTTON $ButtonDown = $WM_LBUTTONDOWN $ButtonUp = $WM_LBUTTONUP ElseIf $sButton = 'right' Then $Button = $MK_RBUTTON $ButtonDown = $WM_RBUTTONDOWN $ButtonUp = $WM_RBUTTONUP EndIf If $vX = "" Or $vY = "" Then $MouseCoord = MouseGetPos() $vX = $MouseCoord[0] $vY = $MouseCoord[1] EndIf Local $stPoint = _MakeLong($vX, $vY) Local $i = 0 For $i = 1 To $iClicks _PostMessage($hWnd, $WM_MOUSEMOVE, 0, $stPoint) _PostMessage($hWnd, $ButtonDown, $Button, $stPoint) _PostMessage($hWnd, $ButtonUp, $Button, $stPoint) Next EndFunc Func _MakeLong($LoWord,$HiWord) Return BitOR($HiWord * 0x10000, BitAND($LoWord, 0xFFFF)) EndFunc Func _PostMessage($hWnd, $iMsg, $iwParam, $ilParam) Local $aResult, $err $aResult = DllCall("User32.dll", "bool", "PostMessageA", "hwnd", $hWnd, "int", $iMsg, "int", $iwParam, "int", $ilParam) $err = _WinAPI_GetLastError () if $err or not $aResult[0] then MsgBox (0,"Error","Access denied in post message with error " & $err) Exit endif Return $aResult[0] EndFunc1 point
-
Using RichEdit or even IE Embeded you can also create EDITOR this is only a matter of approach, to your needs For example: As to your last question: maybe you could try this: https://stackoverflow.com/questions/8499633/how-to-display-base64-images-in-html and take a look also here: and here: and here:1 point
-
$oExcel = _Excel_Open UDF error = 1, extended = -2147221005 - (Moved)
frigopontevedra reacted to JLogan3o13 for a topic
Moved to the appropriate forum. Moderation Team0 points