How can I simulate a button click in the sendmessage API in C#?
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();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With