Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

WinWaitAnyNewWindow


  • Please log in to reply
13 replies to this topic
OrelseIamfired
  • Members
  • 65 posts
  • Last active: Jan 10 2013 01:18 AM
  • Joined: 13 Mar 2006
Hi,

Is there an easy way to wait for any new window that opens? This way I can wait for a window, see which one it is, then act on it appropriately.

/ Louis

FGR
  • Guests
  • Last active:
  • Joined: --
You can try "WinGet" command to retrieve a list of windows(ID)

SKAN
  • Administrators
  • 9115 posts
  • Last active:
  • Joined: 26 Dec 2005
This is somewhat related: <!-- m -->http://www.autohotke... ... 323#123323<!-- m -->

:)

Lexikos
  • Administrators
  • 9844 posts
  • AutoHotkey Foundation
  • Last active:
  • Joined: 17 Oct 2006
If you need to detect when a window is created, you can use a shell hook (as in the post Skan linked to) or SetWinEventHook().

If you want to detect when the active window changes, it's much easier:
WinWaitNotActive, % "ahk_id " WinActive("A")
Also, I found a way to detect when a hidden window becomes active... :lol:
WinWaitNotActive, A


OrelseIamfired
  • Members
  • 65 posts
  • Last active: Jan 10 2013 01:18 AM
  • Joined: 13 Mar 2006
FGR, Skan, and lexikos,

Thank you for your useful responses.

Wow, Skan, that is impressive. On first glance, it looks a little heavy for me, so I shall take some time to study it.

Regards to all,
/ Louis

SKAN
  • Administrators
  • 9115 posts
  • Last active:
  • Joined: 26 Dec 2005

On first glance, it looks a little heavy for me


Not at all. The following is an excerpt from my always running script.

Gui +LastFound 
hWnd := WinExist() 

DllCall( "RegisterShellHookWindow", UInt,hWnd ) 
MsgNum := DllCall( "RegisterWindowMessage", Str,"SHELLHOOK" ) 
OnMessage( MsgNum, "ShellMessage" ) 

Return ;                                                 // End of Auto-Execute Section // 

ShellMessage( wParam,lParam ) { 
If ( wParam = 1 ) 
 {
       WinGetTitle, Title, ahk_id %lParam%

       If ( Title="Apcupsd message" ) 
           PostMessage, 0x112, 0xF060,,,ahk_id %lParam%

       If ( Title="Automatic Updates" ) 
            PostMessage, 0x112, 0xF060,,,ahk_id %lParam%
}}

Windows nags me every 5 minutes to restart ( after an Automatic Update ) and my UPS throws an msgbox in case of a power failure.
The above code automatically disposes them, at creation level.

:)

OrelseIamfired
  • Members
  • 65 posts
  • Last active: Jan 10 2013 01:18 AM
  • Joined: 13 Mar 2006
Hi lexiKos,

If you need to detect when a window is created, you can use a shell hook (as in the post Skan linked to) or SetWinEventHook().


Have you already used DllCall to call that SetWinEventHook() function?

I ask because I do not know how to specify the fourth parameter of SetWinEventHook() in the DllCall(). It is of type WINEVENTPROC.

WINEVENTPROC lpfnWinEventProc

/ Louis

Lexikos
  • Administrators
  • 9844 posts
  • AutoHotkey Foundation
  • Last active:
  • Joined: 17 Oct 2006
Is there some reason not to use a shell hook (SKAN's method)?

WINEVENTPROC is a pointer to a callback function. See WinEventProc Callback Function.

OrelseIamfired
  • Members
  • 65 posts
  • Last active: Jan 10 2013 01:18 AM
  • Joined: 13 Mar 2006

Is there some reason not to use a shell hook (SKAN's method)?

WINEVENTPROC is a pointer to a callback function. See WinEventProc Callback Function.

Hi lexiKos,

I am experimenting with SKAN's method, but I wanted also to try your suggestion. I am an inquisitive person -- curiosity and all, eager to learn. What I saw in your suggestion was that SetWinEventHook() can be made to respond only to window creation messages, whereas RegisterShellHookWindow() responds to 'every' message.

I had already looked at the microsoft documentation for WinEventProc before asking my question. All I wanted to find out is whether you have used it before using DllCall. If you have managed to make it work, then I shall continue my experiment; if not, then I shall end experimenting with it.

I take it by your answering a question with a question that the answer is no. Yes?

/ Louis

Lexikos
  • Administrators
  • 9844 posts
  • AutoHotkey Foundation
  • Last active:
  • Joined: 17 Oct 2006
I have. Search the forums for SetWinEventHook for examples. WINEVENTPROC is a pointer to a callback function, i.e. the return value of RegisterCallback.

  • Guests
  • Last active:
  • Joined: --
Does this work with child dialog windows? I can't get it to work with Open and Save windows.

On first glance, it looks a little heavy for me


Not at all. The following is an excerpt from my always running script.

Gui +LastFound 
hWnd := WinExist() 

DllCall( "RegisterShellHookWindow", UInt,hWnd ) 
MsgNum := DllCall( "RegisterWindowMessage", Str,"SHELLHOOK" ) 
OnMessage( MsgNum, "ShellMessage" ) 

Return ;                                                 // End of Auto-Execute Section // 

ShellMessage( wParam,lParam ) { 
If ( wParam = 1 ) 
 {
       WinGetTitle, Title, ahk_id %lParam%

       If ( Title="Apcupsd message" ) 
           PostMessage, 0x112, 0xF060,,,ahk_id %lParam%

       If ( Title="Automatic Updates" ) 
            PostMessage, 0x112, 0xF060,,,ahk_id %lParam%
}}

Windows nags me every 5 minutes to restart ( after an Automatic Update ) and my UPS throws an msgbox in case of a power failure.
The above code automatically disposes them, at creation level.

:)



SKAN
  • Administrators
  • 9115 posts
  • Last active:
  • Joined: 26 Dec 2005

Does this work with child dialog windows? I can't get it to work with Open and Save windows.


Short answer is no.

SHELL messages are meant for Taskbar.
The Hook will not retrieve messages for any window that does not affect the Taskbar ( specifically, Child and Hidden windows ).
kWo4Lk1.png

  • Guests
  • Last active:
  • Joined: --
Thanks SKAN for the quick answer. What's the best way to accomplish this that is lightest on resources?

SKAN
  • Administrators
  • 9115 posts
  • Last active:
  • Joined: 26 Dec 2005

What's the best way to accomplish this that is lightest on resources?


Somebody wrote a function ( using neither Loop or recurring Timer ) for this using WinWait. I cannot remember the function name and so unable to trace it. :(
kWo4Lk1.png