How To Click a Button using SendMessage and C#

  • Thread starter Thread starter Mark Overstreet
  • Start date Start date
M

Mark Overstreet

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_SETSTATE,0,null);
response = Win32API.SendMessage(hWndYesButton,Win32API.WM_LBUTTONDOWN,1,"11");
response = Win32API.SendMessage(hWndYesButton,Win32API.WM_LBUTTONDOWN,1,null);
response = Win32API.SendMessage(hWndYesButton,Win32API.WM_LBUTTONUP,0,null);
response = Win32API.SendMessage(hWndYesButton,Win32API.BM_SETSTATE,1,null);
response = Win32API.SendMessage(hWndYesButton,Win32API.BM_SETSTATE,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
 
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.
 
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?
 
Back
Top