Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Button click in sendmessage API

Tags:

c#

native

api

How can I simulate a button click in the sendmessage API in C#?

like image 589
Prabodha Eranga Avatar asked Jan 12 '11 04:01

Prabodha Eranga


1 Answers

C code:

#include <Windows.h>
//...
SendMessage(hWndButton, BM_CLICK, 0, 0);

C# code:

[DllImport("user32.dll")]
static extern IntPtr SendMessage(IntPtr hWnd, int msg, IntPtr wParam, IntPtr lParam);

...
Button myButton = ...;
const int BM_CLICK = 0x00F5;
SendMessage(myButton.Handle, BM_CLICK, IntPtr.Zero, IntPtr.Zero);

But be aware that, in C#, you can just as easily do:

myButton.PerformClick();
like image 187
user541686 Avatar answered Oct 18 '22 11:10

user541686