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.
The size of a desktop computer monitor is determined by physically measuring the screen. Using a measuring tape, start at the top-left corner and pull it diagonally to the bottom-right corner. Be sure to only measure the screen; do not include the bezel (the plastic edge) around the screen.
1440p is also called QHD (quad high definition) or WQHD (wide quad high definition) and is a display resolution that measures 2560 x 1440 pixels. This resolution is also commonly referred to as 2K (opens in new tab).
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)
When system use DPI virtualization (Vista and above) using GetSystemMetrics or GetWindowRect will fail to get the real screen resolution (you will get the virtual resolution) unless you created DPI Aware Application.
So the best option here (simple and backward compatible) is to use EnumDisplaySettings with ENUM_CURRENT_SETTINGS.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With