Pressing a button within another application in the loop
I was thinking some one will be able to help me out to do a simple thing,
but for some reason I can not get my head around it. I am trying to press
a button within another application and do it in the loop, loop should
break when the pressed button is gone, I had successfully accomplished
task of pressing button, but I can not do a loop, as soon as I press
button to start loop my application hangs. Thank you in advance.
private void btnCloseCalc_Click(object sender, System.EventArgs e)
{
int hwnd=0;
IntPtr hwndChild = IntPtr.Zero;
//Get a handle for the Application main window
hwnd = FindWindow(null, "Desired MessageBox");
hwndChild = FindWindowEx((IntPtr)hwnd, IntPtr.Zero, "Button", "OK");
//send system message
if (hwnd != 0)
{
SendMessage((int)hwndChild, BN_CLICKED, 0, IntPtr.Zero);
}
else
{
MessageBox.Show("Button Could Not Be Found!", "Warning",
MessageBoxButtons.OK);
}
}
No comments:
Post a Comment