C++ Get screen resolution on active monitor

c++, winapi

Solution

Please try `GetMonitorInfo()` which gives you a `MONITORINFO`.

Details at: http://msdn.microsoft.com/en-us/library/dd144901%28v=vs.85%29.aspx

Problem

How can I get screen resolution for monitor where my C++ application currently is? I can get handle to an active monitor: ``` HMONITOR active_monitor = MonitorFromWindow(GetActiveWindow(), MONITOR_DEFAULTTONEAREST); ``` But cannot make anything out of this) I tried this: ``` HDC hdc = GetDC(GetActiveWindow()); if (hdc) { const int X = GetDeviceCaps(hdc, HORZRES); const int Y = GetDeviceCaps(hdc, VERTRES); ReleaseDC(NULL, hdc); } ``` But it did not work.. How is ot possible to get resolution for active monitor? Thanks, Zhenya

Original source