0

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.

James Esh
  • 2,219
  • 1
  • 24
  • 41
  • 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. Sep 26 '14 at 08:08
  • 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 Sep 26 '14 at 08:11
  • 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. Sep 26 '14 at 08:19
  • 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 Sep 26 '14 at 08:27
  • 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. Sep 26 '14 at 08:33
  • Yes, sort of, because I have no idea on what to do, this is all stuff I have no idea about. win32 stuff is not my ally. That is why I'm coming to Stackoverflow. – James Esh Sep 26 '14 at 08:46
  • How you pass and when you pass hwnd? You can try to get monitor info using [Screen.AllScreens](http://msdn.microsoft.com/en-us/library/system.windows.forms.screen.allscreens(v=vs.110).aspx) – Renatas M. Sep 26 '14 at 09:38

1 Answers1

3

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.

emoacht
  • 2,764
  • 1
  • 13
  • 24
  • The problem with this is, I cant set the AllowsTransperancy to true. But we did figure out a solution. So thanks for your help though. – James Esh Oct 02 '14 at 10:31