[TRY 3] Add support for tooltips for system tray icons

James Liggett jrliggett at cox.net
Tue Aug 29 16:08:59 CDT 2006


Add support for tooltips for system tray icons.

Based on the original systray implementation by Kai Morich <kai.morich at bigfoot.de>.

---

 programs/explorer/Makefile.in |    2 +
 programs/explorer/systray.c   |   60 ++++++++++++++++++++++++++++++++++++-----
 2 files changed, 54 insertions(+), 8 deletions(-)

932c480fb17cc2a117a09cff7e0e8f551e55a746
diff --git a/programs/explorer/Makefile.in b/programs/explorer/Makefile.in
index 740611a..db7d6fc 100644
--- a/programs/explorer/Makefile.in
+++ b/programs/explorer/Makefile.in
@@ -4,7 +4,7 @@ SRCDIR    = @srcdir@
 VPATH     = @srcdir@
 MODULE    = explorer.exe
 APPMODE   = -mwindows
-IMPORTS   = user32 gdi32 advapi32 kernel32 ntdll
+IMPORTS   = user32 gdi32 advapi32 comctl32 kernel32 ntdll 
 EXTRADEFS = @HALINCL@
 
 C_SRCS = \
diff --git a/programs/explorer/systray.c b/programs/explorer/systray.c
index 70d29bf..22ee292 100644
--- a/programs/explorer/systray.c
+++ b/programs/explorer/systray.c
@@ -33,6 +33,7 @@
 #define UNICODE
 #define _WIN32_IE 0x500
 #include <windows.h>
+#include <commctrl.h>
 
 #include <wine/debug.h>
 #include <wine/list.h>
@@ -60,6 +61,7 @@ struct icon
     HICON          image;    /* the image to render */
     HWND           owner;    /* the HWND passed in to the Shell_NotifyIcon call */
     HWND           window;   /* the adaptor window */
+    HWND           tooltip;  /* Icon tooltip */
     UINT           id;       /* the unique id given by the app */
     UINT           callback_message;
 };
@@ -160,7 +162,26 @@ static struct icon *get_icon(HWND owner,
     return NULL;
 }
 
-static void modify_icon(const NOTIFYICONDATAW *nid)
+static void set_tooltip(struct icon *icon, WCHAR *szTip, BOOL modify)
+{
+    TTTOOLINFOW ti;
+        
+    ti.cbSize = sizeof(TTTOOLINFOW);
+    ti.uFlags = TTF_SUBCLASS | TTF_IDISHWND;
+    ti.hwnd = icon->window;
+    ti.hinst = 0;
+    ti.uId = (UINT_PTR)icon->window;  /* avoid a build warning */
+    ti.lpszText = szTip;
+    ti.lParam = 0;
+    ti.lpReserved = NULL;
+        
+    if (modify)
+        SendMessageW(icon->tooltip, TTM_UPDATETIPTEXTW, 0, (LPARAM)&ti);
+    else
+        SendMessageW(icon->tooltip, TTM_ADDTOOLW, 0, (LPARAM)&ti);
+}
+
+static void modify_icon(NOTIFYICONDATAW *nid, BOOL modify_tooltip)
 {
     struct icon    *icon;
 
@@ -186,14 +207,19 @@ static void modify_icon(const NOTIFYICON
     {
         icon->callback_message = nid->uCallbackMessage;
     }
+    
+    if (nid->uFlags & NIF_TIP)
+    {
+        set_tooltip(icon, nid->szTip, modify_tooltip);
+    }
 }
 
-static void add_icon(const NOTIFYICONDATAW *nid)
+static void add_icon(NOTIFYICONDATAW *nid)
 {
     RECT rect;
     struct icon  *icon;
     static const WCHAR adaptor_windowname[] = /* Wine System Tray Adaptor */ {'W','i','n','e',' ','S','y','s','t','e','m',' ','T','r','a','y',' ','A','d','a','p','t','o','r',0};
-
+    
     WINE_TRACE("id=0x%x, hwnd=%p\n", nid->uID, nid->hWnd);
 
     if ((icon = get_icon(nid->hWnd, nid->uID)))
@@ -226,13 +252,32 @@ static void add_icon(const NOTIFYICONDAT
                                   rect.right - rect.left,
                                   rect.bottom - rect.top,
                                   NULL, NULL, NULL, icon);
-
+    
     if (!hide_systray)
-        ShowWindow(icon->window, SW_SHOWNA);
+        ShowWindow(icon->window, SW_SHOWNA);    
+    
+    /* create icon tooltip */
+    
+    /* Register tooltip classes if this is the first icon */
+    if (!list_head(&tray.icons))
+    {
+        INITCOMMONCONTROLSEX init_tooltip;
+        
+        init_tooltip.dwSize = sizeof(INITCOMMONCONTROLSEX);
+        init_tooltip.dwICC = ICC_TAB_CLASSES;
+        
+        InitCommonControlsEx(&init_tooltip);
+    }
+    
+    icon->tooltip = CreateWindowEx(WS_EX_TOPMOST, TOOLTIPS_CLASS, NULL, 
+                                   WS_POPUP | TTS_ALWAYSTIP,
+                                   CW_USEDEFAULT, CW_USEDEFAULT, 
+                                   CW_USEDEFAULT, CW_USEDEFAULT,
+                                   icon->window, NULL, NULL, NULL);
 
     list_add_tail(&tray.icons, &icon->entry);
 
-    modify_icon(nid);
+    modify_icon(nid, FALSE);
 }
 
 static void delete_icon(const NOTIFYICONDATAW *nid)
@@ -247,6 +292,7 @@ static void delete_icon(const NOTIFYICON
         return;
     }
 
+    DestroyWindow(icon->tooltip);
     DestroyWindow(icon->window);
 }
 
@@ -304,7 +350,7 @@ static void handle_incoming(HWND hwndSou
         delete_icon(&nid);
         break;
     case NIM_MODIFY:
-        modify_icon(&nid);
+        modify_icon(&nid, TRUE);
         break;
     default:
         WINE_FIXME("unhandled tray message: %ld\n", cds->dwData);
-- 
1.2.4






More information about the wine-patches mailing list