Solved

Button Controls

Posted on 1998-06-09
13
236 Views
Last Modified: 2013-12-03
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.
0
Comment
Question by:Zainal062797
  • 7
  • 5
13 Comments
 
LVL 6

Expert Comment

by:alamo
ID: 1407349
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
 
LVL 22

Accepted Solution

by:
nietod earned 50 total points
ID: 1407350
The 3rd parameter, must be specified, it must not be NULL.
0
 
LVL 22

Expert Comment

by:nietod
ID: 1407351
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
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 

Author Comment

by:Zainal062797
ID: 1407352
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
 
LVL 22

Expert Comment

by:nietod
ID: 1407353
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
 

Author Comment

by:Zainal062797
ID: 1407354
Yes... The Caption is "OK" - no underscore.
FIndWindowEx is not working. It doesn't return a handle. It returns NULL.

Thanks.
0
 
LVL 22

Expert Comment

by:nietod
ID: 1407355
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
 

Author Comment

by:Zainal062797
ID: 1407356
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
 
LVL 22

Expert Comment

by:nietod
ID: 1407357
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
 

Author Comment

by:Zainal062797
ID: 1407358
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
 
LVL 22

Expert Comment

by:nietod
ID: 1407359
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
 

Author Comment

by:Zainal062797
ID: 1407360
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
 
LVL 22

Expert Comment

by:nietod
ID: 1407361
Thanks, the feedback always helps.
0

Featured Post

Does Powershell have you tied up in knots?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes how to add a user-defined command button to the Windows 7 Explorer toolbar.  In the previous article (http://www.experts-exchange.com/A_2172.html), we saw how to put the Delete button back there where it belongs.  "Delete" is …
For a while now I'v been searching for a circular progress control, much like the one you get when first starting your Silverlight application. I found a couple that were written in WPF and there were a few written in Silverlight, but all appeared o…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question