By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
458,127 Members | 1,366 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 458,127 IT Pros & Developers. It's quick & easy.

How To Click a Button using SendMessage and C#

P: n/a
I am trying to click a button in another window and I have it's hWnd
value so I was trying to use Send message. Here is my code but it
doesn't work as expected...

response = Win32API.SendMessage(hWndYesButton,Win32API.BM_SET STATE,0,null);
response = Win32API.SendMessage(hWndYesButton,Win32API.WM_LBU TTONDOWN,1,"11");
response = Win32API.SendMessage(hWndYesButton,Win32API.WM_LBU TTONDOWN,1,null);
response = Win32API.SendMessage(hWndYesButton,Win32API.WM_LBU TTONUP,0,null);
response = Win32API.SendMessage(hWndYesButton,Win32API.BM_SET STATE,1,null);
response = Win32API.SendMessage(hWndYesButton,Win32API.BM_SET STATE,0,null);

Can someone give me an example in C# that works! I would certainly
appreciate it as this is driving me crazy because all it does is press
the button but fails to fire the click event so that window actually
closes!

Thanks
Mark
Nov 15 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
Send a WM_COMMAND to the parent window or dialog (form) that holds the
control with the wParam set to the ID of the button. This should simulate
the button press, works with Win32API code.
----------------------------
"Mark Overstreet" <ma*************@mail.state.ky.us> wrote in message
news:40*************************@posting.google.co m...
I am trying to click a button in another window and I have it's hWnd
value so I was trying to use Send message. Here is my code but it
doesn't work as expected...

response = Win32API.SendMessage(hWndYesButton,Win32API.BM_SET STATE,0,null); response = Win32API.SendMessage(hWndYesButton,Win32API.WM_LBU TTONDOWN,1,"11"); response = Win32API.SendMessage(hWndYesButton,Win32API.WM_LBU TTONDOWN,1,null); response = Win32API.SendMessage(hWndYesButton,Win32API.WM_LBU TTONUP,0,null); response = Win32API.SendMessage(hWndYesButton,Win32API.BM_SET STATE,1,null); response = Win32API.SendMessage(hWndYesButton,Win32API.BM_SET STATE,0,null);
Can someone give me an example in C# that works! I would certainly
appreciate it as this is driving me crazy because all it does is press
the button but fails to fire the click event so that window actually
closes!

Thanks
Mark

Nov 15 '05 #2

P: n/a
Mark,

Have you tried the BM_CLICK message?

Mattias

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Nov 15 '05 #3

P: n/a
Mark,

Have you tried the BM_CLICK message?

Mattias

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Nov 15 '05 #4

P: n/a


Yes I have tried the BM_CLICK parameter as well. Sometimes it works in
Design mode stepping through the code but when I run the app, it
doesn't.

Any other ideas?

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 15 '05 #5

P: n/a


Yes I have tried the BM_CLICK parameter as well. Sometimes it works in
Design mode stepping through the code but when I run the app, it
doesn't.

Any other ideas?

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 15 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.