Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. WPF
  4. How can I be notified when Windows XP fades the screen to gray?

How can I be notified when Windows XP fades the screen to gray?

Scheduled Pinned Locked Moved WPF
csharpquestiondotnetwpfhelp
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    CooperWu
    wrote on last edited by
    #1

    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.

    P 1 Reply Last reply
    0
    • C CooperWu

      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.

      P Offline
      P Offline
      Pete OHanlon
      wrote on last edited by
      #2

      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.

      My blog | My articles | MoXAML PowerToys | Onyx

      C 1 Reply Last reply
      0
      • P Pete OHanlon

        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.

        My blog | My articles | MoXAML PowerToys | Onyx

        C Offline
        C Offline
        CooperWu
        wrote on last edited by
        #3

        Thanks for your reply, i tried it, it doesn't work. the WPF window can't catch WM_QUERYENDSESSION message...

        Glad to discuss with you and best wishes.

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups