Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How can Spy++ see windows that GetWindow() can't?

12 views
Skip to first unread message

Chris Shearer Cooper

unread,
Nov 8, 2010, 1:47:04 PM11/8/10
to
My program is launching another program using CreateProcess(), and
then the launching program needs to control the launched program by
sending it mouse and keyboard events. Nothing abnormal there.

What is strange, is that the launching program isn't able to find the
correct windows inside the launched program. Spy++ correctly sees
that the main window of the launched program has 7 child windows,
while both GetWindow(GW_HWNDNEXT) and EnumWindows() report only 4
child windows.

Does anyone know what method Spy++ uses to find its windows?

Richard Russell

unread,
Nov 8, 2010, 5:44:14 PM11/8/10
to
On Nov 8, 6:47 pm, Chris Shearer Cooper

<chris.shearer.coo...@gmail.com> wrote:
> What is strange, is that the launching program isn't able to find the
> correct windows inside the launched program.

How quickly after launching the program do you look for them? I
wonder whether the problem isn't that the child windows cannot be
seen, but simply that they don't yet exist. I know I've had to use
Sleep, or WaitForInputIdle, or SendMessage(WM_NULL...) to ensure the
launched application has completed its initialisation before trying to
find its child windows.

Richard.
http://www.rtrussell.co.uk/

Chris Shearer Cooper

unread,
Nov 8, 2010, 6:04:23 PM11/8/10
to

Bingo!

Yes, I was already calling WaitForInputIdle(), and even after that I
was waiting for the main window to appear in EnumWindows(); but I
added some code to check for the number of children, and if they
aren't all there, to wait some more ... and that was it!

I was looking for something difficult, like maybe EnumWindows() didn't
find Unicode windows or something (not that I know the launched
program has Unicode windows), it didn't occur to me that the reason I
wasn't seeing the windows is that they weren't there yet ...

Thanks!
Chris

Joseph M. Newcomer

unread,
Nov 12, 2010, 8:26:46 PM11/12/10
to
On Mon, 8 Nov 2010 15:04:23 -0800 (PST), Chris Shearer Cooper
<chris.shea...@gmail.com> wrote:

>On Nov 8, 3:44�pm, Richard Russell <n...@rtrussell.co.uk> wrote:
>> On Nov 8, 6:47�pm, Chris Shearer Cooper
>>
>> <chris.shearer.coo...@gmail.com> wrote:
>> > What is strange, is that the launching program isn't able to find the
>> > correct windows inside the launched program.
>>
>> How quickly after launching the program do you look for them? �I
>> wonder whether the problem isn't that the child windows cannot be
>> seen, but simply that they don't yet exist. �I know I've had to use
>> Sleep, or WaitForInputIdle, or SendMessage(WM_NULL...) to ensure the
>> launched application has completed its initialisation before trying to
>> find its child windows.
>>
>> Richard.http://www.rtrussell.co.uk/
>
>Bingo!
>
>Yes, I was already calling WaitForInputIdle(), and even after that I
>was waiting for the main window to appear in EnumWindows(); but I
>added some code to check for the number of children, and if they
>aren't all there, to wait some more ... and that was it!

***
WaitForInputIdle indicates the message pump has blocked. So without knowing how the child
process manages its windows, there is no way to guess.
joe
****


>
>I was looking for something difficult, like maybe EnumWindows() didn't
>find Unicode windows or something (not that I know the launched
>program has Unicode windows), it didn't occur to me that the reason I
>wasn't seeing the windows is that they weren't there yet ...
>
>Thanks!
>Chris

Joseph M. Newcomer [MVP]
email: newc...@flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm

0 new messages