[WPF Troubleshooter] hide the taskbar when the window is maximized

Source: Internet
Author: User
Tags abs static class

A bad thing about maximizing a WPF window is that if the window's WindowStyle is set to none directly or indirectly (for example, you will override the default form style in many cases, that is, not using the Windows default border and maximizing the button to create a personalized form), When the window is maximized, the window fills the screen and covers the taskbar. This often does not meet the actual requirements.

Here's a nice solution to solve the problem by Wm_getminmaxinfo (msdn:the wm_getminmaxinfo message being sent to a windows when the size or position O f The window is about to change. An application can use this message to override the window ' s default maximized size and position, or its default minimum O R maximum tracking size.) Messages are hooked up to a hook to handle. The message code is: 0x0024 (more message code can refer to the appendix of this article)

There's nothing to say, just go to the code (call the Fullscreenmanager.repairwpfwindowfullscreenbehavior method for the window you want to process):

 public static class Fullscreenmanager {public static void Repairwpfwindowfullscreenbehavior (Window wpfwindow)
      {if (Wpfwindow = = null) {return;
        } if (wpfwindow.windowstate = = windowstate.maximized) {wpfwindow.windowstate = Windowstate.normal;
      wpfwindow.loaded + = delegate {wpfwindow.windowstate = windowstate.maximized;}; } wpfwindow.sourceinitialized + = delegate {INTPTR handle = (new Windowinterophelper (Wpfwindow)).
        Handle;
        HwndSource Source = Hwndsource.fromhwnd (handle); if (source!= null) {source.
        Addhook (WINDOWPROC);
    }       }; private static INTPTR WindowProc (INTPTR hwnd, int msg, IntPtr wParam, IntPtr LParam, ref BOOL handled) {s
          Witch (msg) {case 0x0024:wmgetminmaxinfo (hwnd, LParam);
          handled = TRUE;
      Break
    Return (INTPTR) 0; } private static void WMGETMINMAxinfo (IntPtr hwnd, IntPtr LParam) {var mmi = (minmaxinfo) marshal.ptrtostructure (LParam, typeof (Minmaxinfo)); Adjust the maximized size and position to fit the work area of the correct monitor int monitor_defaulttonear
      EST = 0x00000002;
      INTPTR monitor = Monitorfromwindow (hwnd, monitor_defaulttonearest);
        if (monitor!= IntPtr.Zero) {var monitorinfo = new Monitorinfo ();
        Getmonitorinfo (monitor, monitorinfo);
        RECT Rcworkarea = monitorinfo.rcwork;
        RECT Rcmonitorarea = Monitorinfo.rcmonitor;
        mmi.ptmaxposition.x = Math.Abs (rcworkarea.left-rcmonitorarea.left);
        MMI.PTMAXPOSITION.Y = Math.Abs (rcworkarea.top-rcmonitorarea.top);
        mmi.ptmaxsize.x = Math.Abs (rcworkarea.right-rcworkarea.left);
      Mmi.ptmaxsize.y = Math.Abs (rcworkarea.bottom-rcworkarea.top);
    Marshal.structuretoptr (MMI, LParam, True); }

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.