在我的Windows应用程序中,我试图找到任务栏的高度。虽然我可以很难将其编程到我的程序中,但我希望通过编程来支持过去,现在(win7)和未来的Windows版本。我如何找到任务栏的高度?
那么,我该怎么做呢?
在我的Windows应用程序中,我试图找到任务栏的高度。虽然我可以很难将其编程到我的程序中,但我希望通过编程来支持过去,现在(win7)和未来的Windows版本。我如何找到任务栏的高度?
那么,我该怎么做呢?
你从GetMonitorInfo()
,MONITORINFOEX.rcWork成员得到它。
获取您需要调用此函数的HMONITOR,例如MonitorFromRect(),传递您的窗口矩形。或者MonitorFromPoint()或EnumDisplayMonitors(),取决于你想要显示窗口的位置。 (0,0)始终是主监视器的左上角。
通过对"height of taskbar c++"谷歌搜索,我得到了以下结果:
下面介绍如何使用Windows函数
FindWindow
和GetWindowRect
获得Windows任务栏的高度。int MyClass::getTaskBarHeight() { RECT rect; HWND taskBar = FindWindow(L"Shell_traywnd", NULL); if(taskBar && GetWindowRect(taskBar, &rect)) { return rect.bottom - rect.top; } }
获取宽度(应在任务栏在左侧或 屏幕的右侧)是可以做到用:
rect-right - rect.left
您可能要检查如果宽度更大比身高。如果宽度较大,则表示该栏位于顶部或底部。否则,它位于屏幕的左侧/右侧。
使用ABM_GETTASKBAR消息询问Windows,并指定任务栏的hwnd。
也许,您不仅需要Taksbar,还需要屏幕上的所有其他“酒吧”?
所有你真正需要的是SystemParametersInfo(SPI_GETWORKAREA)
SystemParametersInfo,路过SPI_GETWORKAREA作为参数
检索主显示屏上的工作区域的大小。 工作区是屏幕上未被系统 任务栏或应用程序桌面工具栏遮挡的部分。 pvParam参数必须指向一个RECT结构,该结构接收工作区域的坐标,以虚拟屏幕坐标表示。
根据您的需要有很多方法。我根据需要使用EnumDisplayMonitors()来测试每个显示器以查看它是否有任务栏。这样做的方法是:
使用EnumDisplayMonitors()获取所有监视器的列表。
MyInfoEnumProc(HMONITOR hMonitor, HDC hdcMonitor, LPRECT lprcMonitor, LPARAM dwData)
在回调里面会给你一个显示的句柄。 警告此功能也会枚举虚拟显示器:使用显示器的手柄,使用带显示器手柄的GetMonitorInfo()。
这将返回显示名称以及两个RECT结构之一的显示位置和分辨率,另一个RECT将作为工作区域。您需要执行两次检查(一个用于X,一个用于Y),以查看显示器上是否有任务栏以及任务栏的高度或宽度。
例如首先,我们检查在Y轴:
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;
}
然后我们检查X轴:
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;
}
的高度或宽度,取决于位置,任务栏通常是高度或显示器的宽度,尽管情况可能并非总是如此。
可能有多个任务栏。或者如果窗口没有显示在主监视器上,则无。这不是一个好方法。 – 2010-09-05 00:59:16
这似乎是最简单的方法。我不关心多个显示器或目前不太可能。 – 2010-09-05 01:50:45
这是一个无证黑客。 – 2016-02-21 22:51:03