Link to home
Start Free TrialLog in
Avatar of sooman
sooman

asked on

FindWindowEx to find Child Window

am attempting to test for the existence of a child window with a specific
name using FindWindowEx, and I am coming up empty.

The parent form is of class TAFOSParent and the child is a TMainForm in the
example below.  EditFile is the name of the child window I am looking for.
The FindWindow function does successfully find the handle of the parent
window.  However, the only way I can get a child window handle from
FindWindowEx is to set the class name and window name pointers both to NIL,
and of course that handle is not to the window I am looking for.  What may
I be doing wrong (I created the program that creates the window in
question, if the problem is likely there).

    HParentWindow:=FindWindow('TAFOSParent','AFOSED');
    ClassName:='TMainForm';
    repeat
      SleepEx(3000,false);
      Y:=FindWindowEx(HParentWindow,0,PChar(ClassName),PChar(EditFile));
    until Y=0;
Avatar of sperling
sperling

Have you used a spy program to make absolutely sure the spelling and case of both class and window name are correct?

Is this a MDI app?



Hi:

If you sure the name and class is same, then check if the window
with name EditFile is one of DIRECT child of the parent window.
Documentation stressed that it must be direct child. In this case

Y:=FindWindow(PChar(ClassName),PChar(EditFile)); may be a better
choice.  If this one fails, then you have to find your window
through child window chain, until you locate what you want.

Hope this helps

Gaohong Xie
Avatar of sooman

ASKER

I stress that I CAN get A child window when I specify NIL (NUL) for both the Child window class name and name pointers when using FindWindowEx, which I would assume means that my child windows ARE direct decendents.  Besides, having made the program containing the child windows I know they are direct decendents and that it is an MDI application.
There a two low-level ways to walk the child windows list:
- use GetTopWindow() / GetNextWindow()
- use EnumChildWindows()

both work, but the first one is unsafe (cannot handle the case of one child being destroyed whilöe walking the list). FindWindowEx is probably using the second method.
So, I would recommend you just try those ways to walk your children list and dump any class names/window names you find. Maybe you find that your child is really not in this list.
ASKER CERTIFIED SOLUTION
Avatar of pavel030297
pavel030297

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I'm facing the same problem with IE7.
The strange thing is that I'm not facing the issue with IE6, FindWindowEx works perfectly fine with IE6