[DllImport("user32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
static extern bool SetForegroundWindow(IntPtr hWnd);
Private Declare Function SetForegroundWindow Lib "user32" (ByVal hwnd As IntPtr) As Long
None.
None.
This is especially useful for test automation to make sure the Application Under Test (AUT) retains focus before manipulating it.
This may be called several times in an automated test script, so it is best to create a method similar to the example below.
public static void Main(string[] args)
{
// test code here...
CheckAutFocus(myProcess.MainWindowHandle);
// more test code...
}
public static void CheckAutFocus(hWnd)
{
if (GetForegroundWindow() != hWnd)
{
SetForegroundWindow(hWnd);
}
}
Do you know one? Please contribute it!