Sign in to follow this  

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.

If you intended to correct an error in the post then please contact us.

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 this post


Link to post
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 this post


Link to post
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 ;-)

Share this post


Link to post
Share on other sites
Ah, I got another way!


int Width, Height
HWND hDWnd;
RECT ScreenRect;

hDWnd = GetDesktopWindow();
GetWindowRect(hDWnd, &ScreenRect);

Width = ScreenRect.right;
Height = ScreenRect.bottom;




-Stenny

Share this post


Link to post
Share on other sites
Sign in to follow this