Leaderboard
Popular Content
Showing content with the highest reputation on 06/25/2024 in all areas
-
You need a sleep(10) before the WEnd in the tracking function at line 69, it's eating a whole core as it is now. Maybe also make it so the mouse can be moved in any direction, not just from left to right and from top to bottom, but also from right to left and bottom to top.2 points
-
A Non-Strict JSON UDF (JSMN)
TheDcoder reacted to argumentum for a topic
..we don't have an introductions area, so I guess any thread is good. So without any further ado: Welcome to the forum @CJR0071 point -
@Werty Yes, you are right. I will add even more. Like: Move whole rectangle after selection and adjusting each side of the rectangle. But until now my focus was to get rid of the click-through problem. @ioa747 Thanks for pointing this out!1 point
-
1 point
-
$hBLK remains alive after the end !1 point
-
Okay, here is the final solution. Two windows. One window to draw on. Another window to block the mouse. 100% blocking mouse interactions with any underlying window. #include <GDIPlus.au3> #include <WindowsConstants.au3> HotKeySet("{ESC}", "End") ; DPI awareness Win10 & Win11 If @OSVersion = 'WIN_10' Or @OSVersion = 'WIN_11' Then DllCall("User32.dll", "bool", "SetProcessDpiAwarenessContext", "hwnd", -2) EndIf _GDIPlus_Startup() Local $hGUI = GUICreate("", @DesktopWidth, @DesktopHeight, 0, 0, $WS_POPUP, BitOR($WS_EX_TOPMOST, $WS_EX_LAYERED)) ; Main GUI Local $hBLK = GUICreate("", @DesktopWidth, @DesktopHeight, 0, 0, $WS_POPUP, BitOR($WS_EX_TOPMOST, $WS_EX_TOOLWINDOW)) ; Mouse Block GUI WinSetTrans($hBLK, "", 1) ; 0 = clicktrough | > 0 = Non clickthrough Local $hGDC = _WinAPI_GetDC($hGUI) Local $hMDC = _WinAPI_CreateCompatibleDC($hGDC) Local $hBit = _WinAPI_CreateCompatibleBitmap($hGDC, @DesktopWidth, @DesktopHeight) Local $hOld = _WinAPI_SelectObject($hMDC, $hBit) Local $hGFX = _GDIPlus_GraphicsCreateFromHDC($hMDC) Local $hPen = _GDIPlus_PenCreate(0xFF00FF00, 2) _GDIPlus_GraphicsSetSmoothingMode($hGFX, $GDIP_SMOOTHINGMODE_HIGHQUALITY) GUISetState(@SW_SHOW, $hBLK) GUISetState(@SW_SHOW, $hGUI) ; Pre-create structs outside the function if they do not change Global $tSize = DllStructCreate("int;int") Global $tPSrc = DllStructCreate("int;int") Global $tPDst = DllStructCreate("int;int") Global $tBlnd = DllStructCreate("byte;byte;byte;byte") ; Initialize constant values in the structs DllStructSetData($tSize, 1, @DesktopWidth) DllStructSetData($tSize, 2, @DesktopHeight) DllStructSetData($tBlnd, 3, 255) ; Alpha value 0-255 DllStructSetData($tBlnd, 4, 1) ; AC_SRC_ALPHA | Has Alpha = 1 | Has No Alpha = 0 While 1 StartMouseTracking($hGUI, $hGDC, $hMDC, $hGFX, $hPen) WEnd Func StartMouseTracking($hGUI, $hGDC, $hMDC, $hGFX, $hPen) Local $topLeft[2], $bottomRight[2], $aCall Local $isDragging = False While 1 $aCall = DllCall("user32.dll", "short", "GetAsyncKeyState", "int", 0x01) If BitAND($aCall[0], 0x8000) <> 0 Then ; Left mouse button is pressed down If Not $isDragging Then $topLeft[0] = MouseGetPos(0) $topLeft[1] = MouseGetPos(1) $isDragging = True Else ; Mouse is dragging Local $currentX = MouseGetPos(0) Local $currentY = MouseGetPos(1) If $currentX <> $bottomRight[0] Or $currentY <> $bottomRight[1] Then $bottomRight[0] = $currentX $bottomRight[1] = $currentY DrawRectangle($topLeft[0], $topLeft[1], $bottomRight[0], $bottomRight[1], $hGUI, $hGDC, $hMDC, $hGFX, $hPen) EndIf EndIf ElseIf $isDragging Then ; Left mouse button is released $isDragging = False ConsoleWrite($topLeft[0] & " " & $topLeft[1] & " " & $bottomRight[0] & " " & $bottomRight[1] & @LF) ExitLoop EndIf WEnd EndFunc ;==>StartMouseTracking Func DrawRectangle(ByRef $x1, ByRef $y1, ByRef $x2, ByRef $y2, ByRef $hGUI, ByRef $hGDC, ByRef $hMDC, ByRef $hGFX, ByRef $hPen) _GDIPlus_GraphicsClear($hGFX, 0x00000000) ; Clear with transparent background _GDIPlus_GraphicsDrawRect($hGFX, $x1, $y1, $x2 - $x1, $y2 - $y1, $hPen) DllCall("user32.dll", "bool", "UpdateLayeredWindow", "hwnd", $hGUI, "handle", $hGDC, "struct*", $tPDst, "struct*", $tSize, "handle", $hMDC, "struct*", $tPSrc, "dword", 0, "struct*", $tBlnd, "dword", 0x02) ; FAST _WinAPI_UpdateLayeredWindow $ULW_ALPHA = 0x02 EndFunc ;==>DrawRectangle Func End() _GDIPlus_PenDispose($hPen) ; Cleanup pen _GDIPlus_GraphicsDispose($hGFX) ; Cleanup graphics object _WinAPI_ReleaseDC($hGUI, $hGDC) ; Release device context _WinAPI_SelectObject($hMDC, $hOld) ; Restore the old object _WinAPI_DeleteObject($hBit) ; Delete the bitmap _WinAPI_DeleteDC($hMDC) ; Delete the memory device context _GDIPlus_Shutdown() ; Shutdown GDI+ GUIDelete($hGUI) ; Delete overlay window Exit EndFunc ;==>End @ioa747 Thanks man for the inspiration!1 point
-
Here is a collection of small examples. Windows Explorer should be open before you run the examples. If you create shortcuts for the scripts, and copy the shortcuts to the desktop, you can run the examples and use Windows Explorer at the same time. For some of the examples you can select files or folders before you run the example. 1) GetCurrentFolder.au3 #include "Includes\AutomatingWindowsExplorer.au3" Opt( "MustDeclareVars", 1 ) Example() Func Example() ; Windows Explorer on XP, Vista, 7, 8 Local $hExplorer = WinGetHandle( "[REGEXPCLASS:^(Cabinet|Explore)WClass$]" ) If Not $hExplorer Then MsgBox( 0, "Automating Windows Explorer", "Could not find Windows Explorer. Terminating." ) Return EndIf ; Get an IShellBrowser interface GetIShellBrowser( $hExplorer ) If Not IsObj( $oIShellBrowser ) Then MsgBox( 0, "Automating Windows Explorer", "Could not get an IShellBrowser interface. Terminating." ) Return EndIf ; Get other interfaces GetShellInterfaces() ; Get current folder Local $pFolder = GetCurrentFolder(), $sFolder SHGetPathFromIDList( $pFolder, $sFolder ) MsgBox( 0, "Folder", $sFolder ) ; Free memory _WinAPI_CoTaskMemFree( $pFolder ) EndFunc 2) SetCurrentFolder.au3 #include "Includes\AutomatingWindowsExplorer.au3" Opt( "MustDeclareVars", 1 ) Example() Func Example() ; Windows Explorer on XP, Vista, 7, 8 Local $hExplorer = WinGetHandle( "[REGEXPCLASS:^(Cabinet|Explore)WClass$]" ) If Not $hExplorer Then MsgBox( 0, "Automating Windows Explorer", "Could not find Windows Explorer. Terminating." ) Return EndIf ; Get an IShellBrowser interface GetIShellBrowser( $hExplorer ) If Not IsObj( $oIShellBrowser ) Then MsgBox( 0, "Automating Windows Explorer", "Could not get an IShellBrowser interface. Terminating." ) Return EndIf ; Get other interfaces GetShellInterfaces() ; Set current folder to desktop Local $pDesktop = _WinAPI_ShellGetSpecialFolderLocation( $CSIDL_DESKTOP ) SetCurrentFolder( $pDesktop, $SBSP_ABSOLUTE ) ; Free memory _WinAPI_CoTaskMemFree( $pDesktop ) EndFunc 3) CountItems.au3 #include "Includes\AutomatingWindowsExplorer.au3" Opt( "MustDeclareVars", 1 ) Example() Func Example() ; Windows Explorer on XP, Vista, 7, 8 Local $hExplorer = WinGetHandle( "[REGEXPCLASS:^(Cabinet|Explore)WClass$]" ) If Not $hExplorer Then MsgBox( 0, "Automating Windows Explorer", "Could not find Windows Explorer. Terminating." ) Return EndIf ; Get an IShellBrowser interface GetIShellBrowser( $hExplorer ) If Not IsObj( $oIShellBrowser ) Then MsgBox( 0, "Automating Windows Explorer", "Could not get an IShellBrowser interface. Terminating." ) Return EndIf ; Get other interfaces GetShellInterfaces() ; Count files and folders MsgBox( 0, "Count files and folders", CountItems() ) ; Count selected files and folders MsgBox( 0, "Count selected files and folders", CountItems( True ) ) EndFunc 4) GetFiles.au3 #include "Includes\AutomatingWindowsExplorer.au3" #include <Array.au3> Opt( "MustDeclareVars", 1 ) Example() Func Example() ; Windows Explorer on XP, Vista, 7, 8 Local $hExplorer = WinGetHandle( "[REGEXPCLASS:^(Cabinet|Explore)WClass$]" ) If Not $hExplorer Then MsgBox( 0, "Automating Windows Explorer", "Could not find Windows Explorer. Terminating." ) Return EndIf ; Get an IShellBrowser interface GetIShellBrowser( $hExplorer ) If Not IsObj( $oIShellBrowser ) Then MsgBox( 0, "Automating Windows Explorer", "Could not get an IShellBrowser interface. Terminating." ) Return EndIf ; Get other interfaces GetShellInterfaces() ; Get all files with full path ;GetFiles( $fSelected = False, $fFullPath = False, $fPidl = False, $iMax = 0 ) Local $aFiles = GetFiles( False, True ) _ArrayDisplay( $aFiles, "All files" ) ; Get selected files with full path ;GetFiles( $fSelected = False, $fFullPath = False, $fPidl = False, $iMax = 0 ) $aFiles = GetFiles( True, True ) _ArrayDisplay( $aFiles, "Selected files" ) EndFunc 5) GetFolders.au3 #include "Includes\AutomatingWindowsExplorer.au3" #include <Array.au3> Opt( "MustDeclareVars", 1 ) Example() Func Example() ; Windows Explorer on XP, Vista, 7, 8 Local $hExplorer = WinGetHandle( "[REGEXPCLASS:^(Cabinet|Explore)WClass$]" ) If Not $hExplorer Then MsgBox( 0, "Automating Windows Explorer", "Could not find Windows Explorer. Terminating." ) Return EndIf ; Get an IShellBrowser interface GetIShellBrowser( $hExplorer ) If Not IsObj( $oIShellBrowser ) Then MsgBox( 0, "Automating Windows Explorer", "Could not get an IShellBrowser interface. Terminating." ) Return EndIf ; Get other interfaces GetShellInterfaces() ; Get all folders ;GetFolders( $fSelected = False, $fFullPath = False, $fPidl = False, $iMax = 0 ) Local $aFolders = GetFolders() _ArrayDisplay( $aFolders, "All folders" ) ; Get selected folders ;GetFolders( $fSelected = False, $fFullPath = False, $fPidl = False, $iMax = 0 ) $aFolders = GetFolders( True ) _ArrayDisplay( $aFolders, "Selected folders" ) EndFunc 6) SetSelectedItem.au3 #include "Includes\AutomatingWindowsExplorer.au3" Opt( "MustDeclareVars", 1 ) Example() Func Example() ; Windows Explorer on XP, Vista, 7, 8 Local $hExplorer = WinGetHandle( "[REGEXPCLASS:^(Cabinet|Explore)WClass$]" ) If Not $hExplorer Then MsgBox( 0, "Automating Windows Explorer", "Could not find Windows Explorer. Terminating." ) Return EndIf ; Get an IShellBrowser interface GetIShellBrowser( $hExplorer ) If Not IsObj( $oIShellBrowser ) Then MsgBox( 0, "Automating Windows Explorer", "Could not get an IShellBrowser interface. Terminating." ) Return EndIf ; Get other interfaces GetShellInterfaces() ; Set second item selected SetSelectedItem( 1 ) EndFunc 7) GetSetIconView.au3 #include "Includes\AutomatingWindowsExplorer.au3" Opt( "MustDeclareVars", 1 ) Example() Func Example() ; Windows Explorer on XP, Vista, 7, 8 Local $hExplorer = WinGetHandle( "[REGEXPCLASS:^(Cabinet|Explore)WClass$]" ) If Not $hExplorer Then MsgBox( 0, "Automating Windows Explorer", "Could not find Windows Explorer. Terminating." ) Return EndIf ; Get an IShellBrowser interface GetIShellBrowser( $hExplorer ) If Not IsObj( $oIShellBrowser ) Then MsgBox( 0, "Automating Windows Explorer", "Could not get an IShellBrowser interface. Terminating." ) Return EndIf ; Get other interfaces GetShellInterfaces() ; Get current icon view Local $view = GetIconView() Local $iView, $iSize If IsArray( $view ) Then ; OS > XP $iView = $view[0] ; Icon view $iSize = $view[1] ; Icon size If $iView <> $FVM_DETAILS Then ; Not details view SetIconView( $FVM_DETAILS, 16 ) ; Set details view ElseIf $iView <> $FVM_ICON Then ; Not icon view SetIconView( $FVM_ICON, 48 ) ; Set icon view EndIf Sleep( 3000 ) ; Wait 3 seconds SetIconView( $iView, $iSize ) ; Restore old view Else ; OS = XP $iView = $view If $iView <> $FVM_DETAILS Then ; Not details view SetIconView( $FVM_DETAILS ) ; Set details view ElseIf $iView <> $FVM_ICON Then ; Not icon view SetIconView( $FVM_ICON ) ; Set icon view EndIf Sleep( 3000 ) ; Wait 3 seconds SetIconView( $iView ) ; Restore old view EndIf EndFunc Zipfile The zip contains examples and necessary include files. Examples.7z1 point