How do I find the height of the taskbar?

In my Windows application, I am trying to find the height of the taskbar. Although I can hard code this in my program, I would like to find it programmatically to support past, present (win7) and future versions of Windows.

So how would I do that?

+4
source share
5 answers

You get it from a member of GetMonitorInfo() , MONITORINFOEX.rcWork.

Get HMONITOR that you need to call this function, say MonitorFromRect (), passing in the rectangle of the window. Either MonitorFromPoint () or EnumDisplayMonitors (), depending on where you want to display your window. (0,0) is always in the upper left corner of the main monitor.

+4
source

When I searched on Google for โ€œC ++ taskbar heightโ€ I got the following result:

Here's how to get the height of the Windows taskbar using the windows functions FindWindow and GetWindowRect .

 int MyClass::getTaskBarHeight() { RECT rect; HWND taskBar = FindWindow(L"Shell_traywnd", NULL); if(taskBar && GetWindowRect(taskBar, &rect)) { return rect.bottom - rect.top; } } 

Getting the width (if the taskbar is to the left or right of the screen) can be done using:

 rect-right - rect.left 

You can check if the width exceeds the width. If the width is larger, this means that the panel is on top or bottom. Otherwise, it is located on the left or right side of the screen.

+3
source

Ask Windows about this using the message ABM_GETTASKBAR and specifying hwnd for the taskbar.

+3
source

Perhaps you want not only Taksbar, but all the other "bars" on the screen?

All you really need is SystemParametersInfo(SPI_GETWORKAREA)

SystemParametersInfo by passing SPI_GETWORKAREA as a parameter

Retrieves the size of the work area on the main display monitor. A workspace is a part of the screen that is not obscured by the system taskbar or application toolbar. The pvParam parameter should point to the RECT structure, which receives the coordinates of the work area, expressed in virtual coordinates of the screen.

+1
source

There are many methods available depending on your needs. I used EnumDisplayMonitors () since I needed to test each display to see if it has a taskbar. The way to do this:

Use EnumDisplayMonitors () to get a list of all monitors.

 MyInfoEnumProc(HMONITOR hMonitor, HDC hdcMonitor, LPRECT lprcMonitor, LPARAM dwData) 

Inside the callback, you will get a display handle. Warning: this function also lists virtual displays: Using the handle on the display, use GetMonitorInfo () with the handle on the display.

This will return the display name along with the two RECT structures to the display and resolution position, and the other RECT will be the work area. You will need to do two checks (one for X, one for Y) to see if there is a taskbar on the monitor and the height or width of the taskbar.

For example, first we check the Y axis:

 if(monitor->rcMonitor.top == monitor->rcWork.top && monitor->rcMonitor.bottom == monitor->rcWork.bottom) { std::cout << "There is no taskbar on the Y axis" << std::endl; } else { std::cout << "There is a taskbar on the Y axis" << std::endl; int height = monitor->rcMonitor.bottom - monitor->rcMonitor.top; int hieghtOfTaskbar = height - (monitor.rcWork.bottom - monitor.rcWork.top); std::cout << "The height of the taskbar is: " << heightOfTaskbar << std::endl; } 

Then we check the X axis:

 if(monitor->rcMonitor.right == monitor->rcWork.right && monitor->rcMonitor.left == monitor->rcWork.left ) { std::cout << "There is no taskbar on the X axis" << std::endl; } else { std::cout << "There is a taskbar on the X axis" << std::endl; int width = monitor->rcMonitor.left - monitor->rcMonitor.right; int widthOfTaskbar = height - (monitor.rcWork.left - monitor.rcWork.right); std::cout << "The width of the taskbar is: " << heightOfTaskbar << std::endl; } 

The height or width depending on the position of the taskbar will usually be corresponding to the height or width of the monitor, although this may not always be the case.

0
source

All Articles