How to get the size of the screen, without the taskbar?

I'm pretty surprised that it seems like no one has asked this question before. So how do you get the RECT of the monitor, without the taskbar? This
1
2
RECT rcScreen;
GetWindowRect(GetDesktopWindow(), &rcScreen);

Gets the RECT of the screen with it, but how do you get it without?
Just get the height of the taskbar and subtract it from the height of the screen.
http://stackoverflow.com/questions/3644531/how-would-i-find-the-height-of-the-task-bar
closed account (E0p9LyTq)
Are you wanting the size of the window's client area?

Use the GetClientRect() API function.
https://msdn.microsoft.com/en-us/library/windows/desktop/ms633503%28v=vs.85%29.aspx

The size of a window is more than just the client area + the caption area/title bar. There is the size of:

1. if present the menu bar

2. the size/thickness of the window frame, x 2. (top and bottom, left and right). This can vary depending of the window is sizable or static sized.

3. if present the size of the scroll bar, horizontal and vertical

4. if present the size/thickness of a 3D border.

5. if present the size of toolbars, dockable or static.

6. if present the size of a status bar.

There might be other non-client parts of a window I forgot, the 6 I mentioned are the most common that change the size of the client area.

To find out the usable area of the desktop window you use the GetSystemMetrics() API function with SM_CXFULLSCREEN and SM_CYFULLSCREEN. SM_CYFULLSCREEN would return the height of the desktop without the height of the taskbar, if the taskbar is at the bottom or top of the desktop. Some people move their taskbar to the left or right of the screen.
https://msdn.microsoft.com/en-us/library/windows/desktop/ms724385%28v=vs.85%29.aspx
Last edited on
closed account (E0p9LyTq)
To obtain the size of the desktop (the work area), without just the taskbar, you can use GetSystemMetrics() API function.
https://msdn.microsoft.com/en-us/library/windows/desktop/ms724385%28v=vs.85%29.aspx

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#include <iostream>
#include <windows.h>

int main()
{
   // size of screen (primary monitor) without taskbar or desktop toolbars
   std::cout << GetSystemMetrics(SM_CXFULLSCREEN) << " x " << GetSystemMetrics(SM_CYFULLSCREEN) << "\n";

   // size of screen (primary monitor) without just the taskbar
   RECT xy;
   BOOL fResult = SystemParametersInfo(SPI_GETWORKAREA, 0, &xy, 0);
   std::cout << xy.right - xy.left << " x " << xy.bottom - xy.top << "\n";

   // the full width and height of the screen (primary monitor)
   std::cout << GetDeviceCaps(GetDC(NULL), HORZRES) << " x " << GetDeviceCaps(GetDC(NULL), VERTRES) << "\n";
}
Topic archived. No new replies allowed.