473,378 Members | 1,383 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

How To Click a Button using SendMessage and C#

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
5 19368
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
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
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


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


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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Brad | last post by:
Hi all, I've been using the well document Click Yes program for auto sending emails for some time now and it has done it's job perfectly. In fact I have been so impressed with this that I've...
6
by: Martijn Coppoolse | last post by:
Hello everyone, I've got two little apps which are able to create a window that displays something on the desktop, but are not clickable. Instead, when you click on the window, the item...
3
by: Rob | last post by:
Hi all, I am having trouble converting the code below (found on http://vbnet.mvps.org/index.html?code/core/sendmessage.htm) into a format that will work using vb .NET. Can anyone have a look...
24
by: aam | last post by:
hi, im trying to figure out how i can program the mouse to automatically click on a button of a web page that i'm viewing.i do not have control over the page.i would also like to set up an...
4
by: Abhishek | last post by:
Hi, I have a activex web browser embedded in a windows form and on a click of a form button i need the mouse to go the position for example 100, 100 and click the link that will be there on that...
3
by: Morten Snedker | last post by:
If I have a number of random applications open, move the mouse cursor to a given position and do a click, the application gets the focus. That is what this simple code should illustrate: Dim...
18
by: eliss.carmine | last post by:
Is it possible to simulate a mouse click in the window I made (it's a Form), but not give it focus? I tried using WinAPI's mouseevent and SendMessage of WM_LBUTTONDOWN/WM_LBUTTONUP as suggested...
3
by: | last post by:
I have a control that need to perform one behavior when it's Clicked and a different behavior when it's DoubleClicked. It seems that you can't get a DoubleClick without first getting a Click. So...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.