Hello,
On 8/25/06, James Liggett jrliggett@cox.net wrote:
Add support for tooltips for system tray icons.
This patch partially based on the original systray implementation by Kai Morich kai.morich@bigfoot.de.
I've been working on the simmilar patch and I want make several comments on the patch
- /* create icon tooltip */
- icon->tooltip = CreateWindowEx(WS_EX_TOPMOST, TOOLTIPS_CLASS, NULL,
WS_POPUP | TTS_NOPREFIX | TTS_ALWAYSTIP,
CW_USEDEFAULT, CW_USEDEFAULT,
CW_USEDEFAULT, CW_USEDEFAULT,
icon->window, NULL, NULL, NULL);
Why the TTS_NOPREFIX flag is needed? It doesn't seem to be used on windows.
Next, we need to set tooltip max width, primarily to enable multiline tooltips, as several applications relay on this. The code can be, just after tooltip creation: SendMessageW (icon->tooltip, TTM_SETMAXTIPWIDTH, 0, 400); On windows width value seem to be dependend on system DPI, but I haven't found the exact formula yet. 400 is value at the default 96 dpi, so it may be a good starting point.
Then my idea is to create tool just after tooltip creation, and then in modify icon just change tooltip text if requested. Not sure if it is a better idea, but it fits better into the existing code. Something like this: after tooltip creation creation: TTTOOLINFOW ti;
ZeroMemory (&ti, sizeof(TTTOOLINFOW)); ti.cbSize = sizeof(TTTOOLINFOW); ti.uFlags = TTF_SUBCLASS; ti.hwnd = icon->window; ti.hinst = 0; ti.uId = 0; ti.lpszText = NULL; GetClientRect (icon->window, &ti.rect); SendMessageW (icon->tooltip, TTM_ADDTOOLW, 0, (LPARAM)&ti);
and in modify icon: if (nid->uFlags & NIF_TIP) { TTTOOLINFOW ti;
ZeroMemory (&ti, sizeof(TTTOOLINFOW)); ti.cbSize = sizeof(TTTOOLINFOW); ti.hwnd = icon->window; ti.hinst = 0; ti.uId = 0; ti.lpszText = nid->szTip;
SendMessageW (icon->tooltip, TTM_UPDATETIPTEXTW, 0, (LPARAM)&ti); }
On Fri, 2006-08-25 at 13:00 +0300, Oleg Krylov wrote:
I've been working on the simmilar patch and I want make several comments on the patch
- /* create icon tooltip */
- icon->tooltip = CreateWindowEx(WS_EX_TOPMOST, TOOLTIPS_CLASS, NULL,
WS_POPUP | TTS_NOPREFIX | TTS_ALWAYSTIP,
CW_USEDEFAULT, CW_USEDEFAULT,
CW_USEDEFAULT, CW_USEDEFAULT,
icon->window, NULL, NULL, NULL);
Why the TTS_NOPREFIX flag is needed? It doesn't seem to be used on windows.
I got that from the example on MSDN, but I don't think it's an absolute must.
Next, we need to set tooltip max width, primarily to enable multiline tooltips, as several applications relay on this. The code can be, just after tooltip creation: SendMessageW (icon->tooltip, TTM_SETMAXTIPWIDTH, 0, 400); On windows width value seem to be dependend on system DPI, but I haven't found the exact formula yet. 400 is value at the default 96 dpi, so it may be a good starting point.
Sounds reasonable to me.
Then my idea is to create tool just after tooltip creation, and then in modify icon just change tooltip text if requested. Not sure if it is a better idea, but it fits better into the existing code. Something like this: after tooltip creation creation: TTTOOLINFOW ti;
ZeroMemory (&ti, sizeof(TTTOOLINFOW)); ti.cbSize = sizeof(TTTOOLINFOW); ti.uFlags = TTF_SUBCLASS; ti.hwnd = icon->window; ti.hinst = 0; ti.uId = 0; ti.lpszText = NULL; GetClientRect (icon->window, &ti.rect); SendMessageW (icon->tooltip, TTM_ADDTOOLW, 0, (LPARAM)&ti);
and in modify icon: if (nid->uFlags & NIF_TIP) { TTTOOLINFOW ti;
ZeroMemory (&ti, sizeof(TTTOOLINFOW)); ti.cbSize = sizeof(TTTOOLINFOW); ti.hwnd = icon->window; ti.hinst = 0; ti.uId = 0; ti.lpszText = nid->szTip; SendMessageW (icon->tooltip, TTM_UPDATETIPTEXTW, 0, (LPARAM)&ti); }
You know, I thought about doing this at first, but I decided against it because it seemed too repetitive. The way I have it now, it's only one function. I may consider doing this though; I haven't decided yet.
Thanks for your feedback, James
And BTW, the MSDN example is at http://msdn.microsoft.com/library/default.asp?url=/library/en-us/shellcc/pla...
On Fri, 2006-08-25 at 13:00 +0300, Oleg Krylov wrote:
Next, we need to set tooltip max width, primarily to enable multiline tooltips, as several applications relay on this. The code can be, just after tooltip creation: SendMessageW (icon->tooltip, TTM_SETMAXTIPWIDTH, 0, 400); On windows width value seem to be dependend on system DPI, but I haven't found the exact formula yet. 400 is value at the default 96 dpi, so it may be a good starting point.
Actually, I don't think we need this to make multiline tips work. I made a small winelib app [1] which demonstrates this. And according to the Wine headers [2] and my copy of the Platform SDK headers, the max tooltip length is 128 characters, so doing this wouldn't have much of an effect. I removed that line from my patch and it didn't seem to have any effect at all. Are you sure this is absolutely needed?
Thanks, James
Notes [1]: http://members.cox.net/~jrliggett/wine/systraytest.tar.gz [2]: http://source.winehq.org/source/include/shellapi.h#L368