How do you scale the title bar on a DPI aware win application?(如何在 DPI 感知 win 应用程序上缩放标题栏?)
问题描述
我通过在清单文件中设置 <dpiAware>True/PM</dpiAware>
使我的应用程序能够识别每个显示器的 dpi.我可以使用进程资源管理器验证这确实有效,或者通过调用 GetProcessDpiAwareness.
I am making my app dpi-aware per monitor by setting <dpiAware>True/PM</dpiAware>
in the manifest file. I can verify with process explorer that this is indeed working or by calling GetProcessDpiAwareness.
这一切都很好,我可以在我的代码中很好地扩展客户区域中的任何内容.但是,我唯一的问题是,如果我将我的应用程序从系统 dpi 监视器拖到非系统 dpi 监视器,标题栏和任何系统菜单都会变得太大或太小.对于大多数内置应用程序(例如 calc、edge browser 等)来说,情况并非如此,因此必须有足够的空间来正确缩放它.有人知道 MS 的开发人员是如何做到这一点的吗?
This is all working fine and I can scale anything in the client area fine in my code. However, my only problem is that if I drag my app from a system-dpi monitor to a non-system dpi monitor, the title bar and any system menu would either become too big or too small. This isn't the case for most built-in apps (e.g. calc, edge browser, etc..) so there must be away to scale it properly. Does anyone how the devs at MS did this?
下面的截图应该能更好地解释我的问题.另请注意,在缩放 (96dpi) 时,关闭、最小和最大按钮之间的填充是不同的.
The screenshot below should explain my problem better. Also notice, that the padding between the close, min, and max button is different when it's scaled (96dpi).
示例应用我附上了一个非常简单的应用,它可以感知每个显示器的 dpi.
Sample app I'm attaching a very simple app that is per-monitor dpi aware.
推荐答案
有人知道 MS 的开发人员是如何做到这一点的吗?
Does anyone how the devs at MS did this?
这有一个非常令人失望的答案.使用 Alin Constantin 的 WinCheat 并检查 Calculator 的顶级窗口,我看到窗口大小为 320x576,客户端大小为也是 320x576.
This has a pretty disappointing answer. Using Alin Constantin's WinCheat and inspecting the top-level window of Calculator, I see a window size of 320x576, and a client size that is also 320x576.
换句话说,微软通过抑制窗口的非客户区完全避免了这个问题,而是把所有东西都放在客户区.使这项工作对您来说很好可能涉及标题栏的自定义绘制.
In other words, Microsoft entirely avoids the problem by suppressing the non-client area of the window, putting everything in the client area instead. Making this work well for you may involve custom drawing of the title bar.
值得注意的是计算器和例如Windows 资源管理器不为标题栏使用相同的颜色.计算器做标题栏的自定义绘图可以完美地解释这一点.
Something worth noting is that Calculator and e.g. Windows Explorer don't use the same colour for the title bars. Calculator doing custom drawing of the title bar would explain that perfectly.
这篇关于如何在 DPI 感知 win 应用程序上缩放标题栏?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何在 DPI 感知 win 应用程序上缩放标题栏?
基础教程推荐
- 为什么语句不能出现在命名空间范围内? 2021-01-01
- 管理共享内存应该分配多少内存?(助推) 2022-12-07
- 如何“在 Finder 中显示"或“在资源管理器中显 2021-01-01
- 在 C++ 中循环遍历所有 Lua 全局变量 2021-01-01
- 为 C/C++ 中的项目的 makefile 生成依赖项 2022-01-01
- 如何在不破坏 vtbl 的情况下做相当于 memset(this, ...) 的操作? 2022-01-01
- 从 std::cin 读取密码 2021-01-01
- Windows Media Foundation 录制音频 2021-01-01
- 如何使图像调整大小以在 Qt 中缩放? 2021-01-01
- 使用从字符串中提取的参数调用函数 2022-01-01