在后台进程中,我想在托盘区域像气球一样显示我的短消息。但是,我不想为此添加一个托盘图标。因此,我创建了一个工具提示图标,并希望它放置在托盘附近。但是,发送TTM_UPDATETIPTEXT
, TTM_TRACKPOSITION
, TTM_TRACKACTIVATE
返回0。虽然我不确定是否应该是这种情况,但下面的代码不显示工具提示窗口,我不知道为什么:
这是代码:
// "hwnd" is the HWND to the hidden background window of my background process
HWND hTrayWnd = FindWindow(_T("Shell_TrayWnd"), NULL);
GetWindowRect(hTrayWnd, &trayPos);
HWND hwndTip = CreateWindowEx(NULL, TOOLTIPS_CLASS, NULL,
WS_POPUP | TTS_ALWAYSTIP | TTS_BALLOON,
CW_USEDEFAULT, CW_USEDEFAULT,
CW_USEDEFAULT, CW_USEDEFAULT,
hWnd, NULL, NULL, NULL);
LRESULT ret;
TOOLINFO toolInfo = { 0 };
ZeroMemory(&toolInfo, sizeof(toolInfo));
toolInfo.cbSize = sizeof(toolInfo);
toolInfo.hinst = GetModuleHandle(NULL);
toolInfo.lpszText = _T("Test Test");
toolInfo.hwnd = hWnd;
ret = SendMessage(hwndTip, TTM_SETTITLE, TTI_INFO , (LPARAM)_T("Test Title"));
这个调用返回0:
ret = SendMessage(hwndTip, TTM_UPDATETIPTEXT, 0 , (LPARAM)&toolInfo); // needs hinst, lpszText, hwnd, cbSize
这个调用也返回0:
ret = SendMessage(hwndTip, TTM_TRACKPOSITION, 0, MAKELPARAM(trayPos.left, trayPos.top));
ZeroMemory(&toolInfo, sizeof(toolInfo));
toolInfo.cbSize = sizeof(toolInfo);
toolInfo.hwnd = hWnd;
toolInfo.uId = 1;
还有这个
ret = SendMessage(hwndTip, TTM_TRACKACTIVATE, TRUE, (LPARAM)&toolInfo); // needs hwnd, uId, cbSize
工具提示窗口永远不会显示。
我还尝试使用TTM_ADDTOOL
(如评论中建议的)和我的SendMessage
调用的不同顺序,但这也返回零,没有显示工具提示:
LRESULT ret;
TOOLINFO toolInfo = { 0 };
ZeroMemory(&toolInfo, sizeof(toolInfo));
toolInfo.cbSize = sizeof(toolInfo);
toolInfo.lpszText = _T("Test Test");
toolInfo.hwnd = hWnd;
toolInfo.uId = 1;
toolInfo.rect.bottom = trayPos.bottom;
toolInfo.rect.left = trayPos.left;
toolInfo.rect.right = trayPos.right;
toolInfo.rect.top = trayPos.top;
//ret = SendMessage(hwndTip, TTM_ADDTOOL, 0, (LPARAM)&toolInfo);
ret = SendMessage(hwndTip, TTM_SETTITLE, TTI_INFO , (LPARAM)_T("Test Title"));
//ret = SendMessage(hwndTip, TTM_UPDATETIPTEXT, 0 , (LPARAM)&toolInfo); // needs hinst, lpszText, hwnd, uId, cbSize
//ret = SendMessage(hwndTip, TTM_TRACKPOSITION, 0, MAKELPARAM(trayPos.left, trayPos.top));
//ret = SendMessage(hwndTip, TTM_TRACKACTIVATE, TRUE, (LPARAM)&toolInfo); // needs hwnd, uId, cbSize
ret = SendMessage(hwndTip, TTM_ADDTOOL, 0, (LPARAM)&toolInfo);
TTM_TRACKACTIVATE
激活'跟踪工具提示',这是通过在TOOLINFO::uFlags
中设置TTF_TRACK
创建的。