Getting the foreground window when a hotkey is pressed
I'm trying to get the active window when a certain hotkey is pressed
however my program is always returning the main form of my application as
the active window, not whatever is currently up on the screen (Firefox,
Chrome, etc.). I suspect that once I pressed the hotkey the form is
somehow considered active and that's why it's being returned as the
foreground window?
This is what I'm using to get the currently active window
[DllImport("user32.dll")]
static extern IntPtr GetForegroundWindow();
public IntPtr getCurrentlyActiveWindow()
{
//Debugging
const int nChars = 256;
IntPtr handle = IntPtr.Zero;
StringBuilder Buff = new StringBuilder(nChars);
handle = GetForegroundWindow();
GetWindowText(handle, Buff, nChars);
MessageBox.Show(Buff.ToString());
return GetForegroundWindow();
}
Any ideas on what I can do to get the ACTUAL active window?
No comments:
Post a Comment