Solved

Button Controls

Posted on 1998-06-09
13
233 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
Comment Utility
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
Comment Utility
The 3rd parameter, must be specified, it must not be NULL.
0
 
LVL 22

Expert Comment

by:nietod
Comment Utility
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
 

Author Comment

by:Zainal062797
Comment Utility
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
Comment Utility
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
Comment Utility
Yes... The Caption is "OK" - no underscore.
FIndWindowEx is not working. It doesn't return a handle. It returns NULL.

Thanks.
0
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 
LVL 22

Expert Comment

by:nietod
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
Thanks, the feedback always helps.
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

This article describes a technique for converting RTF (Rich Text Format) data to HTML and provides C++ source that does it all in just a few lines of code. Although RTF is coming to be considered a "legacy" format, it is still in common use... po…
A theme is a collection of property settings that allow you to define the look of pages and controls, and then apply the look consistently across pages in an application. Themes can be made up of a set of elements: skins, style sheets, images, and 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…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

763 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now