views:

75

answers:

3

In my windows application, I am trying to find the height of the task bar. While I can hard program this into my program, I would like to find it programmatically to support past, present (win7) and future windows versions.

So, how would I do this?

+2  A: 

By searching google for "height of taskbar c++:, I got the following result.

From http://ahackersnotes.com/c/get-the-height-or-width-of-the-windows-taskbar-using-c.html

QUOTE: "Here’s how to get the height of the Windows task bar 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 (should the task bar be on the left or right of the screen) can be done using:

rect-right - rect.left"

EDIT: You may want to check if the width is greater than the height. If the width is greater, this means the bar is at the top or bottom. Otherwise, it is on the left/right side of the screen.

muntoo
There could be multiple task bars. Or none if the window is not displayed on the primary monitor. This is not a good approach.
Hans Passant
This seems like the easiest approach. I am not concerned with multiple monitors or anything unlikely at the moment.
Alexander Rafferty
+3  A: 

You get it from GetMonitorInfo(), MONITORINFOEX.rcWork. Get the HMONITOR from, say, MonitorFromRect(), passing your window rectangle. Or MonitorFromPoint() or EnumDisplayMonitors(), depends where you want to display your window. (0,0) is always the upper left corner of the primary monitor.

Hans Passant
+1  A: 

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

Franci Penov