FWIW, I felt that the tool (mentioned above) would be kind of fun to make, so there you go :
#include <WinAPISysWin.au3>
#include <WinAPISys.au3>
#include <WinAPIConstants.au3>
#include <WindowsConstants.au3>
#include <Misc.au3>
#include <GuiMenu.au3>
#include <GUIConstants.au3>
#include <ColorConstants.au3>
Opt("MustDeclareVars", True)
Global Const $tagTITLEBARINFOEX = "int cbSize;" & $tagRECT & ";dword rgstate[6];dword rgrect[24]"
Global $bRight, $hMSHook, $hMSProc, $hWnd
If Not _Singleton("AutoIt SetOnTop Tool", 1) Then Exit MsgBox($MB_OK, "Error", "Tool already loaded")
HotKeySet("{END}", Terminate)
Example()
Func Example()
$hMSProc = DllCallbackRegister(MouseProc, "long", "int;wparam;lparam")
$hMSHook = _WinAPI_SetWindowsHookEx($WH_MOUSE_LL, DllCallbackGetPtr($hMSProc), _WinAPI_GetModuleHandle(0))
OnAutoItExitRegister(CleanUP)
While Sleep(100)
If $bRight Then
$bRight = False
ToggleSetOnTop()
EndIf
WEnd
EndFunc ;==>Example
Func MouseProc($nCode, $wParam, $lParam)
If $nCode < 0 Then Return _WinAPI_CallNextHookEx($hMSHook, $nCode, $wParam, $lParam)
If ($wParam = $WM_RBUTTONDOWN Or $wParam = $WM_RBUTTONUP) And _IsPressed("11") Then
$hWnd = GetWindow()
If $hWnd Then
$bRight = $wParam = $WM_RBUTTONUP
Return 1
EndIf
EndIf
Return _WinAPI_CallNextHookEx($hMSHook, $nCode, $wParam, $lParam)
EndFunc ;==>MouseProc
Func ToggleSetOnTop()
Local $iTop = BitAND(_WinAPI_GetWindowLong($hWnd, $GWL_EXSTYLE), $WS_EX_TOPMOST)
Local $aPos = MouseGetPos()
Local $hGUI = GUICreate("", 200, 32, $aPos[0], $aPos[1], $WS_POPUP, $WS_EX_TOOLWINDOW + $WS_EX_TOPMOST)
GUISetBkColor(0xD0D0D0)
Local $idLabel = GUICtrlCreateLabel($iTop ? "Topmost OFF" : "Topmost ON", 0, 0, 200, 32, $SS_CENTERIMAGE + $SS_CENTER)
GUICtrlSetFont(-1, 18, Default, Default, "Arial")
GUICtrlSetColor(-1, $iTop ? $COLOR_RED : $COLOR_GREEN)
GUISetState()
While WinActive($hGUI)
Switch GUIGetMsg()
Case $GUI_EVENT_CLOSE
ExitLoop
Case $idLabel
WinSetOnTop($hWnd, "", $iTop ? $WINDOWS_NOONTOP : $WINDOWS_ONTOP)
ExitLoop
EndSwitch
WEnd
GUIDelete()
EndFunc ;==>ToggleSetOnTop
Func CleanUP()
_WinAPI_UnhookWindowsHookEx($hMSHook)
DllCallbackFree($hMSProc)
EndFunc ;==>CleanUP
Func Terminate()
Exit
EndFunc ;==>Terminate
Func GetWindow()
Local Static $tPoint = DllStructCreate($tagPOINT)
Local Static $tTITLEBARINFOEX = DllStructCreate($tagTITLEBARINFOEX)
DllStructSetData($tTITLEBARINFOEX, "cbSize", DllStructGetSize($tTITLEBARINFOEX))
$tPoint.X = MouseGetPos(0)
$tPoint.Y = MouseGetPos(1)
Local $hWin = _WinAPI_GetAncestor(_WinAPI_WindowFromPoint($tPoint), $GA_ROOT)
_SendMessage($hWin, $WM_GETTITLEBARINFOEX, 0, DllStructGetPtr($tTITLEBARINFOEX))
If $tTITLEBARINFOEX.top + $tTITLEBARINFOEX.bottom + $tTITLEBARINFOEX.left + $tTITLEBARINFOEX.right = 0 Then Return 0
If $tTITLEBARINFOEX.bottom <= $tTITLEBARINFOEX.top Then $tTITLEBARINFOEX.bottom = $tTITLEBARINFOEX.top + 35
If $tPoint.X >= $tTITLEBARINFOEX.left And $tPoint.X <= $tTITLEBARINFOEX.right And $tPoint.Y >= $tTITLEBARINFOEX.top And $tPoint.Y <= $tTITLEBARINFOEX.bottom Then
Return $hWin
EndIf
Return 0
EndFunc ;==>GetWindow
Latest version : 2025-02-01 07:01