Jump to content

How to check if GUI window is behind other window?


VAN0
 Share

Recommended Posts

Hello.

Is there a way check if an opened window is actually visible on screen and not behind other window?

WinGetState always returns 7 (Window is visible)

Any tricks available for this? For example a way get z-index (css definition) of all opened windows or something in that nature?

Thank you.

Link to comment
Share on other sites

Look at WinActive(Checks to see if a specified window exists and is currently active)in help.........

#include <MsgBoxConstants.au3>

If WinActive("[CLASS:Notepad]") Then ; Check if Notepad is currently active.
    MsgBox($MB_SYSTEMMODAL, "", "WinActive" & @CRLF & "Notepad is active.")
Else
    MsgBox($MB_SYSTEMMODAL, "", "WinActive" & @CRLF & "Notepad is not active.")
EndIf

Life is like a coin. You can spend it Anyway as you wish and for your kind information. "you can spend it only once."

Link to comment
Share on other sites

Thank you.

z-index of WinList didn't work because top-most window are always first.

WinActive won't work in my case, because I didn't mention how I'm gonna use it:

I need change option name in tray content menu.

So when you right click on tray menu taskbar become active at that moment.

So far I managed to make it work by using WM_SHELLHOOK

Opt("TrayOnEventMode", 1)
Opt("TrayMenuMode", 8 + 4 + 2 + 1)

#include<WinAPIEx.au3>
#include<TrayConstants.au3>
#include <GUIConstantsEx.au3>
Global $hGUI = GUICreate("test")
Global $gFocusedHwnd = $hGUI, $gFocusedPrevHwnd = $hGUI

$tToggle = TrayCreateItem("Show")
TrayItemSetOnEvent(-1, "ShowHide")
TrayCreateItem("")
$tExit = TrayCreateItem("Exit")
TrayItemSetOnEvent(-1, "ExitScript")
TraySetClick(16)
TraySetState($TRAY_ICONSTATE_SHOW)

TraySetOnEvent($TRAY_EVENT_PRIMARYUP, "ShowHide")
TraySetOnEvent($TRAY_EVENT_SECONDARYDOWN, "TrayMenu")

GUIRegisterMsg(_WinAPI_RegisterWindowMessage('SHELLHOOK'), 'WM_SHELLHOOK') ; Define a window message and assign to the WM_SHELLHOOK function.
_WinAPI_RegisterShellHookWindow($hGUI) ; Register the shell hook message to our GUI.
GUISetState()

While 1
    $msg = GUIGetMsg()
    Switch $msg
        Case $GUI_EVENT_CLOSE
            ExitScript()
    EndSwitch
WEnd

Func WM_SHELLHOOK($hWnd, $iMsg, $wParam, $lParam)
    If $wParam = $HSHELL_WINDOWACTIVATED Or $wParam = $HSHELL_RUDEAPPACTIVATED  Then
        If $gFocusedHwnd <> $lParam Then

            If $gFocusedPrevHwnd <> $gFocusedHwnd Then $gFocusedPrevHwnd = $gFocusedHwnd
            $gFocusedHwnd = $lParam
        EndIf
    EndIf
EndFunc   ;==>WM_SHELLHOOK

Func TrayMenu()
    If $hGUI = $gFocusedPrevHwnd And BitAND(WinGetState($hGUI), 2) Then
        TrayItemSetText($tToggle, "Hide")
    Else
        TrayItemSetText($tToggle, "Show")
    EndIf
EndFunc

Func ShowHide()
    If $hGUI = $gFocusedPrevHwnd And BitAND(WinGetState($hGUI), 2) Then
        GUISetState(@SW_HIDE, $hGUI)
        $gFocusedPrevHwnd = 0
    Else
        GUISetState(@SW_SHOWNORMAL, $hGUI)
        WinActivate($hGUI)
        $gFocusedPrevHwnd = $hGUI
    EndIf
EndFunc

Func ExitScript()
    _WinAPI_DeregisterShellHookWindow($hGUI)
    Exit
EndFunc
Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...