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.
source share