How to get the current screen resolution in pixels

1 01 2009

Some times we need to know the screen resolution of our window. Does anybody know how to get screen size?

This could be achieved by using two Windows APIs GetDesktopWindow and GetWindowRect.

GetDesktopWindow returns a handle to the desktop window. The desktop window is the window that makes up the desktop of the computer — that is, the screen.

GetWindowRect function retrieves the window’s bounding dimensions

Please check the code snippet below.

void GetScreenResolution()
   RECT DesktopRect;
   // Gets the Desktop window
   HWND hDesktop=::GetDesktopWindow();
   // Gets the Desktop window rect or screen resolution in pixels
   ::GetWindowRect(hDesktop, &DesktopRect);



Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: