Solved

Button Controls

Posted on 1998-06-09
13
239 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

 

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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Is COM supported from Apache 1 77
VIDEO DATASOURCE Control Resize issue 2 61
"Video DataSource is Offline or not responding"  - why? 1 162
SSRS Deployment problem 5 122
This article shows a few slightly more advanced techniques for Windows 7 gadget programming, including how to save and restore user settings for your gadget and how to populate the "details" panel that is displayed in the Windows 7 gadget gallery.  …
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 …
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…
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…

740 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