How detect current screen resolution?

前端 未结 7 1071
悲哀的现实
悲哀的现实 2020-11-27 04:00

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 wi

7条回答
  •  无人及你
    2020-11-27 04:16

    • 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)

提交回复
热议问题