qwert

How to determine if Program Manager has focus?

8 posts in this topic

I need a way to determine if the desktop is "up" ... like after the user clicks Show Desktop.

Autoit Window Info detects it correctly, but my script steps produce a blank result.  (Other windows are correctly reported.)

$sTitle = WinGetTitle("[active]")
MsgBox (0, "", $sTitle, 0)

Any suggestion will be appreciated.

 

None.thumb.PNG.1e7dcbfc6032ec74f624fd4e3

Detect_PMgr.thumb.PNG.433e16f775f38214c8

 

 

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Works fine when Program Manager is actually active.

WinActivate("Program Manager")

$sTitle = WinGetHandle("[ACTIVE]")
ConsoleWrite(WinGetTitle($sTitle) & @LF)

You'll probably find that the title-less window you got belongs to explorer.exe

Possible that this might get you started.

#include <Process.au3>

MsgBox(0,"Desktop visible",_DesktopOnTop())

Func _DesktopOnTop()
    $sTitle = WinGetTitle("(ACTIVE]")
    $sPName = _ProcessGetName(WinGetProcess(WinGetHandle("[ACTIVE]")))
    If ($sTitle = "" And $sPName = "explorer.exe") Or ($sTitle = "Program Manager") Then
        Return True
    EndIf
    Return False
EndFunc   ;==>_DesktopOnTop

 

Edited by JohnOne

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

If I understand, this could work :

#include <WinAPISys.au3>
MsgBox(0, "", "Desktop is active ?" & @CRLF & _DesktopActive() )

Func _DesktopActive()
    Return ( WinGetHandle("[ACTIVE]") = _WinAPI_GetShellWindow() )
EndFunc

Or this :

#include <WinAPISys.au3>

MsgBox(0, "", "Desktop is active ?" & @CRLF & _DesktopActive() )

Func _DesktopActive()
    Return ( BitAND( WinGetState( _WinAPI_GetShellWindow() ), 8 ) <> 0 )
    ; Return (WinActive( _WinAPI_GetShellWindow()) > 0) ; Or this
EndFunc

 

 

 

Edited by jguinch

Share this post


Link to post
Share on other sites

@JohnOne:  Yes, the combination of the two checks seems to be the answer ... although I haven't tested a lot of cases.  Thanks for the suggestion.

$sTitle = WinGetTitle("(ACTIVE]")
    $sPName = _ProcessGetName(WinGetProcess(WinGetHandle("[ACTIVE]")))

@jguinch:  It seems that those methods should work, but I can't make them do so.  Before calling _DesktopActive(), I place the cursor in the center of the desktop and left click once to make sure it's active ... but the function always returns False.

Thanks for both responses.

 

 

 

 

Share this post


Link to post
Share on other sites

Windows 7 Professional.  But I also have access to Win 8.1 and Win10.

 

 

Share this post


Link to post
Share on other sites

Indeed, they do work.  My test program was cycling through each method and the MSG from the first test was taking focus away from the desktop ... which caused the next method to fail.

Sorry 'bout that.

 

 

Share this post


Link to post
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