Button Controls

I am trying to emulate mouse clicks sent to a an off-shilf software.
The software displays a dialog box which has a number of control buttons. I am trying to emulate this operation by sending a PostMessage() to these button controls. However, the problem is that I cannot find out the handles of these buttons. The button I am interested in is the "OK" button. I used the following:
FindWindowEx (hParent, NULL, NULL, "OK")
But it cannot find it!
Please advise.

Thank you.
Zainal062797Asked:
Who is Participating?
 
nietodCommented:
The 3rd parameter, must be specified, it must not be NULL.
0
 
alamoCommented:
The most obvious possibility is that the button isn't a direct child of the parent you are specifying, it's a child of a child.

Another possibility is that the O in "OK" is underlined, so you'd have to search for "&OK".

Hope this helps!
0
 
nietodCommented:
What you should do is to use Spy++ or a similar utility to obtain the class name of the button and its caption.  (It is possible that the caption is not "OK")  Then you can specify this information to FindWindowEx();
0
Cloud Class® Course: Ruby Fundamentals

This course will introduce you to Ruby, as well as teach you about classes, methods, variables, data structures, loops, enumerable methods, and finishing touches.

 
Zainal062797Author Commented:
I Used Spy++ ans found that the button is a direct child of the window.
The Okay is not underlined.
I used the class name as well for the 3rd parameter, which is "Button".. And it is still not working.

Thanks.
0
 
nietodCommented:
Did you check the captiion in Spy++?  The 4th parameter must match the caption.

What part is not working?  Is FindWindowEx() not returning the handle or is the PostMessage() not working?
0
 
Zainal062797Author Commented:
Yes... The Caption is "OK" - no underscore.
FIndWindowEx is not working. It doesn't return a handle. It returns NULL.

Thanks.
0
 
nietodCommented:
Is the window handle you are passing in the first parameter correct?  It must be a handle to the window that is the dirrect parent window of the button window.  It should not be one of your application's windows and it should not be a grandparent or more distant ancestor of the button.  Use Spy++ to confirm that you are specifying the correct window handle.
0
 
Zainal062797Author Commented:
The parent handle Is correct 100%. It is a direct parent. I could find its siblings using the same function but changing the text. However, the siblings I can get a handle to are all groub boxes. The okay button (and cancel) are stand alone child windows....  I am wondering if this has to do with how Windows  handles and processes windows controls?!

Thanks.

0
 
nietodCommented:
Does Spy++ show the okay button as being a direct child of the parent, or as a child of a group box?  A control is just a window, same as any other window.
0
 
Zainal062797Author Commented:
I solved the promlem. I had to use the "Button" class naem as well as the "OK" text. With others windows, I could get the handle by specifying the text only!

The question now is setting the dialog box item to the desired option.
I can set the radio button to the desired option by passing it  a:
PostMessage (hWnd, WM_SYSKEYDown, Letter, NULL) ;  
But does this actually update the variable associated with this radio button or it just merely checks the radio button, but internally, the variable still holds the old option? Do I have to send additional messges to set the internal variable?

Please Advice.
Thanks.
0
 
nietodCommented:
That was the first thing I told you!  I said the 3rd parameter, the window class, must be specified.

If that makes the radio button appear to be marked that is enough.  You probably will need to send a SYSKEYDOWN and a SYSKEYUP.
0
 
Zainal062797Author Commented:
Thank you very much.
Just to let you know that I did what you told me exactly. As you told me in the beggening , I used the "button" class name nad the window text "OK". The reason it didn't work and later it did is beacuse I realized the timing problem that is caused by Windows messages. See the problem tyurned out to be that the window I was trying to get ist handle was not yet created when the FindWinex() was invoked. This is because the program I am trying to control creats a number of child windows.

I just thought I would share this experience with you.

Thanks again.
Aiman. :)
0
 
nietodCommented:
Thanks, the feedback always helps.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.