9
Answers

Press button from a handled process

Dan

Dan

11y
1.4k
1
I created a C# application. With this application I want to access a button from another application, which is not made by me. Its process name is uWebCam. This is how it looks: 

http://img829.imageshack.us/img829/6606/djq.png

The button that I want to access is located at the bottom of the application, that in the red hexagonal form. 
With Spy++ I took all its classes:

How can I find that button and handle it? I tried something like this, but no answer:

Process process = Process.GetProcessesByName("uWebCam")[0];
IntPtr ButtonHandle = FindWindowEx(process.MainWindowHandle, IntPtr.Zero, null, "button1");
SendMessage(ButtonHandle, BM_CLICK, IntPtr.Zero, IntPtr.Zero);


Here are the API functions:

public const int BM_CLICK = 0x00F5;
[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
private static extern IntPtr SendMessage(IntPtr hwnd, uint Msg, IntPtr wParam, IntPtr lParam);
[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
static extern IntPtr FindWindowEx(IntPtr hwndParent, IntPtr hwndChildAfter, string lpszClass, string lpszWindow);



Answers (9)