Followers 0

# Getting desktop width and height with WinAPI

## 3 posts in this topic

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
0

##### 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).
0

##### 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 ;-)
1

##### Share on other sites
Ah, I got another way!

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

-Stenny
1

## Create an account

Register a new account