I've used something like the following to automate the clicking of OK on some named window.
Spin up a thread which polls for the existence of the pop-up and click it if it does.
[
System.Runtime.InteropServices.DllImportAttribute
(
"User32"
,
SetLastError=true
,
EntryPoint="FindWindow"
)
]
private static extern System.IntPtr
API_FindWindow
(
string lpClassName
,
string lpWindowName
) ;
public static System.IntPtr
FindWindow
(
string WindowName
)
{
return ( API_FindWindow
(
null
,
WindowName
) ) ;
}
public enum WindowsMessage : uint
{
EM_GETPARAFORMAT = 61
,
EM_SETPARAFORMAT = 71
,
WM_LBUTTONDOWN = 0x0201
,
WM_LBUTTONUP = 0x0202
} ;
[
System.Runtime.InteropServices.DllImportAttribute
(
"User32"
,
SetLastError=true
,
EntryPoint="SendMessage"
)
]
private static extern System.Int32
API_SendMessage
(
System.IntPtr hWnd
,
System.UInt32 Msg
,
System.Int16 wParam
,
System.Int32 lParam
) ;
public static System.Int32
SendMessage
(
System.IntPtr Window
,
WindowsMessage Message
)
{
return ( API_SendMessage
(
Window
,
(System.UInt32) Message
,
0
,
0
) ) ;
}
System.IntPtr hTemp ;
if ( ( hTemp = PIEBALD.Lib.LibApi.FindWindow ( k.Caption ) ) != System.IntPtr.Zero )
{
PIEBALD.Lib.LibApi.SetActiveWindow ( hTemp ) ;
System.IntPtr hok ;
if ( ( hok = PIEBALD.Lib.LibApi.FindWindowEx ( hTemp , k.Press ) ) != System.IntPtr.Zero )
{
PIEBALD.Lib.LibApi.SendMessage ( hok , PIEBALD.Lib.LibApi.WindowsMessage.WM_LBUTTONDOWN ) ;
PIEBALD.Lib.LibApi.SendMessage ( hok , PIEBALD.Lib.LibApi.WindowsMessage.WM_LBUTTONUP ) ;
}
}