簡體   English   中英

WindowStyle =沒有窗口最大化黑客無法與多個監視器一起使用

[英]WindowStyle=None and window maximized hack not working with multiple monitors

當窗口樣式為無且窗口最大化時,窗口將覆蓋任務欄時,我遇到了問題。 我從這里得到了一個解決方案(我從源代碼中獲得了代碼,而不是他發布的內容),除了一部分之外,它運行良好。 當您有兩個監視器並且主監視器小於輔助監視器時,則會最大化輔助監視器上的窗口,這會發生(請注意,該窗口溢出了整個屏幕):

窗大。

它應該是這樣的:(我只是將窗口調整為全屏。)

手動調整大小

它在這里工作:

主顯示器

我正在做的是制作自定義Chrome。 所有代碼和示例項目都已上傳到此處 另外,如果有人有其他方法可以做到這一點,我將非常感激。 提前致謝!

編輯這是一些快速刷新的代碼:

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);
    }

我沒有編寫這段代碼,所以我真的不知道這里發生了什么。 這就是為什么我在這里。

我在Windows 8.1上測試了您的代碼,並重現了該問題。 因此,我檢查了WmGetMinMaxInfo函數,發現要覆蓋MINMAXINFO的值,WM_GETMINMAXINFO的lParam是正確的,但是在輔助監視器大於主監視器的情況下ptMaxSize不能正確反映。 怪異的

我本人已經使用WindowChrome開發了自定義窗口,並且在設置WindowStyle = None時遇到了一些奇怪的事情。 因此,我個人建議使用GlassFrameThickness = 0CornerRadius = 0而不是WindowStyle = NoneAllowsTransparency = True這樣您就不再需要此技巧。

因此,您的CustomChrome_Initialized函數將是:

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);
  }
}

並且您的Window_StateChanged函數將是:

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);
  }
}

我不確定陰影。

我找到了自己問題的答案。 這真的很復雜,因此如果沒有人發表評論,我將不會發布答案。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM