Solved

send message to button of a window

Posted on 2001-06-27
11
222 Views
Last Modified: 2010-04-02
i need to activate a checkbox on a window which runs in windows system
i manage to get the windows hwnd.
i know the checkbox name
how can i find with the parent window handle & caption & the checkbox name the checkbox handle & send a message to check that checkbox?

for code i will add points
0
Comment
Question by:etay
11 Comments
 
LVL 4

Expert Comment

by:IainHere
Comment Utility
Sounds like you're up to no good. Use GetParent to get the parents handle, the use GetWindowText to get the caption.  You already have the name of the checkbox?  If you mean the class name, you can use FindWindowEx using the other information you have to get the checkbox handle.

Then, with the handle of the checkbox, you can use SendMessage.  Sorry I don't have more info or code, but this should help you along a bit, and all the functions are fully documented in MSDN.

Have fun.
0
 

Author Comment

by:etay
Comment Utility
i've tried that it doesnt work
i need to click the mute all checkbox in the volume control of the windows
0
 
LVL 30

Expert Comment

by:Axter
Comment Utility
Check out the following link:
http://www.axter.com/faq/topic.asp?TOPIC_ID=35&FORUM_ID=4&CAT_ID=9&Topic_Title=Controlling+Another+Program&Forum_Title=C%2FC%2B%2B

It has a wrapper class that does what IainHere stated above.
0
 
LVL 4

Expert Comment

by:IainHere
Comment Utility
My word! You went to all that trouble for 50 points!  Very impressive - I think I'll give up :)
0
 
LVL 30

Expert Comment

by:Axter
Comment Utility
std::vector<WindowPath> windowpath1;
windowpath1.push_back(WindowPath("Volume Control","",0));
windowpath1.push_back(WindowPath("","&Mute all",0));
Ext_Wnd VolumeControl(windowpath1);
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 30

Expert Comment

by:Axter
Comment Utility
IainHere,
Didn't you see the date on the link.  That's an old class I created a couple months ago for another project.

etay,
On my previous comment, I posted example code for getting the window handle for the Mute-All checkbox on the Volume Control.

If I had time, I would show you how to send the check message.
If IainHere or none of the other experts haveing givin you the additional information by the time I get back, then I'll posted it for you.

It should be something like the following:
VolumeControl.SendMessage(???,???,???);
0
 
LVL 4

Expert Comment

by:IainHere
Comment Utility
If you have a handle on the checkbox, use:

<from msdn under BM_SETCHECK>

SendMessage(
  (HWND) hWnd,              // handle to destination window
  BM_SETCHECK,              // message to send
  (WPARAM) wParam,          // check state
  (LPARAM) lParam          // not used; must be zero
);

in order to set it, you'd use

SendMessage(hwndMuteAll, BM_SETCHECK, BST_CHECKED, 0);

Hope this helps.  Also, "i've tried that it doesnt work" - which bit doesn't work?
0
 
LVL 4

Expert Comment

by:IainHere
Comment Utility
Axter:  I was trying to suggest that you'd created the website specifically to answer this question.  Sorry I didn't make it more clear.  Or funny.
0
 
LVL 32

Expert Comment

by:jhance
Comment Utility
Axter,

>>Didn't you see the date on the link.  That's an old
>>class I created a couple months ago for another
>>project.

Don't give me that!  Give yourself full credit.  You ANTICIPATED that this question would come up and proactively created this example so you'd be ready...

Right??
0
 
LVL 30

Expert Comment

by:Axter
Comment Utility
jhance,
>>Don't give me that!  Give yourself full credit.  You
>>ANTICIPATED that this question would come up and
>>proactively created this example so you'd be ready...
>>Right??
Ok, I must confess.  I did create the class for a personel project, but I posted it on the web because I see this question asked so many times in EE.
Thought it be easier to answer with wrapper class.

Though I need to add some more examples to it.
0
 
LVL 30

Accepted Solution

by:
Axter earned 50 total points
Comment Utility
Adding to what IainHere said above on the SendMessage() function, you can do the following with the wrapper class:

std::vector<WindowPath> windowpath1;
windowpath1.push_back(WindowPath("Volume Control","",0));
windowpath1.push_back(WindowPath("","&Mute all",0));
Ext_Wnd VolumeControl(windowpath1);
VolumeControl.SendMessage(
  BM_SETCHECK,              // message to send
 (WPARAM) wParam,          // check state
 (LPARAM) NULL          // not used; must be zero
);

For the Ext_Wnd class you don't need to use the "hWnd" variable because it stores it, and calls the global SendMessage() function with the stored m_hWnd variable.
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

When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

728 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

12 Experts available now in Live!

Get 1:1 Help Now