形式讲述在Windows 8上错误的大小 - 如何让真正的大小? [英] Form tells wrong size on Windows 8 - how to get real size?

查看:192
本文介绍了形式讲述在Windows 8上错误的大小 - 如何让真正的大小?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有一个WinForms设置为可调整大小在Windows 8中,的 DesktopBounds 属性告诉正确的值:

Having a WinForms form with form border style set to Sizable on Windows 8, the DesktopBounds property tells the correct values:

相反,具有 FixedDialog 的形式边框样式时,该值是错误的:

In contrast, when having a form border style of FixedDialog, the values are wrong:

在Windows XP中,值始终是正确的:

On Windows XP, the values are always correct:

我的问题是:

如何获得一个窗口的实际大小,包括完整的非客户区?

How to get the real size of a Window including the complete non-client area?

更新1:

似乎是关系到这太问题。我会尝试,看看这是否会解决我的问题也在这里。

Seems that it is related to this SO question. I'll try and see whether this would solve my issue here, too.

更新2:

只是为了完整性,这里有来自VMware的Windows 7的结果:

Just for completeness, here are the results from a VMware Windows 7:

更新3:

终于找到,其中包括使用的 DwmGetWindowAttribute 功能一起的 DWMWA_EXTENDED_FRAME_BOUNDS 。我会后下面的答案。

Finally found a solution which involves using the DwmGetWindowAttribute function together with the DWMWA_EXTENDED_FRAME_BOUNDS value. I'll post an answer below.

推荐答案

要回答我的问题,我终于发现,其中包括使用的 DwmGetWindowAttribute 功能一起的 DWMWA_EXTENDED_FRAME_BOUNDS

To answer my own question, I finally found a solution which involves using the DwmGetWindowAttribute function together with the DWMWA_EXTENDED_FRAME_BOUNDS value

答案的灵感来自于<一href="https://$c$c.google.com/p/zscreen/source/browse/trunk/ZScreenLib/Global/GraphicsCore.cs?r=1349"相对=nofollow>这个来源$ C ​​$ C 其中presents功能,似乎工作的所有系统。其核心是一个功能

The answer was inspired by this source code which presents a function that seems to work on all system. The core is a function

public static Rectangle GetWindowRectangle(IntPtr handle)
{
    if (Environment.OSVersion.Version.Major < 6)
    {
        return GetWindowRect(handle);
    }
    else
    {
        Rectangle rectangle;
        return DWMWA_EXTENDED_FRAME_BOUNDS(handle, out rectangle) 
                   ? rectangle 
                   : GetWindowRect(handle);
    }
}

下面是的code 的全引擎收录。

这篇关于形式讲述在Windows 8上错误的大小 - 如何让真正的大小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆