tags:

views:

290

answers:

2

Anyone have an idea why this wouldn't work?

IntPtr hWnd = FindWindow(null, "Calculator");
IntPtr hWnd2 = GetActiveWindow();

if(hWnd == hWnd2)
{
     MessageBox.Show("Same");
}

Invokes are:

[DllImport("user32.dll")]
static extern IntPtr GetActiveWindow();

[DllImport("user32.dll", SetLastError = true)]
public static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
A: 

It's very possible that GetActiveWindow() is returning the handle to your application/command window.

scottm
+1  A: 

Ends up "GetActiveWindow" seems to be returning child areas.

GetForegroundWindow() is returning the windows handle.