I write simple Windows service and trying to get hwnd of active window:
private int _hwnd;
[DllImport("User32.dll", SetLastError = true)]
public static extern int GetForegroundWindow();
private void timer1_Tick(object sender, EventArgs e)
{
_hwnd = GetForegroundWindow();
}
_hwnd always equals 0 here. Why? Is there any way to get the correct (!= 0) value?
In Vista and 7, services cannot interact with the desktop. See Interactive Services on MSDN.