3

In a background process I want to display I short message like a balloon in the tray area. However, I do not want to add a tray icon just for that. Hence I create a tooltip icon and want it to place near the tray. However, sending TTM_UPDATETIPTEXT, TTM_TRACKPOSITION, TTM_TRACKACTIVATE returns 0. While I am not sure if this should be the case or not, the following code does not show the tooltip window and I don't know why:

This is the code:

// "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"));

This call returns zero:

ret = SendMessage(hwndTip, TTM_UPDATETIPTEXT, 0 , (LPARAM)&toolInfo); // needs hinst, lpszText, hwnd, cbSize

This call returns zero too:

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;

And this too:

ret = SendMessage(hwndTip, TTM_TRACKACTIVATE, TRUE, (LPARAM)&toolInfo); // needs hwnd, uId, cbSize

And the tooltip window is never shown.

I also tried to use TTM_ADDTOOL (as suggested in a comment) ad different order of my SendMessage calls but this too returns zero and no tooltip is shown:

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);
divB
  • 896
  • 1
  • 11
  • 28
  • 1
    Unrelated to your question, but you seem to be somewhat confused about populating the [TOOLINFO structure](https://msdn.microsoft.com/en-us/library/windows/desktop/bb760256.aspx). There's no need to set the `hinst` member, unless you specify a string resource identifier for `lpszText` (which you aren't). Zeroing the structure twice is awkward as well. – IInspectable May 15 '15 at 06:57
  • Thanks for the hint. Actually, I am not sure if `TTM_UPDATETIPTEXT`, `TTM_TRACKPOSITION`, `TTM_TRACKACTIVATE` should even return non-zero in the first place. In any case, the code shown does not show the tooltip ... I updated the question. – divB May 15 '15 at 07:24
  • 1
    Do you ever use `TTM_ADDTOOL` to add the tooltip to the control? – andlabs May 15 '15 at 14:04
  • No, but I do **not** want to attach it to a control! I want to "simulate" a balloon in the tray without a tray icon, so just TTM_TRACKACTIVATE should do the job to my understanding ... – divB May 16 '15 at 00:40
  • 1
    By "to the control" I meant "to the tooltip control"; you can't `TTM_TRACKACTIVATE` to a tooltip that can't be identified. You don't need to attach your tooltip to a control, but you do need to register it. Don't specify `TTF_IDISHWND`, set `uId` to some integer that will be used to identify the tool, and set `hwnd` to your application's main window (I think). – andlabs May 16 '15 at 01:20
  • Thanks - I tried sending `TTM_ADDTOOL` before and after it but still no change. I changed the posting accordingly. – divB May 18 '15 at 08:00

1 Answers1

0

TTM_TRACKACTIVATE activates a 'tracking tooltip', which is created by setting TTF_TRACK in TOOLINFO::uFlags.

javs
  • 798
  • 10
  • 28