I want to use SendMessageor PostMessageto click a button in another application
I have sample code to do this by getting a Window Handle, but it doesn't work
I also used "WinDowse" to get the required information. here is the code
private const uint BM_CLICK = 0x00F5;
private const uint WM_LBUTTONDOWN = 0x0201;
private const uint WM_LBUTTONUP = 0x0202;
private void PushOKButton(IntPtr ptrWindow)
{
WindowHandle = FindWindow(null, "Form1");
if (ptrWindow == IntPtr.Zero)
return;
IntPtr ptrOKButton = FindWindowEx(ptrWindow, IntPtr.Zero, "Button", "&Yes");
if (ptrOKButton == IntPtr.Zero)
return;
SendMessage(ptrOKButton, WM_LBUTTONDOWN, 0, 0);
SendMessage(ptrOKButton, WM_LBUTTONUP, 0, 0);
SendMessage(ptrOKButton, BM_CLICK, 0, 0);
}
Is there a Compelete Suloution in C #?
source
share