Leaderboard
Popular Content
Showing content with the highest reputation on 08/07/2020 in all areas
-
2020/08/16 New Version CropTool.au3 I've made some changes and fixes to this function: I added the possibility to vary both the thickness of the selector and its color. to customize the appearance and behavior of the tool, you can change the values of some variables in the function listing. See comments on lines 140-170 You can also vary the look of the border by setting a custom dash/space length pattern. Thanks to @UEZ for that. See here for reference. Hope it is free of bugs. (i don't know how to test it to see if it is also DPI aware??) Suggestions for improvements and bug reports are welcome. How to use this demo of use: hit Ctrl+PrintScreen to activate the tool LeftClick and drag on the borders of the tool to resize the area you can also Leftclick and drag within the area to move it around RightClick within the area to shot a screenshot of only the delimited area to the clipboard. in short "how to use the function" outside this demo in your programs: including the following 4 standard udf #include <Windowsconstants.au3> #include <WinAPISys.au3> #include <Misc.au3> #include <GDIPlus.au3> and pasting the _Crop function in your listing is all what you need, then: call the _Crop() function; the 'selector' appears around the mouse hovering the mouse over any side or corner the cursor should change accordingly; LeftClick on the edges and drag to redim the area, also LeftClick within the area and drag to move the selection around. When you are done with the selection, RightClick within the area or also hit the ESC key, the 4 element 1D array is returned to the caller and the 'selector' disappears from the screen Thank you ... below original post ... A function that allows you to freely and visually select an area of the screen Yes I know, there are already some in the forum, however here is yet another cropping tool. I collected some snippets from the forum and merged in a simple and quick cropping tool implemented as a single standalone function. The _Crop() function simply returns a 4-element 1D array with the x-y coordinates of the upper left and the width and height of the selected area, respectively in the elements [0] [1] [2] [3]. So it's up to you to make good use of these parameters An example of use: Since Windows already has both a screenprint functionkey to copy the whole screen to the clipboard and the Alt-printscreen shortkut to copy only the active window to the clipboard, I'm goinmg to bind this _crop() function combined with the Control-printscreen hotkey to create a "partial" screenshot of the delimited area of the screen. The captured screenshot of that area is copied to the clipboard, so you can paste it wherever you want. How to use it: after running the script, use the Control+Printscreen keys to activate the crop tool that appears around the mouse position; then use the mouse to visually resize and move the area and when you have delimited the desired area click with the right mouse button inside the area to copy it to the clipboard. Suggestions, improvements and finally error reports are welcome Happy cropping #AutoIt3Wrapper_Res_HiDpi=y #include <Windowsconstants.au3> #include <WinAPISys.au3> #include <Misc.au3> #include <GDIPlus.au3> #include <Clipboard.au3> ; ---------------------- ; -- Demo start -------- ; ---------------------- #include <ScreenCapture.au3> ; needed only For this demo Global $user32 = DllOpen("user32.dll") While 1 ; hit Control+Printscreen to call the _Crop Function If _IsPressed("11", $user32) And _IsPressed("2C", $user32) Then _example() ; 11 CTRL key + 2C PRINTSCREEN key ; hit Control + c to exit this script (can be castomized with other keys) If _IsPressed("11", $user32) And _IsPressed("43", $user32) Then ExitLoop ; 11 CTRL key + 43 C key Sleep(150) WEnd DllClose($user32) TrayTip("Crop demo", "End of the 'TSR' crop demo", 3, 1) ; (1) = Info icon Sleep(3000) Exit Func _example() $aRect = _Crop() ; mark the area If Not @extended Then ; if the ESC key was pressed within the _Crop function the @extended is set to 1 _GDIPlus_Startup() Local $hGui = GUICreate("", $aRect[2], $aRect[3], $aRect[0] - 1, $aRect[1] - 1, $WS_POPUPWINDOW) Local $idPic = GUICtrlCreatePic('', 0, 0, $aRect[2], $aRect[3]) Local $hTimer = TimerInit() Local $hBmp = _ScreenCapture_Capture('', $aRect[0], $aRect[1], $aRect[0] + $aRect[2] - 1, $aRect[1] + $aRect[3] - 1, False) Local $hBitmap = _GDIPlus_BitmapCreateFromHBITMAP($hBmp) Local $iMidX = $aRect[0] + $aRect[2] / 2 Local $iMidY = $aRect[1] + $aRect[3] / 2 ; snippet by UEZ ; https://www.autoitscript.com/forum/topic/129333-screen-capture-to-clipboard/?do=findComment&comment=898287 Local $bResult = _ClipBoard_Open(0) + _ClipBoard_Empty() + Not _ClipBoard_SetDataEx($hBmp, $CF_BITMAP) _ClipBoard_Close() If $bResult = 2 Then ToolTip("the area was copied to the clipboard", $iMidX, $iMidY, 'Info', 1, 6) Else ToolTip("Something went wrong", $iMidX, $iMidY, 'Error', 3, 6) EndIf ; snippet by Malkey ; https://www.autoitscript.com/forum/topic/191425-capturing-image-without-saving/?do=findComment&comment=1373088 Local $STM_SETIMAGE = 0x0172 GUICtrlSendMsg($idPic, $STM_SETIMAGE, $IMAGE_BITMAP, $hBmp) _WinAPI_DeleteObject($hBmp) GUISetState() DllCall("User32.dll", "int", "AnimateWindow", "hwnd", $hGui, "int", 750, "long", "0x00050002") ; Right-Left GUIDelete($hGui) Sleep(250) ToolTip('') ; #ce ; GUIDelete($hGui) _WinAPI_DeleteObject($hBmp) _GDIPlus_BitmapDispose($hBitmap) _GDIPlus_Shutdown() EndIf EndFunc ;==>_example ; ---------------------- ; -- Demo end ---------- ; ---------------------- ; #FUNCTION# ==================================================================================================================== ; Name ..........: _Crop ; Description ...: A function that allows you to freely and visually select an area of the screen ; Syntax ........: _Crop([$i_X = Default[, $i_Y = Default[, $i_W = Default[, $i_H = Default[, $iMinW = -1[, $iMaxW = -1[, ; $iMinH = -1[, $iMaxH = -1]]]]]]]]) ; ; - To resize the area click the left mouse button and drag on any of the moving colored edges of the tool. ; You can also LeftClick within the selected area and drag to move the whole selection. ; ; - To terminate the selection operation RightClick within the selected area. ; ; You can alse terminate the selection operation by hitting the ESC key; ; in that case the @extended macro will be setted to true ; ; Parameters ....: All parameters are optional: ; $i_X - [optional] an integer value. Default is MouseGetPos(0) - 50. ; The upper left X coordinate where you want the cropping tool to appear ; ; $i_Y - [optional] an integer value. Default is MouseGetPos(1) - 50. ; The upper left Y coordinate where you want the cropping tool to appear ; ; $i_W - [optional] an integer value. Default is 100. ; The initial width of the selection area ; ; $i_H - [optional] an integer value. Default is 100. ; The initial height of the selection area ; ; $iMinW - [optional] an integer value. Default is 1 (minimum allowed is 1). ; The minimum selectable width ; ; $iMaxW - [optional] an integer value. Default is -1 (no limit). ; The maximum selectable width ; ; $iMinH - [optional] an integer value. Default is 1 (minimum allowed is 1). ; The minimum selectable height ; ; $iMaxH - [optional] an integer value. Default is -1 (no limit). ; The maximum selectable height ; ; Return values .: - A 4 element 1D array where: ; element [0] the upperLeft X coordinate of the selected area ; element [1] the upperLeft Y coordinate of the selected area ; element [2] the width of the selected area ; element [3] the height of the selected area ; ; @extended is set to True if you exit from the _crop() function by pressing the ESC key ; ; Author ........: Chimp (Gianni Addiego) ; Modified ......: ; Remarks .......: ; Related .......: ; Link ..........: ; Example .......: ; =============================================================================================================================== ; Func _Crop($i_X = MouseGetPos(0) - 50, $i_Y = MouseGetPos(1) - 50, $i_W = 100, $i_H = 100, $iMinW = -1, $iMaxW = -1, $iMinH = -1, $iMaxH = -1) Func _Crop($i_X = Default, $i_Y = Default, $i_W = Default, $i_H = Default, $iMinW = 1, $iMaxW = -1, $iMinH = 1, $iMaxH = -1) _GDIPlus_Startup() If ($i_X = '') Or ($i_X = Default) Then $i_X = MouseGetPos(0) - 50 If ($i_Y = '') Or ($i_Y = Default) Then $i_Y = MouseGetPos(1) - 50 If ($i_W = '') Or ($i_W = Default) Then $i_W = 100 If ($i_H = '') Or ($i_H = Default) Then $i_H = 100 If ($iMinW < 1) Or ($iMinW = Default) Then $iMinW = 1 If ($iMaxW < 1) Or ($iMaxW = Default) Then $iMaxW = 65535 If ($iMinH < 1) Or ($iMinH = Default) Then $iMinH = 1 If ($iMaxH < 1) Or ($iMaxH = Default) Then $iMaxH = 65535 ; used local variables Local $hGUI2, $hGUI3, $aWinPos2, $aPrevPos2[4], $aClientSize Local $iX, $iY, $iW, $iH Local Enum $x, $y Local $iOuterTolerance, $iBorder, $iInnerTolerance Local $hGraphic, $hPen, $AlphaKey = 0xFF000000, $RectColor, $RectBgColor Local $hDLL = DllOpen("user32.dll") Local $fOffset, $iDelay, $iTimerID = TimerInit() Local $iCursorID, $iBorderID, $aMousePointer, $iSide, $iTopBot, $iInner, $iRightEdge, $iBottomEdge, $iMouseOffsetX, $iMouseOffsetY Local $bEscape ; ================================================================================== ; Set the appearance and behaviour of the tool ; ================================================================================== $iBorder = 2 ; the width of the colored border (minimum 1) ; since with a very thin border it is difficult to click on it to drag it ; it is possible to set an external courtesy area authorized to click on the border ; even if the mouse is not exactly on it (it can also be set to 0 to disable it) $iOuterTolerance = 4 ; 'courtesy' external area allowed to click on the border ; same as above but for the inside of the edge $iInnerTolerance = 3 ; 'courtesy' internal area allowed to click on the border $RectColor = 0xFFFF0000 ; The color of the colored moving edge $RectBgColor = 0xFFFFFF00 ; The Background color of the colored moving edge $iDelay = 50 ; this value determines the rotation speed of the moving colored border. The lower it is, the faster it is ; here the pattern of the moving edge can be customized ; Thanks to @UEZ for this snippet. See Here for reference: https://www.autoitscript.com/forum/topic/185769-moving-dash-rectangle/?do=findComment&comment=1343856 Local $iCount = 4, $tArray = DllStructCreate("float;float;float;float") DllStructSetData($tArray, 1, 2) ; dash length DllStructSetData($tArray, 2, 4) ; space length DllStructSetData($tArray, 3, 2) ; dash length DllStructSetData($tArray, 4, 4) ; space length ; Important!: also set the below variable as the sum of all the above dash/space values ; ========== Local $iDotsDashesTotLen = 2 + 4 + 2 + 4 ; <--- adapt this variable to the above values ; ================================================================================== ; Create a transparent window where to draw the moving colored edge effect using the $iBorder variable ; X and Y coordinates refers to where will be placed the client crop area (not the draggable outer colored border) $hGUI2 = GUICreate('', $i_W + $iBorder * 2, $i_H + $iBorder * 2, $i_X - $iBorder, $i_Y - $iBorder, $WS_POPUP, BitOR($WS_EX_LAYERED, $WS_EX_TOPMOST)) ; make sure $AlphaKey color is different from both $RectColor and $RectBgColor While ($AlphaKey = $RectColor) Or ($AlphaKey = $RectBgColor) $AlphaKey += 1 WEnd GUISetBkColor($AlphaKey, $hGUI2) _WinAPI_SetLayeredWindowAttributes($hGUI2, $AlphaKey, 0, $LWA_COLORKEY) ; Create a transparent window wider than the main one to allow the custom mouse cursor to be displayed even beyond the colored border (Tolerance) ; also, since this window is not "passthrough", it prevents mouse clicks from passing underneath. $hGUI3 = GUICreate('', $i_W + $iBorder * 2 + $iOuterTolerance * 2, $i_H + $iBorder * 2 + $iOuterTolerance * 2, $i_X - $iBorder - $iOuterTolerance, $i_Y - $iBorder - $iOuterTolerance, $WS_POPUP, BitOR($WS_EX_LAYERED, $WS_EX_TOPMOST)) WinSetTrans($hGUI3, "", 1) WinSetOnTop($hGUI3, "", $WINDOWS_ONTOP) GUISetState(@SW_SHOW, $hGUI2) GUISetState(@SW_SHOW, $hGUI3) $hPen = _GDIPlus_PenCreate($RectColor, $iBorder * 2) ; why * 2 ?? _GDIPlus_PenSetColor($hPen, $RectColor) $hGraphic = _GDIPlus_GraphicsCreateFromHWND($hGUI2) Do $iSide = 0 $iTopBot = 0 $iInner = 0 $bEscape = False $aMousePointer = GUIGetCursorInfo($hGUI2) ; zero based $aWinPos2 = WinGetPos($hGUI2) $aClientSize = WinGetClientSize($hGUI2) ; ----------------------- ; check pointer position ; -------------------------------------------------------------------------------------------------------------------------------------------------------- If _ ; Pointer is on the left border (($aMousePointer[$x] >= -$iOuterTolerance) And ($aMousePointer[$x] < ($iBorder + $iInnerTolerance))) And _ (($aMousePointer[$y] >= -$iOuterTolerance) And ($aMousePointer[$y] < ($aClientSize[1] + $iOuterTolerance))) Then $iSide = 1 If _ ; Pointer is on the right border (($aMousePointer[$x] >= ($aClientSize[0] - $iBorder - $iInnerTolerance)) And ($aMousePointer[$x] < ($aClientSize[0] + $iOuterTolerance))) And _ (($aMousePointer[$y] >= -$iOuterTolerance) And ($aMousePointer[$y] < ($aClientSize[1] + $iOuterTolerance))) Then $iSide = 2 If _ ; Pointer is on the top border (($aMousePointer[$y] >= -$iOuterTolerance) And ($aMousePointer[$y] < ($iBorder + $iInnerTolerance))) And _ (($aMousePointer[$x] >= -$iOuterTolerance) And ($aMousePointer[$x] < ($aClientSize[0] + $iOuterTolerance))) Then $iTopBot = 3 If _ ; Pointer is on the bottom border (($aMousePointer[$y] >= ($aClientSize[1] - $iBorder - $iInnerTolerance)) And ($aMousePointer[$y] < $aClientSize[1] + $iOuterTolerance)) And _ (($aMousePointer[$x] >= -$iOuterTolerance) And ($aMousePointer[$x] < ($aClientSize[0] + $iOuterTolerance))) Then $iTopBot = 6 If _ ; Pointer is within the client area (($aMousePointer[$x] >= ($iBorder + $iInnerTolerance)) And $aMousePointer[$x] < ($aClientSize[0] - $iBorder - $iInnerTolerance)) And _ (($aMousePointer[$y] >= ($iBorder + $iInnerTolerance)) And $aMousePointer[$y] < ($aClientSize[1] - $iBorder - $iInnerTolerance)) Then $iInner = 9 ; -------------------------------------------------------------------------------------------------------------------------------------------------------- $iBorderID = $iSide + $iTopBot + $iInner ; ; SetCursor ; --------- $iCursorID = 0 Switch $iBorderID Case 0 $iCursorID = 2 ; ARROW Case 1, 2 ; 1 left ; 2 right $iCursorID = 13 ; SIZEWE Case 3, 6 ; 3 top ; 6 bottom $iCursorID = 11 ; SIZENS Case 5, 7 ; 5 TopRight ; 7 BottomLeft $iCursorID = 10 ; SIZENESW Case 4, 8 ; 4 TopLeft ; 8 BottomRight $iCursorID = 12 ; SIZENWSE Case 9 ; 9 Inside $iCursorID = 0 ; HAND - or SIZEALL (9) EndSwitch GUISetCursor($iCursorID, 1) ; ------------------------------------------------------- ; If LeftClick on the tool then Drag or redimm selector ; ------------------------------------------------------- If _IsPressed("1", $hDLL) And $iBorderID And (WinActive($hGUI2) Or WinActive($hGUI3)) Then ; Left clicked $aWinPos2 = WinGetPos($hGUI2) Switch $iBorderID Case 0 Case 1 ; Pointer is on the left border $iMouseOffsetX = $aWinPos2[0] - MouseGetPos(0) $iRightEdge = $aWinPos2[0] + WinGetClientSize($hGUI2)[0] Case 2 ; Pointer is on the right border $iMouseOffsetX = $aWinPos2[0] + $aWinPos2[2] - MouseGetPos(0) Case 3 ; Pointer is on the top border $iMouseOffsetY = $aWinPos2[1] - MouseGetPos(1) $iBottomEdge = $aWinPos2[1] + $aWinPos2[3] Case 4 ; Pointer is on the top-left corner $iMouseOffsetY = $aWinPos2[1] - MouseGetPos(1) $iMouseOffsetX = $aWinPos2[0] - MouseGetPos(0) $iRightEdge = $aWinPos2[0] + WinGetClientSize($hGUI2)[0] $iBottomEdge = $aWinPos2[1] + $aWinPos2[3] Case 5 ; Pointer is on the top-right corner $iMouseOffsetX = $aWinPos2[0] + $aWinPos2[2] - MouseGetPos(0) $iMouseOffsetY = $aWinPos2[1] - MouseGetPos(1) $iBottomEdge = $aWinPos2[1] + $aWinPos2[3] Case 6 ; Pointer is on the bottom border $iMouseOffsetY = $aWinPos2[1] + $aWinPos2[3] - MouseGetPos(1) Case 7 ; Pointer is on the bottom-left $iMouseOffsetY = $aWinPos2[1] + $aWinPos2[3] - MouseGetPos(1) $iMouseOffsetX = $aWinPos2[0] - MouseGetPos(0) $iRightEdge = $aWinPos2[0] + WinGetClientSize($hGUI2)[0] Case 8 ; Pointer is on the bottom-right $iMouseOffsetY = $aWinPos2[1] + $aWinPos2[3] - MouseGetPos(1) $iMouseOffsetX = $aWinPos2[0] + $aWinPos2[2] - MouseGetPos(0) Case 9 $iMouseOffsetY = $aWinPos2[1] - MouseGetPos(1) $iMouseOffsetX = $aWinPos2[0] - MouseGetPos(0) EndSwitch Do $iX = Default $iY = Default $iW = Default $iH = Default Switch $iBorderID Case 1 ; Pointer is on the left border $iX = MouseGetPos(0) + $iMouseOffsetX $iW = $iRightEdge - MouseGetPos(0) + -$iMouseOffsetX Case 2 ; Pointer is on the right border $iW = (MouseGetPos(0) - $aWinPos2[0]) + $iMouseOffsetX Case 3 ; Pointer is on the top border $iY = MouseGetPos(1) + $iMouseOffsetY $iH = $iBottomEdge - MouseGetPos(1) + -$iMouseOffsetY Case 4 ; Pointer is on the top-left corner $iX = MouseGetPos(0) + $iMouseOffsetX $iY = MouseGetPos(1) + $iMouseOffsetY $iW = $iRightEdge - MouseGetPos(0) + -$iMouseOffsetX $iH = $iBottomEdge - MouseGetPos(1) + -$iMouseOffsetY Case 5 ; Pointer is on the top-right corner $iY = MouseGetPos(1) + $iMouseOffsetY $iW = (MouseGetPos(0) - $aWinPos2[0]) + $iMouseOffsetX $iH = $iBottomEdge - MouseGetPos(1) + -$iMouseOffsetY Case 6 ; Pointer is on the bottom border $iH = (MouseGetPos(1) - $aWinPos2[1]) + $iMouseOffsetY Case 7 ; Pointer is on the bottom-left corner $iX = MouseGetPos(0) + $iMouseOffsetX $iW = $iRightEdge - MouseGetPos(0) + -$iMouseOffsetX $iH = (MouseGetPos(1) - $aWinPos2[1]) + $iMouseOffsetY Case 8 ; Pointer is on the bottom-right corner $iW = (MouseGetPos(0) - $aWinPos2[0]) + $iMouseOffsetX $iH = (MouseGetPos(1) - $aWinPos2[1]) + $iMouseOffsetY Case 9 ; Pointer is inside the client area $iX = MouseGetPos(0) + $iMouseOffsetX $iY = MouseGetPos(1) + $iMouseOffsetY EndSwitch If $iW > ($iMaxW + $iBorder * 2) Then $iW = $iMaxW + $iBorder * 2 $iX = Default EndIf If $iW < ($iMinW + $iBorder * 2) Then $iW = $iMinW + $iBorder * 2 $iX = Default EndIf If $iH > ($iMaxH + $iBorder * 2) Then $iH = $iMaxH + $iBorder * 2 $iY = Default EndIf If $iH < ($iMinH + $iBorder * 2) Then $iH = $iMinH + $iBorder * 2 $iY = Default EndIf WinMove($hGUI2, '', $iX, $iY, $iW, $iH) GUISetCursor($iCursorID, 1) $aWinPos2 = WinGetPos($hGUI2) $aClientSize = WinGetClientSize($hGUI2) ; If GUI2 moved or resized then redraw the colored border and reposition also GUI3 If $aPrevPos2[0] <> $aWinPos2[0] Or $aPrevPos2[1] <> $aWinPos2[1] Or $aPrevPos2[2] <> $aWinPos2[2] Or $aPrevPos2[3] <> $aWinPos2[3] Then ; store new position/size $aPrevPos2[0] = $aWinPos2[0] $aPrevPos2[1] = $aWinPos2[1] $aPrevPos2[2] = $aWinPos2[2] $aPrevPos2[3] = $aWinPos2[3] _GDIPlus_GraphicsDispose($hGraphic) WinMove($hGUI3, '', $aWinPos2[0] - $iOuterTolerance, $aWinPos2[1] - $iOuterTolerance, $aWinPos2[2] + $iOuterTolerance * 2, $aWinPos2[3] + $iOuterTolerance * 2) $hGraphic = _GDIPlus_GraphicsCreateFromHWND($hGUI2) _GDIPlus_GraphicsClear($hGraphic, $AlphaKey) ; erase rect _GDIPlus_PenSetDashStyle($hPen, $GDIP_DASHSTYLESOLID) _GDIPlus_PenSetColor($hPen, $RectBgColor) _GDIPlus_GraphicsDrawRect($hGraphic, 0, 0, $aWinPos2[2], $aWinPos2[3], $hPen) ; _GDIPlus_PenSetDashStyle($hPen, $GDIP_DASHSTYLEDOT) DllCall($__g_hGDIPDll, "int", "GdipSetPenDashArray", "handle", $hPen, "struct*", $tArray, "long", $iCount) _GDIPlus_PenSetColor($hPen, $RectColor) _GDIPlus_GraphicsDrawRect($hGraphic, 0, 0, $aWinPos2[2], $aWinPos2[3], $hPen) ; draw again rect EndIf If TimerDiff($iTimerID) > $iDelay Then $fOffset = Mod($fOffset + .5, $iDotsDashesTotLen) ; this is the key for the animated dotted line ;-) by UEZ ; https://www.autoitscript.com/forum/topic/185769-moving-dash-rectangle/?do=findComment&comment=1343851 DllCall($__g_hGDIPDll, "int", "GdipSetPenDashOffset", "handle", $hPen, "float", $fOffset) _GDIPlus_GraphicsClear($hGraphic, $AlphaKey) ; erase rect _GDIPlus_PenSetDashStyle($hPen, $GDIP_DASHSTYLESOLID) _GDIPlus_PenSetColor($hPen, $RectBgColor) _GDIPlus_GraphicsDrawRect($hGraphic, 0, 0, $aWinPos2[2], $aWinPos2[3], $hPen) ; _GDIPlus_PenSetDashStyle($hPen, $GDIP_DASHSTYLEDOT) DllCall($__g_hGDIPDll, "int", "GdipSetPenDashArray", "handle", $hPen, "struct*", $tArray, "long", $iCount) _GDIPlus_PenSetColor($hPen, $RectColor) _GDIPlus_GraphicsDrawRect($hGraphic, 0, 0, $aWinPos2[2], $aWinPos2[3], $hPen) ; draw again rect $iTimerID = TimerInit() EndIf Until Not _IsPressed("1", $hDLL) ; Right click released EndIf If TimerDiff($iTimerID) > $iDelay Then $fOffset = Mod($fOffset + .5, $iDotsDashesTotLen) DllCall($__g_hGDIPDll, "int", "GdipSetPenDashOffset", "handle", $hPen, "float", $fOffset) ; this is the key for the animated dotted line ;-) by UEZ _GDIPlus_GraphicsClear($hGraphic, $AlphaKey) ; erase rect _GDIPlus_PenSetDashStyle($hPen, $GDIP_DASHSTYLESOLID) _GDIPlus_PenSetColor($hPen, $RectBgColor) _GDIPlus_GraphicsDrawRect($hGraphic, 0, 0, $aWinPos2[2], $aWinPos2[3], $hPen) ; _GDIPlus_PenSetDashStyle($hPen, $GDIP_DASHSTYLEDOT) DllCall($__g_hGDIPDll, "int", "GdipSetPenDashArray", "handle", $hPen, "struct*", $tArray, "long", $iCount) _GDIPlus_PenSetColor($hPen, $RectColor) _GDIPlus_GraphicsDrawRect($hGraphic, 0, 0, $aWinPos2[2], $aWinPos2[3], $hPen) ; draw again rect $iTimerID = TimerInit() EndIf If _IsPressed('1B', $hDLL) Then $bEscape = True ; 1B ESC key Until ((_IsPressed('2', $hDLL) Or $bEscape) And (WinActive($hGUI2) Or WinActive($hGUI3))) ; RightClick means I'm done with selection Do ; neutralize the RightClick persistency Until Not _IsPressed('2', $hDLL) Local $aGotRect[4] = [ _ $aWinPos2[0] + $iBorder, _ ; ....... UpperLeft X of window's client area $aWinPos2[1] + $iBorder, _ ; ....... UpperLeft Y of window's client area $aWinPos2[2] - $iBorder * 2, _ ; ... Width of window's client area $aWinPos2[3] - $iBorder * 2 _ ; .... Height of window's client area ] _GDIPlus_PenDispose($hPen) _GDIPlus_GraphicsDispose($hGraphic) _GDIPlus_Shutdown() DllClose($hDLL) $tArray = 0 GUIDelete($hGUI3) GUIDelete($hGUI2) Return SetError(0, $bEscape, $aGotRect) EndFunc ;==>_Crop CropTool.au31 point
-
I have checked also my script which I coded sometime in 2018 on my previous notebook without DPI and it didn't work either. I've updated the script by adding the function _WinAPI_SetProcessDpiAwarenessContext which seems to work properly on my Win10 v2004. I don't know if the script works properly on OS < Win10. I've not check yet if #AutoIt3Wrapper_Res_HiDpi=y is sufficient.1 point
-
@Danp2 Thanks a lot. The workaround works! The matching element was wrong. Completly right.1 point
-
There : #include <GUIConstants.au3> #include <Constants.au3> #include <GDIPlus.au3> Global $size = 400 Global $__g_tStruct, $__g_tString, $__g_iWidth, $__g_iHeight _GDIPlus_Startup() _GetScreen_Initialize($size, $size) $timer = TimerInit() loop() ConsoleWrite(TimerDiff($timer) & @CRLF) $2d_Gui = GUICreate("", $size, $size, Default, Default, $WS_POPUP) GUISetState(@SW_SHOW, $2d_Gui) $2d_hGraphic = _GDIPlus_GraphicsCreateFromHWND($2d_Gui) $2d_hBitmap =_GetScreen_GetBitMap() $2d_hBackBuffer = _GDIPlus_ImageGetGraphicsContext($2d_hBitmap) _GDIPlus_GraphicsDrawImageRect($2d_hGraphic, $2d_hBitmap, 0, 0, $size, $size) While True If GUIGetMsg() = $GUI_EVENT_CLOSE Then ExitLoop WEnd _GDIPlus_GraphicsDispose($2d_hBackBuffer) _GDIPlus_BitmapDispose($2d_hBitmap) _GDIPlus_GraphicsDispose($2d_hGraphic) ;_GetScreen_SaveFile("Test.jpg") ;ConsoleWrite(TimerDiff($timer) & @CRLF) _GDIPlus_Shutdown() Func loop() Local $width = 2, $r, $b, $color For $y = 0 To $size - 1 Step $width $b = Int(($y / $size) * 255) For $x = 0 To $size - 1 Step $width $r = Int(($x / $size) * 255) $color = rgbToRGB($r, Random(0, 255, 1), $b) ;ConsoleWrite (Hex($color) & @CRLF) _GetScreen_SetPixelEX($x, $y, $color) _GetScreen_SetPixelEX($x + 1, $y, $color) _GetScreen_SetPixelEX($x, $y + 1, $color) _GetScreen_SetPixelEX($x + 1, $y + 1, $color) Next Next EndFunc ;==>loop Func rgbToRGB($r, $g, $b) Return Dec("FF" & Hex($r, 2) & Hex($g, 2) & Hex($b, 2)) EndFunc ;==>rgbToRGB Func _GetScreen_SetPixelEX($iX, $iY, $iValue) DllStructSetData($__g_tStruct, "color", $iValue, ($iY * $__g_iWidth) + $iX + 1) EndFunc ;==>_GetScreen_SetPixel Func _GetScreen_Initialize($iWidth, $iHeight) $__g_iWidth = $iWidth $__g_iHeight = $iHeight $__g_tStruct = DllStructCreate("int color [" & $iWidth * $iHeight & "]") EndFunc ;==>_GetScreen_Initialize Func _GetScreen_GetBitMap() Return _GDIPlus_BitmapCreateFromScan0($__g_iWidth, $__g_iHeight, $GDIP_PXF32ARGB, $__g_iWidth * 4, DllStructGetPtr($__g_tStruct, "color")) EndFunc ;==>_GetScreen_GetBitMap I extracted the _GetScreen_* functions from a personal (unpublished) UDF that I made to fast capture part of the screen.1 point
-
Searching specific content in Text file or AU3
seadoggie01 reacted to Nine for a topic
New version available (added support to copy include file names)...1 point -
How to destroy tooltip?
Professor_Bernd reacted to MaximusCZ for a topic
Since I stumbled upon this thread after 10 years and there is still no valid response, I present my solution, for whomever might come looking for solution after me. To Show ToolTip for desired time, while the script continues in the meantime, I define custom tooltip function wrapper: Func _ToolTip($msg = "", $timeout = 1000) ToolTip($msg) AdlibRegister(_ToolTipStop, $timeout) EndFunc Func _ToolTipStop() ToolTip("") AdlibUnRegister(_ToolTipStop) EndFunc This destroys the tooltip after set timeout. Note that here I use timeout as second argument, if you wish to display the tooltip on specified location, you have to add those parameters.1 point -
ImageSearch Usage Explanation
TinyCoopMan reacted to kjensen for a topic
I think it's fine. I appreciate that I can use that now instead of merging Auto Hot Key/AutoIT type features. I look forward to re-writing some of my mcros to incorporate this and thank you again for the intro into Image search1 point -
Adlib function help
Professor_Bernd reacted to water for a topic
Don't use MouseClick, use ControlClick to click away the pop up window.1 point -
7-zip32.dll
BlackLumiere reacted to jak for a topic
Functions for 7-zip32.dll To hide the created window, you need to use -hide for the $cmdline parameter The newest files and 7-zip32.dll are on my website now: http://www.jak-software.org/pub/autoit-stuff/7-zip/ (2006/10/14: Only 0.4 at the moment) Newest Version: 0.4.1 (2006/10/15) [0.5 Alpha 1 Removed] New in 0.4.1 includes the Multiple Zip Script from cue (http://www.autoitscript.com/forum/index.ph...586&hl=7zip), but modified to use my functions.Works with AutoIT 3.2 now (Tested with 3.2.0.1 inside Wine in Linux)7_zip32.dll SevenZip_0_4_1.zip1 point -
Create a GUI with only the Close button.
Professor_Bernd reacted to guinness for a topic
Have you ever wondered how do I create a GUI like the one shown below?! Then look no further with these Examples. I was playing around with $WS_DLGFRAME and figured that if I BitOR'd it with $WS_SIZEBOX it would create a GUI without the minimize and maximize, but what if I didn't want the re-sizing? After some playing around I realised that replacing $WS_SIZEBOX with $WS_SYSMENU would accomplish this instead of using WM_COMMAND to intercept SC_SIZE from the GUI. Then ?do=embed' frameborder='0' data-embedContent> pointed out it could be done via a different approach, so I updated using his way Examples below are for both re-sizing and non re-sizing as well as 2 Examples that don't appear in the TaskBar, this is due to using the hidden window [AutoItWinGetTitle()] as the parent handle. Any suggestions, then please post below. Thanks. Examples: #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> Example1() ; Without Re-Sizing. Example2() ; With Re-Sizing. Example3() ; Without Re-Sizing & No TaskBar. Example4() ; With Re-Sizing & No TaskBar. Func Example1() ; Without Re-Sizing. Local $hGUI = GUICreate('GUI With Only Close', 250, 250, -1, -1, BitXOR($GUI_SS_DEFAULT_GUI, $WS_MINIMIZEBOX)) GUISetState(@SW_SHOW, $hGUI) While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop EndSwitch WEnd GUIDelete($hGUI) EndFunc ;==>Example1 Func Example2() ; With Re-Sizing. Local $hGUI = GUICreate('GUI With Only Close', 250, 250, -1, -1, BitXOR($GUI_SS_DEFAULT_GUI, $WS_SIZEBOX, $WS_MINIMIZEBOX)) GUISetState(@SW_SHOW, $hGUI) While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop EndSwitch WEnd GUIDelete($hGUI) EndFunc ;==>Example2 Func Example3() ; Without Re-Sizing & No TaskBar. Local $hGUI = GUICreate('GUI With Only Close', 250, 250, -1, -1, BitXOR($GUI_SS_DEFAULT_GUI, $WS_MINIMIZEBOX), -1, WinGetHandle(AutoItWinGetTitle())) GUISetState(@SW_SHOW, $hGUI) While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop EndSwitch WEnd GUIDelete($hGUI) EndFunc ;==>Example3 Func Example4() ; With Re-Sizing & No TaskBar. Local $hGUI = GUICreate('GUI With Only Close', 250, 250, -1, -1, BitXOR($GUI_SS_DEFAULT_GUI, $WS_SIZEBOX, $WS_MINIMIZEBOX), -1, WinGetHandle(AutoItWinGetTitle())) GUISetState(@SW_SHOW, $hGUI) While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop EndSwitch WEnd GUIDelete($hGUI) EndFunc ;==>Example4Old way I was doing it: #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> Example5() ; Old Way Of Doing It! Func Example5() ; Old Way Of Doing It! Local $hGUI = GUICreate('GUI With Only Close', 250, 250, -1, -1, BitOR($WS_SIZEBOX, $WS_DLGFRAME)) GUIRegisterMsg($WM_SYSCOMMAND, 'WM_SYSCOMMAND') GUISetState(@SW_SHOW, $hGUI) While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop EndSwitch WEnd GUIDelete($hGUI) EndFunc ;==>Example5 Func WM_SYSCOMMAND($hWnd, $iMsg, $iwParam, $ilParam) #forceref $hWnd, $iMsg, $ilParam Local Const $SC_MAXIMIZE = 0xF030, $SC_MINIMIZE = 0xF020, $SC_RESTORE = 0xF120, $SC_SIZE = 0xF000 ; $SC_MOVE = 0xF010 Switch BitAND($iwParam, 0xFFF0) Case $SC_MAXIMIZE, $SC_MINIMIZE, $SC_RESTORE, $SC_SIZE Return -1 EndSwitch Return $GUI_RUNDEFMSG EndFunc ;==>WM_SYSCOMMAND ?do=embed' frameborder='0' data-embedContent>1 point -
Remove: Minimize, Restore Down, Maximize and Close
Professor_Bernd reacted to Malkey for a topic
Try this. #include <GUIConstantsEx.au3> #include <WinAPI.au3> #include <WindowsConstants.au3> Local $iGuiWidth = 500 ; initial width of window Local $sTitle = "Window Title" ; caption for window ;$hGui = GUICreate($sTitle, $iGuiWidth, 400, -1, -1, BitxOR($GUI_SS_DEFAULT_GUI, $WS_MINIMIZEBOX)) ; Exit box & Centre title Local $hGui = GUICreate($sTitle, $iGuiWidth, 400, -1, -1, $WS_CAPTION) ; Centre title only (Press Esc to exit) GUISetState(@SW_SHOW); will display an empty dialog box SetCentreTitle($hGui, $sTitle) While 1 $msg = GUIGetMsg() If $msg = $GUI_EVENT_CLOSE Then ExitLoop WEnd ;GUIDelete() Func SetCentreTitle($hWnd, $sTitle) Local $aWPos = WinGetPos($hWnd) $hDC = _WinAPI_GetDC($hWnd) Do $sTitle = ' ' & $sTitle & " " $tSize = _WinAPI_GetTextExtentPoint32($hDC, $sTitle) WinSetTitle($hWnd, "", $sTitle) ;sleep(50) ; Until DllStructGetData($tSize, 1) > $aWPos[2]*2 ; 1.2 ; Title on right Until DllStructGetData($tSize, 1) > $aWPos[2] * 1.2 ; Title at centre EndFunc ;==>SetCentreTitle Edit: Added <GUIConstantsEx.au3>, <WinAPI.au3>, and <WindowsConstants.au3> behind the three blank #includes, as mentioned in the next 2 posts.1 point -
[SOLVED] Center a window title
Professor_Bernd reacted to martin for a topic
The _API are now _WINAPI Here's another way to do it #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <winapi.au3> $guiwid = 600;initial width of window $Title = " Some Caption";caption for window $hG = GUICreate("My GUI", $guiwid, 400, -1, -1, BitOR($WS_MINIMIZEBOX, $WS_SIZEBOX, $WS_THICKFRAME, $WS_SYSMENU, $WS_CAPTION, $WS_POPUP, $WS_POPUPWINDOW, $WS_GROUP, $WS_BORDER, $WS_CLIPSIBLINGS)); will create a dialog box that when displayed is centered GUISetState(@SW_SHOW); will display an empty dialog box SetCentreTitle($hG, $Title) GUIRegisterMsg($WM_SIZE, "ReTitle") While 1 $msg = GUIGetMsg() If $msg = $GUI_EVENT_CLOSE Then ExitLoop WEnd GUIDelete() Func SetCentreTitle($hWnd, $sTitle) Local $wp = WinGetPos($hWnd) $hDC = _WinAPI_GetDC($hWnd) Do $sTitle = ' ' & $sTitle & ' ' $size = _WinAPI_GetTextExtentPoint32($hDC, $sTitle) Until DllStructGetData($size, 1) > $wp[2] - 110;110 was by trial and error WinSetTitle($hWnd, "", $sTitle) EndFunc ;==>SetCentreTitle Func ReTitle($hWnd, $msg, $wParam, $lParam) SetCentreTitle($hWnd, $Title) EndFunc ;==>reTitle1 point