How can I be notified when Windows XP fades the screen to gray?
-
We have an application developed in C# with WPF (.NET Framework 3.0) The main window has a glass border, and a child window containing a WebBrowser is centered within it:
WPF main window -> Child window - frame control -> Page -> WindowsFormsHost -> WebBrowser
Because we used .NET 3.0, we have to put WebBrowser in WindowsFormsHost, and it can't show if we set the window property AllowTransparency to true. Now, on Windows XP, when the user clicks the Shutdown button on the Start menu, a dialog is displayed with various choices (shutdown, restart, etc.) while behind it the entire desktop appears to fade from color to shades of gray. When this occurs, our main window becomes hidden, while the page window is still displayed on the screen. We have already set page window's owner to be the main window, but this did not help. Therefore, I have come to the conclusion that I must intercept the "fade to gray" event and... do something to mitigate this ugliness. So: does anyone know how I might allow my program to be notified prior to the fade to gray?Glad to discuss with you and best wishes.
-
We have an application developed in C# with WPF (.NET Framework 3.0) The main window has a glass border, and a child window containing a WebBrowser is centered within it:
WPF main window -> Child window - frame control -> Page -> WindowsFormsHost -> WebBrowser
Because we used .NET 3.0, we have to put WebBrowser in WindowsFormsHost, and it can't show if we set the window property AllowTransparency to true. Now, on Windows XP, when the user clicks the Shutdown button on the Start menu, a dialog is displayed with various choices (shutdown, restart, etc.) while behind it the entire desktop appears to fade from color to shades of gray. When this occurs, our main window becomes hidden, while the page window is still displayed on the screen. We have already set page window's owner to be the main window, but this did not help. Therefore, I have come to the conclusion that I must intercept the "fade to gray" event and... do something to mitigate this ugliness. So: does anyone know how I might allow my program to be notified prior to the fade to gray?Glad to discuss with you and best wishes.
Add the following WndProc in:
private static IntPtr WndProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled)
{
const WM_QUERYENDSESSION = 0x0011;
switch (msg)
{
case WM_QUERYENDSESSION:
// The "screen" is fading here - do what you need to do...
break;
}
return IntPtr.Zero;
}Alternatively, you could have a thread monitoring
System.Environment.HasShutdownStarted;
The advantage of the WndProc approach is that it gets called when the event is fired, and doesn't require a separate thread. Now, to add the WndProc, you do the following in the Window loaded event:void MyWindow_Loaded(object sender, RoutedEventArgs e)
{
HwndSource src = HwndSource.FromHwnd(new WindowInteropHelper(this).Handle);
src.AddHook(new HwndSourceHook(WndProc));
}"WPF has many lovers. It's a veritable porn star!" - Josh Smith
As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
-
Add the following WndProc in:
private static IntPtr WndProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled)
{
const WM_QUERYENDSESSION = 0x0011;
switch (msg)
{
case WM_QUERYENDSESSION:
// The "screen" is fading here - do what you need to do...
break;
}
return IntPtr.Zero;
}Alternatively, you could have a thread monitoring
System.Environment.HasShutdownStarted;
The advantage of the WndProc approach is that it gets called when the event is fired, and doesn't require a separate thread. Now, to add the WndProc, you do the following in the Window loaded event:void MyWindow_Loaded(object sender, RoutedEventArgs e)
{
HwndSource src = HwndSource.FromHwnd(new WindowInteropHelper(this).Handle);
src.AddHook(new HwndSourceHook(WndProc));
}"WPF has many lovers. It's a veritable porn star!" - Josh Smith
As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.