0
votes

I had a problem when the window style is none and the window is maximized that the window would cover the taskbar. I got a solution from here (I got the code from the source code not what he posted), and it works well except for one part. When you have two monitors and the primary monitor is smaller than your secondary monitor, then you maximize the window on your secondary monitor, this happens (notice the window is spilling out over the screen):

Window is WAY to big.

This is how it should look: (I just resized the window to full screen.)

Resized Manually

It works here though:

Primary monitor

What I'm doing is making a custom chrome thing. All the code and a sample project is uploaded here. Also if someone has any other ways to do this, I would really appreciate it. Thanks in advance!

EDIT Here is some of the code for quick refrence:

private static void WmGetMinMaxInfo(System.IntPtr hwnd, System.IntPtr lParam)
    {
        MINMAXINFO mmi = (MINMAXINFO)Marshal.PtrToStructure(lParam, typeof(MINMAXINFO));

        // Adjust the maximized size and position to fit the work area of the correct monitor
        int MONITOR_DEFAULTTONEAREST = 0x00000002;
        System.IntPtr monitor = MonitorFromWindow(hwnd, MONITOR_DEFAULTTONEAREST);

        if (monitor != System.IntPtr.Zero)
        {
            MONITORINFO 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) - 8;
            mmi.ptMaxSize.x = Math.Abs(rcWorkArea.right - rcWorkArea.left);
            mmi.ptMaxSize.y = Math.Abs(rcWorkArea.bottom - rcWorkArea.top) + 8;
            if (rcWorkArea.bottom == rcMonitorArea.bottom)//full screen (no taskbar)
                mmi.ptMaxSize.y--;//remove 1 px from the bottom for "Auto-hide taskbar" configuration
            mmi.ptMinTrackSize.x = (int)currentlyChangingWindow.MinWidth;
            mmi.ptMinTrackSize.y = (int)currentlyChangingWindow.MinHeight;
        }

        Marshal.StructureToPtr(mmi, lParam, true);
    }

I didn't wright this code so I don't really know what is going on here. That's why I'm here.

2
Cant understand so you want that window cover task bar or not? P.s. I think nobody is going to download all you project. Please post issue related code. - Renatas M.
If you look at the first picture, it shows the app way too big, extending off the screen. That is the problem. And yes I want the taskbar shown. - James Esh
Oh that's the problem. For future - it is nice to write exact problem and show code in questions. So are you getting correct monitor and correct working area in your code? - Renatas M.
If you put a break point in at 'WmGetMinMaxInfo(System.IntPtr hwnd, System.IntPtr lParam)' and debug it and notice when you have the correct scenario the 'rcWorkArea' is really funked up. - James Esh
I'am not going to debug for you. Please add details to question with monitor resolutions, actual results while debugging and expected results. Is it very hard to do to formulate question with you current problem? - Renatas M.

2 Answers

3
votes

I tested your code on Windows 8.1 and the problem was reproduced. So I checked your WmGetMinMaxInfo function and found the values to overwrite MINMAXINFO, lParam of WM_GETMINMAXINFO were correct but ptMaxSize was not correctly reflected in the case secondary monitor is larger than primary one. Wierd.

I myself have developed custom window using WindowChrome and experienced some wierd things when setting WindowStyle = None. So I personally recommend to use GlassFrameThickness = 0 and CornerRadius = 0 instead of WindowStyle = None and AllowsTransparency = True then your no longer need this hack.

So your CustomChrome_Initialized function will be:

void CustomChrome_Initialized(object sender, EventArgs e)
{
  if (CurrentWindow != null)
  {
    Chrome = new WindowChrome()
    {
      GlassFrameThickness = new Thickness(0),
      CornerRadius = new CornerRadius(0),
      ResizeBorderThickness = new Thickness(ResizeGripWidth)
    };

    WindowChrome.SetWindowChrome(CurrentWindow, Chrome);

    //DropShadow
    CurrentWindow.Effect = WindowEffect;
    CurrentWindow.StateChanged += Window_StateChanged;
    Window_StateChanged(CurrentWindow, EventArgs.Empty);
  }
}

and your Window_StateChanged function will be:

void Window_StateChanged(object sender, EventArgs e)
{
  var window = ((Window)sender);
  if (window.WindowState == WindowState.Maximized)
  {
    window.BorderThickness = new Thickness(ResizeGripWidth);
  }
  else
  {
    window.BorderThickness = new Thickness(0);
  }
}

I am not certain about shadow though.

-1
votes

I found the answer to my own question. It's really complicated so if no one comments I wont post the answer.