运行 Aero 时如何确定实际窗口窗体大小(包含所有非客户端元素)?

发布于 2024-12-26 14:59:41 字数 223 浏览 3 评论 0原文

我试图将我的表单精确定位在任务栏上方。不幸的是,我的努力受到以下事实的阻碍:表单上的 this.Height 返回的值比实际表单(包含所有边框、标题栏等)小 10 像素。我正在运行带 Aero 的 Windows 7。当 Aero 关闭(并且边框更细)时,一切都会按预期进行。表单边框样式为FixedSingle。我不想实施特定于 Aero 的黑客。我该怎么做才能获得正确的高度?

I'm trying to position my form precisely above the taskbar. Unfortunately my efforts are hampered by the fact that this.Height on my form returns a value which is 10 pixels smaller than the actual form (with all the borders, title bar, etc). I'm running Windows 7 with Aero. When Aero is turned off (and the borders are thinner), all works as expected. The form border style is FixedSingle. I don't want to implement Aero-specific hacks. What can I do to get the correct height?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

奶茶白久 2025-01-02 14:59:41

是的,Aero 对 GetWindowRect() 返回的窗口大小撒了谎。这是一个相当重要的应用程序兼容性技巧,如果没有它,太多程序的客户区就会太小。不幸的是,既没有 API 调用也没有清单条目可以用来消除谎言。唯一的方法是在 EXE 头中设置 Windows 版本并将其标记为 Vista 兼容。

您可以在构建后事件中使用 Editbin.exe 执行此操作:

set pathsave=%path%
set path=$(devenvdir);$(devenvdir)..\..\vc\bin
editbin.exe /subsystem:windows,6.0 "$(targetfilename)"
set path=%pathsave%

请注意,此后您的程序将不再在 XP 中运行。


更新:当您以 .NET 4.5 为目标时,现在在 VS2012 及更高版本中默认执行此操作

Yes, Aero lies about the window size returned by GetWindowRect(). It is a rather important appcompat hack, without it far too many programs would have a client area that's too small. Unfortunately there's neither an API call nor a manifest entry that can be used to turn off the lie. The only way is to set the Windows version in the EXE header and mark it Vista compatible.

You can do so with Editbin.exe in a postbuild event:

set pathsave=%path%
set path=$(devenvdir);$(devenvdir)..\..\vc\bin
editbin.exe /subsystem:windows,6.0 "$(targetfilename)"
set path=%pathsave%

Beware that your program will not run in XP anymore after this.


UPDATE: this is now done by default in VS2012 and up when you target .NET 4.5

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文