I'm handling WndProc in my WPF application in order to respond to the event where some other application enters fullscreen. At this time, the main window of my application needs to hide. Here is the code I have written:
Hooking:
HwndSource source = HwndSource.FromHwnd(MyMainWindowHandle);
source.AddHook(this.WndProc);
WndProc:
private IntPtr WndProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled)
{
Debug.Print("In wndproc");
QUERY_USER_NOTIFICATION_STATE state;
SHQueryUserNotificationState(out state);
if (MyMainWindow.Visibility == Visibility.Visible && state == QUERY_USER_NOTIFICATION_STATE.QUNS_BUSY)
{
Debug.Print("hiding");
MyMainWindow.Hide();
}
else if (MyMainWindow.Visibility == Visibility.Hidden && state != QUERY_USER_NOTIFICATION_STATE.QUNS_BUSY)
{
Debug.Print("showing");
MyMainWindow.Show();
}
return IntPtr.Zero;
}
This works as expected with applications like PowerPoint or Skype. However, when a web browser (Chrome) enters full screen while playing a video, the WndProc is not called when the user exits full screen. It is called and behaves as expected after the user does something else, like click the Windows task bar, etc. Does anyone know why / a workaround to this issue?