Hello
i need some hints on how to implement a small app that does click an
"Ok" button on a form that comes up from one other app once every 10
minutes.
Something like "Push the freaking button".
Any ideas where to get some information for this?
_thanks rene
You need to use PInvokes.
You'll need
[DllImport("user32.dll", SetLastError = true)]
static extern IntPtr FindWindow(string lpClassName, string
lpWindowName);
[DllImport("user32.dll", SetLastError = true)]
public static extern IntPtr FindWindowEx(IntPtr parentHandle, IntPtr
childAfter, string className, IntPtr windowTitle);
[DllImport("user32.dll")]
private static extern bool PostMessage(
IntPtr hWnd, // handle to destination window
UInt32 Msg, // message
Int32 wParam, // first message parameter
Int32 lParam // second message parameter
);
[DllImport("user32.dll", SetLastError = true)]
static extern IntPtr FindWindowEx(IntPtr hwndParent, IntPtr
hwndChildAfter, string lpszClass, string lpszWindow);
[DllImport("user32.dll")]
That lot, then the process is basically find the window by name
(assuming it has a name)
window=FindWindow(null, "Popup box")
Then you have to find the control and send it a message, the following
is a bit scrubby, it's out of an application I wrote a while ago, but
it should give you the idea. In this case you can see I was trying to
drive a VB6 application thus the reference to ThunderRT6CommandButton.
int hWnd =
(int)FindWindowEx((IntPtr)int.Parse(txt1.Text)
,IntPtr.Zero,"ThunderRT6CommandButton",null);//"Text1");
hWnd = (int)FindWindowEx((IntPtr)int.Parse(txt1.Text) ,(IntPtr)
hWnd,"ThunderRT6CommandButton",null);//"Text1");
txt4.Text=PostMessage((IntPtr)hWnd,
(UInt32)WindowsMessages.WM_LBUTTONDOWN,0,0).ToString();
txt4.Text=PostMessage((IntPtr)hWnd,
(UInt32)WindowsMessages.WM_LBUTTONUP,0,0).ToString();
That's not a complete solution, but it should point you in the right
direction.