# Getting desktop width and height with WinAPI

This topic is 4077 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hello, How can I get the width and height of the desktop, with just bear-naked WinAPI? For the window's size you can use GetWindowRect, but what's the desktop's function? -Stenny

##### Share on other sites
Use GetSystemMetrics with SM_CXSCREEN and SM_CYSCREEN.

Things get a bit more complicated if you want to detect a virtual desktop with more than one monitor. If it's enough you can use SM_CXVIRTUALSCREEN and S_CYVIRTUALSCREEN (i might be off with the constants name).

##### Share on other sites
You could use either
a) GetSystemMetrics( SM_CXSCREEN ), GetSystemMetrics( SM_CYSCREEN ) OR
b) GetDeviceCaps( hDC, HORZRES ), GetDeviceCaps( hDC, VERTRES )

If you have a multi-monitor setup, there's also the notion of SM_CXVIRTUALSCREEN
and SM_CYVIRTUALSCREEN.

EDIT: beaten to it ;-)

int Width, HeightHWND hDWnd;RECT ScreenRect;hDWnd = GetDesktopWindow();GetWindowRect(hDWnd, &ScreenRect);Width = ScreenRect.right;Height = ScreenRect.bottom;