Hypertrophy Posted June 24, 2009 Share Posted June 24, 2009 Would the following code get the currently active windows handle? expandcollapse popup $state = WinGetState("", "") If BitAnd($state, 8) Then $handle=WinGetHandle($state) EndIf Link to comment Share on other sites More sharing options... Richard Robertson Posted June 24, 2009 Richard Robertson Active Members 10.2k 3 Share Posted June 24, 2009 WinGetHandle("") will return the active window's handle. Xandy 1 Link to comment Share on other sites More sharing options... Hypertrophy Posted June 24, 2009 Hypertrophy Active Members 330 Author Share Posted June 24, 2009 (edited) I've been trying to tweak this code so it will put a red border around whatever window is active. Credits to MrCreator, martin; and Melba for his further tweakage.#include <GuiConstantsEx.au3> #include <WindowsConstants.au3> #include <WinAPI.au3> Opt("GuiOnEventMode", 1) HotKeySet("{ESC}", "QuitApp") If Not IsDeclared("WM_WINDOWPOSCHANGED") Then Assign("WM_WINDOWPOSCHANGED",0x0047) Global $ahGUI[4] Global $Frame_Color = 0xFF0000 Global $Frame_Width = 2 $Main_GUI = GuiCreate("Highlight Window Demo") GUISetOnEvent($GUI_EVENT_CLOSE, "QuitApp") GUIRegisterMsg($WM_WINDOWPOSCHANGED, "WM_WINDOWPOSCHANGED") GUISetState() Global $fSquare = False While 1 Sleep(100) $handle = WinGetHandle("") If BitAND(WinGetState($handle), 8) Then If $fSquare = False Then ; Get window data $aWin = WinGetPos($handle) ; X Y $iBorder = _WinAPI_GetSystemMetrics(8); Border width $iBar = _WinAPI_GetSystemMetrics(4); Title bar height ; Get Client area size $aCA = WinGetClientSize($handle); Width, height GUICreateSquare($aWin[0] + $iBorder, $aWin[1] + $iBar + $iBorder, $aCA[0], $aCA[1]) WinActivate($handle) EndIf Else If $fSquare = True Then GUISquareDelete() EndIf WEnd Func GUICreateSquare($X, $Y, $W, $H) $X -= $Frame_Width $Y -= $Frame_Width $W += $Frame_Width $H += $Frame_Width $ahGUI[0] = GUICreate("", $W, $Frame_Width, $X, $Y, $WS_POPUP, $WS_EX_TOPMOST+$WS_EX_TOOLWINDOW) GUISetBkColor($Frame_Color) $ahGUI[1] = GUICreate("", $Frame_Width, $H, $X, $Y, $WS_POPUP, $WS_EX_TOPMOST+$WS_EX_TOOLWINDOW) GUISetBkColor($Frame_Color) $ahGUI[2] = GUICreate("", $Frame_Width, $H, $X+$W, $Y, $WS_POPUP, $WS_EX_TOPMOST+$WS_EX_TOOLWINDOW) GUISetBkColor($Frame_Color) $ahGUI[3] = GUICreate("", $W+$Frame_Width, $Frame_Width, $X, $Y+$H, $WS_POPUP, $WS_EX_TOPMOST+$WS_EX_TOOLWINDOW) GUISetBkColor($Frame_Color) For $i = 0 To 3 GUISetState(@SW_SHOW, $ahGUI[$i]) Next $fSquare = True EndFunc Func GUISquareDelete() For $i = 0 To 3 If IsHWnd($ahGUI[$i]) And $ahGUI[$i] <> $Main_GUI Then GUIDelete($ahGUI[$i]) Next $ahGUI = "" Dim $ahGUI[4] $fSquare = False EndFunc Func WM_WINDOWPOSCHANGED($hWnd, $MsgID, $WParam, $LParam) If $hWnd = $Main_GUI Then GUISquareDelete() Else Return $GUI_RUNDEFMSG EndIf EndFunc Func QuitApp() Exit EndFunc Edited June 24, 2009 by coder09 Link to comment Share on other sites More sharing options...
Richard Robertson Posted June 24, 2009 Share Posted June 24, 2009 $handle = WinGetHandle("") If BitAND(WinGetState($handle), 8) Then This is pointless. WinGetHandle("") always returns the active window's handle. There's no need to waste time getting the state of the window. Also, the way you have it set up, it's going to create and destroy those windows 10 times a second. That's a huge waste of resources. What you need to do is resize/relocate the windows already used to match the new window. Link to comment Share on other sites More sharing options...
Hypertrophy Posted June 24, 2009 Author Share Posted June 24, 2009 (edited) Thanks brah for not helping me on my actual problem and telling me to change something that I didn't write. Edited June 24, 2009 by coder09 Link to comment Share on other sites More sharing options...
Richard Robertson Posted June 24, 2009 Share Posted June 24, 2009 I did help. I told you what needed to be changed. Help does not mean "rewrite it for me". Link to comment Share on other sites More sharing options...
Hypertrophy Posted June 24, 2009 Author Share Posted June 24, 2009 I don't want you to re-write it for me. Whether you think its wasting resources or not it works fine therefore should be left alone. Link to comment Share on other sites More sharing options...
Richard Robertson Posted June 24, 2009 Share Posted June 24, 2009 If it works, what are you asking for? Link to comment Share on other sites More sharing options...
Hypertrophy Posted June 24, 2009 Author Share Posted June 24, 2009 No it doesn't work with what I'm trying to do. It works in its original form. Link to comment Share on other sites More sharing options...
MDCT Posted June 25, 2009 Share Posted June 25, 2009 No it doesn't work with what I'm trying to do. It works in its original form. I moded your code, try this: expandcollapse popup#include <GuiConstantsEx.au3> #include <WindowsConstants.au3> #include <WinAPI.au3> Opt("GuiOnEventMode", 1) HotKeySet("{ESC}", "QuitApp") Global $ahGUI[4] Global $Frame_Color = 0xFF0000 Global $Frame_Width = 2 $Main_GUI = GuiCreate("Highlight Window Demo") GUISetOnEvent($GUI_EVENT_CLOSE, "QuitApp") GUISetState() Global $fSquare = False Global $handle = 0 While 1 Sleep(100) if WinGetHandle("") <> $handle Then if $fSquare = True then GUISquareDelete() $handle = WinGetHandle("") $aWin = WinGetPos($handle) ; X Y $iBorder = _WinAPI_GetSystemMetrics(8); Border width $iBar = _WinAPI_GetSystemMetrics(4); Title bar height ; Get Client area size $aCA = WinGetClientSize($handle); Width, height GUICreateSquare($aWin[0] + $iBorder, $aWin[1] + $iBar + $iBorder, $aCA[0], $aCA[1]) WinActivate($handle) Else $aWin2 = WinGetPos($handle) if $aWin[0] <> $aWin2[0] and $aWin[1] <> $aWin2[1] Then GUISquareDelete() $fSquare = True $aWin = WinGetPos($handle) ; X Y $iBorder = _WinAPI_GetSystemMetrics(8); Border width $iBar = _WinAPI_GetSystemMetrics(4); Title bar height ; Get Client area size $aCA = WinGetClientSize($handle); Width, height GUICreateSquare($aWin[0] + $iBorder, $aWin[1] + $iBar + $iBorder, $aCA[0], $aCA[1]) WinActivate($handle) EndIf Sleep(150) EndIf WEnd exit If BitAND(WinGetState($handle), 8) Then tooltip(_WinAPI_GetClassName($handle),0,0) If $fSquare = False Then ; Get window data $aWin = WinGetPos($handle) ; X Y $iBorder = _WinAPI_GetSystemMetrics(8); Border width $iBar = _WinAPI_GetSystemMetrics(4); Title bar height ; Get Client area size $aCA = WinGetClientSize($handle); Width, height GUICreateSquare($aWin[0] + $iBorder, $aWin[1] + $iBar + $iBorder, $aCA[0], $aCA[1]) WinActivate($handle) EndIf Else If $fSquare = True Then GUISquareDelete() EndIf Func GUICreateSquare($X, $Y, $W, $H) $X -= $Frame_Width $Y -= $Frame_Width $W += $Frame_Width $H += $Frame_Width $ahGUI[0] = GUICreate("", $W, $Frame_Width, $X, $Y, $WS_POPUP, $WS_EX_TOPMOST+$WS_EX_TOOLWINDOW) GUISetBkColor($Frame_Color) $ahGUI[1] = GUICreate("", $Frame_Width, $H, $X, $Y, $WS_POPUP, $WS_EX_TOPMOST+$WS_EX_TOOLWINDOW) GUISetBkColor($Frame_Color) $ahGUI[2] = GUICreate("", $Frame_Width, $H, $X+$W, $Y, $WS_POPUP, $WS_EX_TOPMOST+$WS_EX_TOOLWINDOW) GUISetBkColor($Frame_Color) $ahGUI[3] = GUICreate("", $W+$Frame_Width, $Frame_Width, $X, $Y+$H, $WS_POPUP, $WS_EX_TOPMOST+$WS_EX_TOOLWINDOW) GUISetBkColor($Frame_Color) For $i = 0 To 3 GUISetState(@SW_SHOW, $ahGUI[$i]) Next $fSquare = True EndFunc Func GUISquareDelete() For $i = 0 To 3 If IsHWnd($ahGUI[$i]) And $ahGUI[$i] <> $Main_GUI Then GUIDelete($ahGUI[$i]) Next $ahGUI = "" Dim $ahGUI[4] $fSquare = False EndFunc Func QuitApp() Exit EndFunc It works by checking if the active window is changed. I believe your code won't work because it cannot detect if there's change in active window. And it is true that "If BitAND(WinGetState($handle), 8) Then" is not necessary as the active window will give the same result. And one more thing, WM_WINDOWPOSCHANGED here cannot be used on all windows. Hope this helps. Link to comment Share on other sites More sharing options...
Hypertrophy Posted June 25, 2009 Author Share Posted June 25, 2009 MDCT: your code works well except when i try to move the currently active window that has the red border around it, I can't move the window constantly. it like freezes at certain points and i have to release it and move it again. (this doesn't happen with the main gui) Link to comment Share on other sites More sharing options...
MDCT Posted June 26, 2009 Share Posted June 26, 2009 MDCT: your code works well except when i try to move the currently active window that has the red border around it, I can't move the window constantly. it like freezes at certain points and i have to release it and move it again. (this doesn't happen with the main gui)I set the condition of the mousepos with AND, instead OR. Otherwise, you would have problem with moving window as it always recreates the border and reactivate the window. Here, I've changed some in the code, it should work with no problem. expandcollapse popup#include <GuiConstantsEx.au3> #include <WindowsConstants.au3> #include <WinAPI.au3> Opt("GuiOnEventMode", 1) HotKeySet("{ESC}", "QuitApp") Global $ahGUI[4] Global $Frame_Color = 0xFF0000 Global $Frame_Width = 2 $Main_GUI = GuiCreate("Highlight Window Demo") GUISetOnEvent($GUI_EVENT_CLOSE, "QuitApp") GUISetState() Global $fSquare = False Global $handle = 0 While 1 Sleep(50) if WinGetHandle("") <> $handle Then if $fSquare = True then GUISquareDelete() Sleep(24) $handle = WinGetHandle("") $aWin = WinGetPos($handle) ; X Y $iBorder = _WinAPI_GetSystemMetrics(8); Border width $iBar = _WinAPI_GetSystemMetrics(4); Title bar height ; Get Client area size $aCA = WinGetClientSize($handle); Width, height GUICreateSquare($aWin[0] + $iBorder, $aWin[1] + $iBar + $iBorder, $aCA[0], $aCA[1]) Sleep(24) Else Sleep(50) $aWin2 = WinGetPos($handle) if $aWin[0] <> $aWin2[0] or $aWin[1] <> $aWin2[1] Then GUISquareDelete() Sleep(24) $fSquare = True $aWin = WinGetPos($handle) ; X Y $iBorder = _WinAPI_GetSystemMetrics(8); Border width $iBar = _WinAPI_GetSystemMetrics(4); Title bar height ; Get Client area size $aCA = WinGetClientSize($handle); Width, height GUICreateSquare($aWin[0] + $iBorder, $aWin[1] + $iBar + $iBorder, $aCA[0], $aCA[1]) Sleep(24) EndIf Sleep(50) EndIf Sleep(50) WEnd exit If BitAND(WinGetState($handle), 8) Then tooltip(_WinAPI_GetClassName($handle),0,0) If $fSquare = False Then ; Get window data $aWin = WinGetPos($handle) ; X Y $iBorder = _WinAPI_GetSystemMetrics(8); Border width $iBar = _WinAPI_GetSystemMetrics(4); Title bar height ; Get Client area size $aCA = WinGetClientSize($handle); Width, height GUICreateSquare($aWin[0] + $iBorder, $aWin[1] + $iBar + $iBorder, $aCA[0], $aCA[1]) WinActivate($handle) EndIf Else If $fSquare = True Then GUISquareDelete() EndIf Func GUICreateSquare($X, $Y, $W, $H) $X -= $Frame_Width $Y -= $Frame_Width $W += $Frame_Width $H += $Frame_Width $ahGUI[0] = GUICreate("", $W, $Frame_Width, $X, $Y, $WS_POPUP, $WS_EX_TOPMOST+$WS_EX_TOOLWINDOW) GUISetBkColor($Frame_Color) $ahGUI[1] = GUICreate("", $Frame_Width, $H, $X, $Y, $WS_POPUP, $WS_EX_TOPMOST+$WS_EX_TOOLWINDOW) GUISetBkColor($Frame_Color) $ahGUI[2] = GUICreate("", $Frame_Width, $H, $X+$W, $Y, $WS_POPUP, $WS_EX_TOPMOST+$WS_EX_TOOLWINDOW) GUISetBkColor($Frame_Color) $ahGUI[3] = GUICreate("", $W+$Frame_Width, $Frame_Width, $X, $Y+$H, $WS_POPUP, $WS_EX_TOPMOST+$WS_EX_TOOLWINDOW) GUISetBkColor($Frame_Color) For $i = 0 To 3 GUISetState(@SW_SHOWNOACTIVATE, $ahGUI[$i]) Next $fSquare = True EndFunc Func GUISquareDelete() For $i = 0 To 3 If IsHWnd($ahGUI[$i]) And $ahGUI[$i] <> $Main_GUI Then GUIDelete($ahGUI[$i]) Next $ahGUI = "" Dim $ahGUI[4] $fSquare = False EndFunc Func QuitApp() Exit EndFunc Link to comment Share on other sites More sharing options...
Hypertrophy Posted June 26, 2009 Author Share Posted June 26, 2009 Thank you this is perfect. Link to comment Share on other sites More sharing options...
MDCT Posted June 26, 2009 Share Posted June 26, 2009 Thank you this is perfect.I think you need to add some sleep commands here and there. It might lower the responsiveness, but it helps your CPU. 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