views:

63

answers:

1

I noticed that if you call FindWindowEx or EnumChildWindows against a hWnd that belongs to a window that's not in the foreground, i.e. minimized, then they don't report any children. On the other hand if I first call SetForegroundWindow against the window I'm querying, and after that FindWindowEx or EnumChildWindows, they report all the children. Next calls report all the children even if the window I'm interested in is not in foreground. It's almost it does some sort of caching after the first call?

A: 

Is this a window in your own application, or are you investigating what a third-party application does?

I would guess that the application only creates its child windows the first time it is brought into the foreground; this would explain the behaviour you are seeing. To my knowledge, EnumChildWindows does not perform any caching.

Martin B
It's another application, what I'm saying is that in order for EnumChildWindows to report any children, the target window needs to be in foreground, the first time at least. The window has created it's child windows prior to calling EnumChildWindows, I can see all of them, but if it's not in foreground is almost as it doesn't have any children.
Ion Todirel
@Ion: If, as you said in the question, the window is minimized when you call EnumChildWindows, how can you be sure that the child windows have already been created? Or does this behaviour also occur if the window is visible (i.e. un-minimized) but not in the foreground?
Martin B
That is correct, even if the window is visible but not in foreground.
Ion Todirel
Im pretty sure EnumChildwindows DOES operate off of a cache - I mean, one of the things programmers are likely to do in their EnumChildWindowProc would be to change the order or state of the enumerated child windows. EnumChildwindows would be impossible to use if it did not enumerate a cached collection of hwnds.
Chris Becke
@Chris: True -- in fact the documentation makes some very specific statements about this: "A child window that is moved or repositioned in the Z order during the enumeration process will be properly enumerated. The function does not enumerate a child window that is destroyed before being enumerated or that is created during the enumeration process." Since some of the information is apparently updated even during the enumeration, I would however expect the state to be current as of the time that `EnumChildWindows` was called.
Martin B