wpf - 处理 WM_GETMINMAXINFO 时如何考虑帧大小

标签 wpf winapi window-chrome

我有一个处理 WM_GETMINMAXINFO 的 WPF 应用程序,以便自定义窗口镶边并仍然尊重系统任务栏。也就是说,当您最大化带有任务栏的显示器上的窗口时,它不会覆盖任务栏。这工作得很好,只是窗口的框架在最大化时仍然可见,这既丑陋又无用,因为窗口在最大化时无论如何都无法调整大小。

为了解决这个问题,我认为我需要改变对 WM_GETMINMAXINFO 的处理,以增加窗口的大小,如下所示:

var monitorInfo = new SafeNativeMethods.MONITORINFO
    {
        cbSize = Marshal.SizeOf(typeof(SafeNativeMethods.MONITORINFO))
    };
SafeNativeMethods.GetMonitorInfo(monitor, ref monitorInfo);
var workArea = monitorInfo.rcWork;
var monitorArea = monitorInfo.rcMonitor;
minMaxInfo.ptMaxPosition.x = Math.Abs(workArea.left - monitorArea.left);
minMaxInfo.ptMaxPosition.y = Math.Abs(workArea.top - monitorArea.top);
minMaxInfo.ptMaxSize.x = Math.Abs(workArea.right - workArea.left);
minMaxInfo.ptMaxSize.y = Math.Abs(workArea.bottom - workArea.top);

// increase size to account for frame
minMaxInfo.ptMaxPosition.x -= 2;
minMaxInfo.ptMaxPosition.y -= 2;
minMaxInfo.ptMaxSize.x += 4;
minMaxInfo.ptMaxSize.y += 4;

这确实有效,但我担心的是最后四行,我假设帧宽度为 2 像素。是否有更通用的方法来获取帧宽度,以便我可以将其容纳在我的 WM_GETMINMAXINFO 处理程序中?

谢谢

最佳答案

Sertac 指出 GetSystemMetrics 让我走上了正确的方向。 Win32 API。这让我想起了WPF的SystemParameters类,在其中我找到了 FixedFrameHorizo​​ntalBorderHeightFixedFrameVerticalBorderWidth 属性。这些正是我所需要的:

// increase size to account for frame
minMaxInfo.ptMaxPosition.x -= (int)SystemParameters.FixedFrameVerticalBorderWidth;
minMaxInfo.ptMaxPosition.y -= (int)SystemParameters.FixedFrameHorizontalBorderHeight;
minMaxInfo.ptMaxSize.x += (int)(SystemParameters.FixedFrameVerticalBorderWidth * 2);
minMaxInfo.ptMaxSize.y += (int)(SystemParameters.FixedFrameHorizontalBorderHeight * 2);

关于wpf - 处理 WM_GETMINMAXINFO 时如何考虑帧大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5351543/

相关文章:

wpf - WindowChrome ResizeBorderThickness 问题

c# - 使用 WindowChrome 复制标准系统菜单?

wpf - 如何更改默认 RadRadioButton 的前景

c# - MVVM-如何在文本框中选择文本?

wpf - Dispatcher.Run 与 Dispatcher.PushFrame

c++ - 在 C++ 上使用 GetTempFileName 函数生成随机文件名

c++ - C++ 中的 ReadFile、COM 和 NULL 字符

c# - 如何迁移到 MVVM

c++ - 如何使 WSAAsyncSelect 在应用程序控制台中启动?

wpf - wpf 中的自定义 Chrome Windows