如何检测当前屏幕分辨率? [英] How detect current screen resolution?

查看:961
本文介绍了如何检测当前屏幕分辨率?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何从WINAPI(用C或C ++)检测当前的屏幕分辨率?

一些背景资料:

我想要开始一个新的OpenGL全屏窗口,但希望它与该桌面已经被设置为相同的水平和垂直尺寸中打开。 (现在,当每个人都使用液晶屏,我想这是让画面的原始分辨率的最佳方式。)

我不迫切需要也知道桌面颜色深度,尽管这将是一个不错的奖金。


解决方案

  • 主监视器的大小: GetSystemMetrics的 SM_CXSCREEN / SM_CYSCREEN(GetDeviceCaps也可使用)

  • 所有显示器的尺寸(组合):GetSystemMetrics的SM_CX / YVIRTUALSCREEN

  • 在主显示器上工作区(不包括屏幕任务栏和其他停靠栏)的大小:的 SystemParametersInfo SPI_GETWORKAREA

  • 一个特定的监视器(工作区和屏)的大小:的 GetMonitorInfo

编辑:
重要的是要记住,一个显示器并不总是开始0x0在所以只是知道大小是不够的,你的窗口的位置是非常重要的。您可以使用MonitorFromWindow找到你的显示器窗口上,然后调用GetMonitorInfo

如果你想要去低级别的路由或改变你需要使用EnumDisplayDevices,EnumDisplaySettings和ChangeDisplaySettings(这是获得刷新率AFAIK的唯一途径,但GetDeviceCaps会告诉你的颜色深度)

How do I from Winapi (in C or C++) detect the current screen resolution?

Some background:

I want to start a new OpenGL fullscreen window, but want it open with the same horizontal and vertical size which the desktop already is set to. (Now when everyone uses LCD screens, I figured this is the best way to get the native resolution of the screen.)

I don't desperately need to also know the desktop color depth, although that would be a nice bonus.

解决方案

  • Size of the primary monitor: GetSystemMetrics SM_CXSCREEN / SM_CYSCREEN (GetDeviceCaps can also be used)
  • Size of all monitors (combined): GetSystemMetrics SM_CX/YVIRTUALSCREEN
  • Size of work area (screen excluding taskbar and other docked bars) on primary monitor: SystemParametersInfo SPI_GETWORKAREA
  • Size of a specific monitor (work area and "screen"): GetMonitorInfo

Edit: It is important to remember that a monitor does not always "begin" at 0x0 so just knowing the size is not enough to position your window. You can use MonitorFromWindow to find the monitor your window is on and then call GetMonitorInfo

If you want to go the low-level route or change the resolution you need to use EnumDisplayDevices, EnumDisplaySettings and ChangeDisplaySettings (This is the only way to get the refresh rate AFAIK, but GetDeviceCaps will tell you the color depth)

这篇关于如何检测当前屏幕分辨率?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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