Click a button in another application

Posted by sam on Stack Overflow See other posts from Stack Overflow or by sam
Published on 2010-06-09T20:14:16Z Indexed on 2010/06/09 20:22 UTC
Read the original article Hit count: 195

Filed under:

I want yo use SendMessage or PostMessage to press a button in another app

i have a sample code to do this but by getting Window Handle, but don't work

also i used "WinDowse" to get required info. 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# ?

© Stack Overflow or respective owner

Related posts about c#