为什么GetSystemMetrics()返回这些值? [英] Why does GetSystemMetrics() return these values?

查看:115
本文介绍了为什么GetSystemMetrics()返回这些值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在创建一个大小的客户区时遇到了一些问题。 AdjustWindowRect()将无法正常工作,所以我决定尝试手动计算窗口的宽度和高度。



这没有工作,我想知道为什么这样检查我用来考虑边界等的值。

  #include< iostream> 
#include< Windows.h>

int main(void)
{
std :: cout< GetSystemMetrics(SM_CYEDGE)=< GetSystemMetrics(SM_CYEDGE)<< std :: endl;
std :: cout<< GetSystemMetrics(SM_CXEDGE)=< GetSystemMetrics(SM_CXEDGE)< std :: endl;
std :: cout<< GetSystemMetrics(SM_CYBORDER)=< GetSystemMetrics(SM_CYBORDER)<< std :: endl;
std :: cout<< GetSystemMetrics(SM_CXBORDER)=< GetSystemMetrics(SM_CXBORDER)<< std :: endl;
std :: cout<< GetSystemMetrics(SM_CYCAPTION)=< GetSystemMetrics(SM_CYCAPTION);

std :: cin.get();
}

这给我:

  GetSystemMetrics(SM_CYBORDER)= 2 
GetSystemMetrics(SM_CXBORDER)= 2
GetSystemMetrics(SM_CYBORDER)= 1
$ b GetSystemMetrics(SM_CYCAPTION)= 22

我PRETTY确定我的窗口的边框不那薄。我做错了什么?



编辑1:



WS_OVERLAPPED样式。由于AdjustWindowRect不允许使用该样式,我构造了我想要的相同类型的窗口:(WS_BORDER | WS_CAPTION | WS_SYSMENU)。这是调用AdjustWindowRect和AdjustWindowRectEx(这一个与NULL作为扩展样式,因为我不使用任何)使用相同的样式。这给我正确的宽度,但是高度缺少几个像素。

  RECT rect = {0,0,800,600 }; 

AdjustWindowRectEx(& rect,(WS_BORDER | WS_CAPTION | WS_SYSMENU),FALSE,NULL);

CreateWindowEx(...,rect.right - rect.left,rect.bottom - rect.top,...);

这给我800像素宽的客户端区域,但只有582像素的高度。



编辑2:



CURIOUS,我用GetClientRect它给我的宽度是800,高度是600.它是怎么显示不正确?






看来,当我画了整个窗口,它都测量了。原因?

解决方案



/ div>

第一个问题是您使用了错误的指标。您需要使用SM_CXSIZEFRAME来获取可调整大小的边框的宽度。



第二个问题是Windows不会给你正确的值。 Aero上的窗口的肥边是一个严重的appcompat问题。 Windows有意识地围绕窗口矩形和边框大小。要求允许旧程序仍然正常工作,它们在CreateWindow()调用中指定窗口的大小。但这是框架的大小,包括边框。没有谎言,窗口最终会有一个太小的客户区。



要关闭谎言,你必须告诉Windows你知道关于航空行为,不需要谎报。 Project + Properties,Linker,Command Line,Additional options box and add:

  /SUBSYSTEM:CONSOLE,6.0 

版本6.0是Vista版本号,是具有Aero的Windows的第一个版本。请注意,当您这样做时,您的程序将无法在XP上运行。


I am having some issues creating a client area of a set size. AdjustWindowRect() won't work properly so I decided to try manually calculating the width and height of the window.

That didn't work either and I wondered why so I checked up the values I used to take in account the borders etc.

#include <iostream>
#include <Windows.h>

int main(void)
{
    std::cout << "GetSystemMetrics(SM_CYEDGE) = " << GetSystemMetrics(SM_CYEDGE) << std::endl;
    std::cout << "GetSystemMetrics(SM_CXEDGE) = " << GetSystemMetrics(SM_CXEDGE) << std::endl;
    std::cout << "GetSystemMetrics(SM_CYBORDER) = " << GetSystemMetrics(SM_CYBORDER) << std::endl;
    std::cout << "GetSystemMetrics(SM_CXBORDER) = " << GetSystemMetrics(SM_CXBORDER) << std::endl;
    std::cout << "GetSystemMetrics(SM_CYCAPTION) = " << GetSystemMetrics(SM_CYCAPTION);

    std::cin.get();
}

This gives me:

GetSystemMetrics(SM_CYEDGE) = 2
GetSystemMetrics(SM_CXEDGE) = 2
GetSystemMetrics(SM_CYBORDER) = 1
GetSystemMetrics(SM_CXBORDER) = 1
GetSystemMetrics(SM_CYCAPTION) = 22

I am PRETTY sure that the borders of my window aren't that thin. What am I doing wrong?

EDIT 1:

Initially my window used the WS_OVERLAPPED style. Since the AdjustWindowRect does not allow that style to be used alongside it I constructed the same type of window I wanted with: (WS_BORDER | WS_CAPTION | WS_SYSMENU). This is the same style I use during the call to AdjustWindowRect and AdjustWindowRectEx(this one with NULL as extended style since I do not use any). This gives me the correct width but the height is missing a few pixels.

RECT rect = { 0, 0, 800, 600};

AdjustWindowRectEx( &rect, (WS_BORDER | WS_CAPTION | WS_SYSMENU), FALSE, NULL);

CreateWindowEx( ..., rect.right - rect.left, rect.bottom - rect.top, ...);

This gives me 800 pixels wide client-area but only 582 pixels in height.

EDIT 2:

CURIOUS, I used GetClientRect(); and it gave me that the width is 800 and the height IS 600. How come it doesn't display properly?


It seems that when I painted the whole window it all measured up. The reason? I don't know.

Maybe someone else can shed some light over this.

解决方案

The first issue is that you use the wrong metric. You'll need to use SM_CXSIZEFRAME to get the width of a resizable border.

The second issue is that Windows won't give you the correct value. The fat borders of a window on Aero are a serious appcompat problem. Windows intentionally lies about the window rectangle and border size. Required to allow old programs to still work correctly, they specify the size of the window in the CreateWindow() call. But that's the size of the frame, including the borders. Without the lie, the window would end up with a client area that's too small.

To turn off the lie, you have to tell Windows that you know about the Aero behavior and don't need to be lied to. Project + Properties, Linker, Command Line, Additional options box and add:

/SUBSYSTEM:CONSOLE,6.0

Version 6.0 is the Vista version number, the first version of Windows that had Aero. Beware that your program won't run on XP anymore when you do this.

这篇关于为什么GetSystemMetrics()返回这些值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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