是否有 WinAPI 函数来检索任务栏的句柄?
目的是确定任务栏停靠设置(ABE_LEFT、ABE_RIGHT、ABE_BOTTOM、ABE_TOP)。功能SHAppBarMessage
需要任务栏句柄来检索对接信息。除非有另一种方法可以确定任务栏停靠设置而不需要手柄?
我知道这种方法可以正常工作,但我不确定它是否适用于所有 Windows 版本:
HWND taskBar = FindWindow("Shell_TrayWnd", NULL);
That appears to be a documentation bug. You don't need to provide a window handle in the APPBARDATA https://msdn.microsoft.com/en-us/library/windows/desktop/bb773184.aspx structure for the ABM_GETTASKBARPOS https://msdn.microsoft.com/en-us/library/windows/desktop/bb787949.aspx when calling SHAppBarMessage https://msdn.microsoft.com/en-us/library/windows/desktop/bb762108.aspx1).
以下代码正确返回任务栏的位置(在 Windows 10 x64 上测试):
#include <shellapi.h>
#pragma comment(lib, "Shell32.lib")
#include <stdexcept>
RECT GetTaskbarPos() {
APPBARDATA abd = { 0 };
abd.cbSize = sizeof( abd );
if ( !::SHAppBarMessage( ABM_GETTASKBARPOS, &abd ) ) {
throw std::runtime_error( "SHAppBarMessage failed." );
}
return abd.rc;
}
更新:问题实际上是在询问对接枚举值。这也被返回:
#include <shellapi.h>
#pragma comment(lib, "Shell32.lib")
#include <stdexcept>
UINT GetTaskbarDockingEdge() {
APPBARDATA abd = { 0 };
abd.cbSize = sizeof( abd );
if ( !::SHAppBarMessage( ABM_GETTASKBARPOS, &abd ) ) {
throw std::runtime_error( "SHAppBarMessage failed." );
}
return abd.uEdge;
}
1) It would be awkward if you needed the well hidden window handle of the taskbar to send this message. If you had the window handle already, you could simply call GetWindowRect https://msdn.microsoft.com/en-us/library/windows/desktop/ms633519.aspx instead.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)