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

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

问题描述

我如何从 Winapi(在 C 或 C++ 中)检测当前屏幕分辨率?

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

一些背景:

我想启动一个新的 OpenGL 全屏窗口,但希望它以桌面已设置的相同水平和垂直大小打开.(现在大家都用 LCD 屏幕,我觉得这是获得屏幕原始分辨率的最好方法.)

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.

推荐答案

  • 主监视器的大小:GetSystemMetrics SM_CXSCREEN/SM_CYSCREEN(也可以使用 GetDeviceCaps)
  • 所有监视器的大小(组合):GetSystemMetrics SM_CX/YVIRTUALSCREEN
  • 主监视器上的工作区大小(不包括任务栏和其他停靠栏的屏幕):系统参数信息 SPI_GETWORKAREA
  • 特定监视器的大小(工作区和屏幕"):GetMonitorInfo
    • 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
    • 重要的是要记住,监视器并不总是从 0x0开始",因此仅知道大小不足以定位您的窗口.您可以使用 MonitorFromWindow 找到您的窗口所在的监视器,然后调用 GetMonitorInfo

      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

      如果你想走低级路线或改变分辨率,你需要使用 EnumDisplayDevices、EnumDisplaySettings 和 ChangeDisplaySettings(这是获得刷新率 AFAIK 的唯一方法,但 GetDeviceCaps 会告诉你颜色深度)

      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天全站免登陆