Index: trunk/src/VBox/Additions/WINNT/VBoxTray/VBoxDisplay.cpp
===================================================================
--- trunk/src/VBox/Additions/WINNT/VBoxTray/VBoxDisplay.cpp	(revision 34018)
+++ trunk/src/VBox/Additions/WINNT/VBoxTray/VBoxDisplay.cpp	(revision 34025)
@@ -688,5 +688,5 @@
             }
             if (waitEvent.u32EventFlagsOut & VMMDEV_EVENT_MOUSE_CAPABILITIES_CHANGED)
-                VBoxServiceReloadCursor();
+                hlpReloadCursor();
         } else
         {
Index: trunk/src/VBox/Additions/WINNT/VBoxTray/VBoxHelpers.cpp
===================================================================
--- trunk/src/VBox/Additions/WINNT/VBoxTray/VBoxHelpers.cpp	(revision 34018)
+++ trunk/src/VBox/Additions/WINNT/VBoxTray/VBoxHelpers.cpp	(revision 34025)
@@ -26,4 +26,35 @@
 #include "resource.h"
 
+
+
+/**
+ * Attempt to force Windows to reload the cursor image by attaching to the
+ * thread of the window currently under the mouse, hiding the cursor and
+ * showing it again.  This could fail to work in any number of ways (no
+ * window under the cursor, the cursor has moved to a different window while
+ * we are processing), but we just accept this, as the cursor will be reloaded
+ * at some point anyway.
+ */
+void hlpReloadCursor(void)
+{
+    POINT mousePos;
+    HWND hWin;
+    DWORD hThread, hCurrentThread;
+
+    GetCursorPos(&mousePos);
+    hWin = WindowFromPoint(mousePos);
+    if (hWin)
+    {
+        hThread = GetWindowThreadProcessId(hWin, NULL);
+        hCurrentThread = GetCurrentThreadId();
+        if (hCurrentThread != hThread)
+            AttachThreadInput(hCurrentThread, hThread, TRUE);
+    }
+    ShowCursor(false);
+    ShowCursor(true);
+    if (hWin && (hCurrentThread != hThread))
+        AttachThreadInput(hCurrentThread, hThread, FALSE);
+}
+
 static unsigned hlpNextAdjacentRectXP(RECTL *paRects, unsigned nRects, unsigned uRect)
 {
@@ -208,44 +239,66 @@
 {
     NOTIFYICONDATA niData;
+    ZeroMemory(&niData, sizeof(NOTIFYICONDATA));
     niData.cbSize = sizeof(NOTIFYICONDATA);
-    niData.uFlags = NIF_INFO;
+    niData.uFlags = NIF_INFO; /* Display a balloon notification. */
     niData.hWnd = hWnd;
     niData.uID = uID;
+    /* If not timeout set, set it to 5sec. */
+    if (uTimeout == 0)
+        uTimeout = 5000;
     niData.uTimeout = uTimeout;
+    /* If no info flag (info, warning, error) set,
+     * set it to info by default. */
     if (dwInfoFlags == 0)
         dwInfoFlags = NIIF_INFO;
     niData.dwInfoFlags = dwInfoFlags;
 
-    OSVERSIONINFO   info;
-    DWORD           dwMajorVersion = 5; /* default XP */
-
-    info.dwOSVersionInfoSize = sizeof(info);
-    if (FALSE == GetVersionEx(&info))
-        return FALSE;
-
-    if (info.dwMajorVersion >= 5)
-    {
-        niData.uFlags |= NIF_ICON;
-        if (   info.dwMajorVersion == 5
-            && info.dwMinorVersion == 1) /* WinXP */
-        {
-            //niData.dwInfoFlags = NIIF_USER; /* Use an own icon instead of the default one */
-            niData.hIcon = LoadIcon(hInst, MAKEINTRESOURCE(IDI_VIRTUALBOX));
-        }
-#ifdef BALLOON_WITH_VISTA_TOOLTIP_ICON
-        else if (info.dwMajorVersion == 6) /* Vista and up */
-        {
-            niData.dwInfoFlags = NIIF_USER | NIIF_LARGE_ICON; /* Use an own icon instead of the default one */
-            niData.hBalloonIcon = LoadIcon(hInst, MAKEINTRESOURCE(IDI_VIRTUALBOX));
-        }
-#endif
-    }
-
-    strcpy(niData.szInfo, pszMsg ? pszMsg : "");
-    strcpy(niData.szInfoTitle, pszTitle ? pszTitle : "");
+    /* Do we want to have */
+
+    /* Get running OS version. */
+    OSVERSIONINFO osInfo;
+    osInfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
+    if (FALSE == GetVersionEx(&osInfo))
+        return RTErrConvertFromWin32(GetLastError());
+
+    /* Is the current OS supported (at least WinXP) for displaying
+     * our own icon and do we actually *want* to display our own stuff? */
+    if (   osInfo.dwMajorVersion >= 5
+        && (dwInfoFlags & NIIF_INFO))
+    {
+        /* Load (or retrieve handle of) the app's icon. */
+        HICON hIcon = LoadIcon(hInst, MAKEINTRESOURCE(IDI_VIRTUALBOX));
+        if (hIcon)
+            niData.dwInfoFlags = NIIF_USER; /* Use an own notification icon. */
+
+        if (   osInfo.dwMajorVersion == 5
+            && osInfo.dwMinorVersion == 1) /* WinXP. */
+        {
+            /* Use an own icon instead of the default one. */
+            niData.hIcon = hIcon;
+        }
+        else if (osInfo.dwMajorVersion == 6) /* Vista and up. */
+        {
+            /* Use an own icon instead of the default one. */
+            niData.dwInfoFlags |= NIIF_LARGE_ICON; /* Use a  large icon if available! */
+            niData.hIcon        = hIcon;
+            niData.hBalloonIcon = hIcon;
+        }
+    }
+    else
+    {
+        /* This might be a warning, error message or a to old OS. Use the
+         * standard icons provided by Windows (if any). */
+    }
+
+    strcpy(niData.szInfo, pszMsg ? pszMsg : "-");
+    strcpy(niData.szInfoTitle, pszTitle ? pszTitle : "Information");
 
     if (!Shell_NotifyIcon(NIM_MODIFY, &niData))
-        return GetLastError();
-    return 0;
-}
-
+    {
+        DWORD dwErr = GetLastError();
+        return RTErrConvertFromWin32(dwErr);
+    }
+    return VINF_SUCCESS;
+}
+
Index: trunk/src/VBox/Additions/WINNT/VBoxTray/VBoxHelpers.h
===================================================================
--- trunk/src/VBox/Additions/WINNT/VBoxTray/VBoxHelpers.h	(revision 34018)
+++ trunk/src/VBox/Additions/WINNT/VBoxTray/VBoxHelpers.h	(revision 34025)
@@ -27,4 +27,5 @@
 #endif /* !DEBUG_DISPLAY_CHANGE */
 
+extern void hlpReloadCursor(void);
 extern void hlpResizeRect(RECTL *paRects, unsigned nRects, unsigned uPrimary, unsigned uResized, int iNewWidth, int iNewHeight);
 extern int hlpShowBalloonTip(HINSTANCE hInst, HWND hWnd, UINT uID, const char *pszMsg, const char *pszTitle, UINT uTimeout, DWORD dwInfoFlags);
Index: trunk/src/VBox/Additions/WINNT/VBoxTray/VBoxHostVersion.cpp
===================================================================
--- trunk/src/VBox/Additions/WINNT/VBoxTray/VBoxHostVersion.cpp	(revision 34018)
+++ trunk/src/VBox/Additions/WINNT/VBoxTray/VBoxHostVersion.cpp	(revision 34025)
@@ -49,7 +49,9 @@
                 _snprintf(szMsg, sizeof(szMsg), "Your guest is currently running the Guest Additions version %s. "
                                                 "We recommend updating to the latest version (%s) by choosing the "
-                                                "install option from the Devices menu.", pszGuestVersion, pszHostVersion);
+                                                "install option from the Devices menu.", "1", "2");
 
-                rc = hlpShowBalloonTip(gInstance, gToolWindow, ID_TRAYICON, szMsg, szTitle, 5000, 0);
+                rc = hlpShowBalloonTip(gInstance, gToolWindow, ID_TRAYICON,
+                                       szMsg, szTitle,
+                                       5000 /* Time to display in msec */, NIIF_INFO);
                 if (RT_FAILURE(rc))
                     Log(("VBoxTray: Guest Additions update found; however: could not show version notifier balloon tooltip! rc = %d\n", rc));
Index: trunk/src/VBox/Additions/WINNT/VBoxTray/VBoxTray.cpp
===================================================================
--- trunk/src/VBox/Additions/WINNT/VBoxTray/VBoxTray.cpp	(revision 34018)
+++ trunk/src/VBox/Additions/WINNT/VBoxTray/VBoxTray.cpp	(revision 34025)
@@ -51,7 +51,13 @@
 DWORD                 gMajorVersion;
 
+/* Global message handler prototypes. */
+int vboxTrayGlMsgTaskbarCreated(LPARAM lParam, WPARAM wParam);
+int vboxTrayGlMsgShowBalloonMsg(LPARAM lParam, WPARAM wParam);
+
 /* Prototypes */
+int vboxTrayCreateTrayIcon(void);
 VOID DisplayChangeThread(void *dummy);
 LRESULT CALLBACK VBoxToolWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);
+
 
 /* The service table. */
@@ -62,5 +68,5 @@
         VBoxDisplayInit,
         VBoxDisplayThread,
-        VBoxDisplayDestroy,
+        VBoxDisplayDestroy
     },
     {
@@ -81,5 +87,5 @@
         VBoxRestoreInit,
         VBoxRestoreThread,
-        VBoxRestoreDestroy,
+        VBoxRestoreDestroy
     },
 #endif
@@ -88,5 +94,5 @@
         VBoxVRDPInit,
         VBoxVRDPThread,
-        VBoxVRDPDestroy,
+        VBoxVRDPDestroy
     },
     {
@@ -95,11 +101,67 @@
 };
 
-static BOOL vboxTrayIconAdd()
+/* The global message table. */
+static VBOXGLOBALMESSAGE s_vboxGlobalMessageTable[] =
+{
+    /* Windows specific stuff. */
+    {
+        "TaskbarCreated",
+        vboxTrayGlMsgTaskbarCreated
+    },
+
+    /* VBoxTray specific stuff. */
+    {
+        "VBoxTrayShowBalloonMsg",
+        vboxTrayGlMsgShowBalloonMsg
+    },
+
+    {
+        NULL
+    }
+};
+
+/**
+ * Gets called whenever the Windows main taskbar
+ * get (re-)created. Nice to install our tray icon.
+ *
+ * @return  IPRT status code.
+ * @param   wParam
+ * @param   lParam
+ */
+static int vboxTrayGlMsgTaskbarCreated(LPARAM lParam, WPARAM wParam)
+{
+    return vboxTrayCreateTrayIcon();
+}
+
+/**
+ * Shows a balloon tooltip message in VBoxTray's
+ * message area in the Windows main taskbar.
+ *
+ * @return  IPRT status code.
+ * @param   wParam
+ * @param   lParam
+ */
+static int vboxTrayGlMsgShowBalloonMsg(LPARAM wParam, WPARAM lParam)
+{
+    int rc = hlpShowBalloonTip(gInstance, gToolWindow, ID_TRAYICON,
+                               (char*)wParam /* Ugly hack! */, "Foo",
+                               5000 /* Time to display in msec */, NIIF_INFO);
+    /*
+     * If something went wrong while displaying, log the message into the
+     * the release log so that the user still is being informed, at least somehow.
+     */
+    if (RT_FAILURE(rc))
+        LogRel(("VBoxTray Information: %s\n", "Foo"));
+    return rc;
+}
+
+static int vboxTrayCreateTrayIcon(void)
 {
     HICON hIcon = LoadIcon(gInstance, MAKEINTRESOURCE(IDI_VIRTUALBOX));
     if (hIcon == NULL)
     {
-        Log(("VBoxTray: Could not load tray icon, err %08X\n", GetLastError()));
-        return FALSE;
+        DWORD dwErr = GetLastError();
+        Log(("VBoxTray: Could not load tray icon, error %08X\n", dwErr));
+        return RTErrConvertFromWin32(dwErr);
     }
 
@@ -116,8 +178,10 @@
             VBOX_PRODUCT, VBOX_VERSION_MAJOR, VBOX_VERSION_MINOR, VBOX_VERSION_BUILD, VBOX_SVN_REV);
 
-    BOOL fCreated = Shell_NotifyIcon(NIM_ADD, &gNotifyIconData);
-    if (!fCreated)
-    {
-        Log(("VBoxTray: Could not create tray icon, err %08X\n", GetLastError()));
+    int rc = VINF_SUCCESS;
+    if (!Shell_NotifyIcon(NIM_ADD, &gNotifyIconData))
+    {
+        DWORD dwErr = GetLastError();
+        Log(("VBoxTray: Could not create tray icon, error = %08X\n", dwErr));
+        rc = RTErrConvertFromWin32(dwErr);
         RT_ZERO(gNotifyIconData);
     }
@@ -125,8 +189,8 @@
     if (hIcon)
         DestroyIcon(hIcon);
-    return fCreated;
-}
-
-static void vboxTrayIconRemove()
+    return rc;
+}
+
+static void vboxTrayRemoveTrayIcon()
 {
     if (gNotifyIconData.cbSize > 0)
@@ -145,5 +209,5 @@
 }
 
-static int vboxStartServices(VBOXSERVICEENV *pEnv, VBOXSERVICEINFO *pTable)
+static int vboxTrayStartServices(VBOXSERVICEENV *pEnv, VBOXSERVICEINFO *pTable)
 {
     Log(("VBoxTray: Starting services ...\n"));
@@ -209,5 +273,5 @@
 }
 
-static void vboxStopServices(VBOXSERVICEENV *pEnv, VBOXSERVICEINFO *pTable)
+static void vboxTrayStopServices(VBOXSERVICEENV *pEnv, VBOXSERVICEINFO *pTable)
 {
     if (!pEnv->hStopEvent)
@@ -242,36 +306,46 @@
 }
 
-
-/**
- * Attempt to force Windows to reload the cursor image by attaching to the
- * thread of the window currently under the mouse, hiding the cursor and
- * showing it again.  This could fail to work in any number of ways (no
- * window under the cursor, the cursor has moved to a different window while
- * we are processing), but we just accept this, as the cursor will be reloaded
- * at some point anyway.
- */
-void VBoxServiceReloadCursor(void)
-{
-    LogFlowFunc(("\n"));
-    POINT mousePos;
-    HWND hWin;
-    DWORD hThread, hCurrentThread;
-
-    GetCursorPos(&mousePos);
-    hWin = WindowFromPoint(mousePos);
-    if (hWin)
-    {
-        hThread = GetWindowThreadProcessId(hWin, NULL);
-        hCurrentThread = GetCurrentThreadId();
-        if (hCurrentThread != hThread)
-            AttachThreadInput(hCurrentThread, hThread, TRUE);
-    }
-    ShowCursor(false);
-    ShowCursor(true);
-    if (hWin && (hCurrentThread != hThread))
-        AttachThreadInput(hCurrentThread, hThread, FALSE);
-    LogFlowFunc(("exiting\n"));
-}
-
+int vboxTrayRegisterGlobalMessages(PVBOXGLOBALMESSAGE pTable)
+{
+    int rc = VINF_SUCCESS;
+    if (pTable == NULL) /* No table to register? Skip. */
+        return rc;
+    while (   pTable->pszName
+           && RT_SUCCESS(rc))
+    {
+        /* Register global accessible window messages. */
+        pTable->uMsgID = RegisterWindowMessage(TEXT(pTable->pszName));
+        if (!pTable->uMsgID)
+        {
+            DWORD dwErr = GetLastError();
+            Log(("VBoxTray: Registering global message \"%s\" failed, error = %08X\n", dwErr));
+            rc = RTErrConvertFromWin32(dwErr);
+        }
+
+        /* Advance to next table element. */
+        pTable++;
+    }
+    return rc;
+}
+
+bool vboxTrayHandleGlobalMessages(PVBOXGLOBALMESSAGE pTable, UINT uMsg,
+                                  WPARAM wParam, LPARAM lParam)
+{
+    if (pTable == NULL)
+        return false;
+    while (pTable->pszName)
+    {
+        if (pTable->uMsgID == uMsg)
+        {
+            if (pTable->pfnHandler)
+                pTable->pfnHandler(wParam, lParam);
+            return true;
+        }
+
+        /* Advance to next table element. */
+        pTable++;
+    }
+    return false;
+}
 
 void WINAPI VBoxServiceStart(void)
@@ -280,6 +354,5 @@
 
     VBOXSERVICEENV svcEnv;
-
-    DWORD status = NO_ERROR;
+    DWORD dwErr = NO_ERROR;
 
     /* Open VBox guest driver. */
@@ -293,11 +366,9 @@
     if (gVBoxDriver == INVALID_HANDLE_VALUE)
     {
-        LogRel(("VBoxTray: Could not open VirtualBox Guest Additions driver! Please install / start it first! rc = %d\n", GetLastError()));
-        status = ERROR_GEN_FAILURE;
-    }
-
-    Log(("VBoxTray: Driver Handle = %p, Status = %p\n", gVBoxDriver, status));
-
-    if (status == NO_ERROR)
+        dwErr = GetLastError();
+        LogRel(("VBoxTray: Could not open VirtualBox Guest Additions driver! Please install / start it first! Error = %08X\n", dwErr));
+    }
+
+    if (dwErr == NO_ERROR)
     {
         /* Create a custom window class. */
@@ -307,25 +378,34 @@
         windowClass.hInstance     = gInstance;
         windowClass.hCursor       = LoadCursor(NULL, IDC_ARROW);
-        windowClass.lpszClassName = "VirtualBoxTool";
+        windowClass.lpszClassName = "VBoxTrayToolWndClass";
         if (!RegisterClass(&windowClass))
-            status = GetLastError();
-    }
-
-    Log(("VBoxTray: Class st %p\n", status));
-
-    if (status == NO_ERROR)
+        {
+            dwErr = GetLastError();
+            Log(("VBoxTray: Registering invisible tool window failed, error = %08X\n", dwErr));
+        }
+    }
+
+    if (dwErr == NO_ERROR)
     {
         /* Create our (invisible) tool window. */
+        /* Note: The window name ("VBoxTrayToolWnd") and class ("VBoxTrayToolWndClass") is
+         * needed for posting globally registered messages to VBoxTray and must not be
+         * changed! Otherwise things get broken! */
         gToolWindow = CreateWindowEx(WS_EX_TOOLWINDOW | WS_EX_TRANSPARENT | WS_EX_TOPMOST,
-                                     "VirtualBoxTool", "VirtualBoxTool",
+                                     "VBoxTrayToolWndClass", "VBoxTrayToolWnd",
                                      WS_POPUPWINDOW,
                                      -200, -200, 100, 100, NULL, NULL, gInstance, NULL);
         if (!gToolWindow)
-            status = GetLastError();
+        {
+            dwErr = GetLastError();
+            Log(("VBoxTray: Creating invisible tool window failed, error = %08X\n", dwErr));
+        }
         else
-            VBoxServiceReloadCursor();
-    }
-
-    Log(("VBoxTray: Window Handle = %p, Status = %p\n", gToolWindow, status));
+        {
+            hlpReloadCursor();
+        }
+    }
+
+    Log(("VBoxTray: Window Handle = %p, Status = %p\n", gToolWindow, dwErr));
 
     OSVERSIONINFO info;
@@ -334,14 +414,14 @@
     if (GetVersionEx(&info))
     {
-        Log(("VBoxTray: Windows version major %d minor %d\n", info.dwMajorVersion, info.dwMinorVersion));
+        Log(("VBoxTray: Windows version %ld.%ld\n", info.dwMajorVersion, info.dwMinorVersion));
         gMajorVersion = info.dwMajorVersion;
     }
 
-    if (status == NO_ERROR)
+    if (dwErr == NO_ERROR)
     {
         gStopSem = CreateEvent(NULL, TRUE, FALSE, NULL);
         if (gStopSem == NULL)
         {
-            Log(("VBoxTray: CreateEvent for Stopping failed: rc = %d\n", GetLastError()));
+            Log(("VBoxTray: CreateEvent for stopping VBoxTray failed, error = %08X\n", GetLastError()));
             return;
         }
@@ -358,5 +438,5 @@
         ret = SetSecurityDescriptorDacl(SecAttr.lpSecurityDescriptor, TRUE, 0, FALSE);
         if (!ret)
-            Log(("VBoxTray: SetSecurityDescriptorDacl failed with %d\n", GetLastError()));
+            Log(("VBoxTray: SetSecurityDescriptorDacl failed with error = %08X\n", GetLastError()));
 
         /* For Vista and up we need to change the integrity of the security descriptor too */
@@ -383,13 +463,13 @@
                                                                                   SDDL_REVISION_1, &pSD, NULL);
                     if (!ret)
-                        Log(("VBoxTray: ConvertStringSecurityDescriptorToSecurityDescriptorA failed with %d\n", GetLastError()));
+                        Log(("VBoxTray: ConvertStringSecurityDescriptorToSecurityDescriptorA failed with error = %08X\n", GetLastError()));
 
                     ret = GetSecurityDescriptorSacl(pSD, &fSaclPresent, &pSacl, &fSaclDefaulted);
                     if (!ret)
-                        Log(("VBoxTray: GetSecurityDescriptorSacl failed with %d\n", GetLastError()));
+                        Log(("VBoxTray: GetSecurityDescriptorSacl failed with error = %08X\n", GetLastError()));
 
                     ret = SetSecurityDescriptorSacl(SecAttr.lpSecurityDescriptor, TRUE, pSacl, FALSE);
                     if (!ret)
-                        Log(("VBoxTray: SetSecurityDescriptorSacl failed with %d\n", GetLastError()));
+                        Log(("VBoxTray: SetSecurityDescriptorSacl failed with error = %08X\n", GetLastError()));
                 }
             }
@@ -401,5 +481,5 @@
             if (ghSeamlessNotifyEvent == NULL)
             {
-                Log(("VBoxTray: CreateEvent for Seamless failed: rc = %d\n", GetLastError()));
+                Log(("VBoxTray: CreateEvent for Seamless failed, error = %08X\n", GetLastError()));
                 return;
             }
@@ -414,5 +494,5 @@
 
     /* initializes disp-if to default (XPDM) mode */
-    status = VBoxDispIfInit(&svcEnv.dispIf);
+    dwErr = VBoxDispIfInit(&svcEnv.dispIf);
 #ifdef VBOX_WITH_WDDM
     /*
@@ -422,22 +502,22 @@
 #endif
 
-    if (status == NO_ERROR)
-    {
-        int rc = vboxStartServices(&svcEnv, vboxServiceTable);
-
+    if (dwErr == NO_ERROR)
+    {
+        int rc = vboxTrayStartServices(&svcEnv, vboxServiceTable);
         if (RT_FAILURE (rc))
         {
-            status = ERROR_GEN_FAILURE;
+            dwErr = ERROR_GEN_FAILURE;
         }
     }
 
     /* terminate service if something went wrong */
-    if (status != NO_ERROR)
-    {
-        vboxStopServices(&svcEnv, vboxServiceTable);
+    if (dwErr != NO_ERROR)
+    {
+        vboxTrayStopServices(&svcEnv, vboxServiceTable);
         return;
     }
 
-    if (   vboxTrayIconAdd()
+    int rc = vboxTrayCreateTrayIcon();
+    if (   RT_SUCCESS(rc)
         && gMajorVersion >= 5) /* Only for W2K and up ... */
     {
@@ -450,4 +530,5 @@
     }
 
+    /* Do the Shared Folders auto-mounting stuff. */
     VBoxSharedFoldersAutoMount();
 
@@ -510,9 +591,9 @@
     Log(("VBoxTray: Returned from main loop, exiting ...\n"));
 
-    vboxTrayIconRemove();
+    vboxTrayRemoveTrayIcon();
 
     Log(("VBoxTray: Waiting for display change thread ...\n"));
 
-    vboxStopServices(&svcEnv, vboxServiceTable);
+    vboxTrayStopServices(&svcEnv, vboxServiceTable);
 
     Log(("VBoxTray: Destroying tool window ...\n"));
@@ -521,5 +602,5 @@
     DestroyWindow(gToolWindow);
 
-    UnregisterClass("VirtualBoxTool", gInstance);
+    UnregisterClass("VBoxTrayToolWndClass", gInstance);
 
     CloseHandle(gVBoxDriver);
@@ -540,11 +621,11 @@
     /* Do not use a global namespace ("Global\\") for mutex name here, will blow up NT4 compatibility! */
     HANDLE hMutexAppRunning = CreateMutex(NULL, FALSE, "VBoxTray");
-    if (   (hMutexAppRunning != NULL)
-        && (GetLastError() == ERROR_ALREADY_EXISTS))
-    {
-      /* Close the mutex for this application instance. */
-      CloseHandle (hMutexAppRunning);
-      hMutexAppRunning = NULL;
-      return 0;
+    if (   hMutexAppRunning != NULL
+        && GetLastError() == ERROR_ALREADY_EXISTS)
+    {
+        /* Close the mutex for this application instance. */
+        CloseHandle (hMutexAppRunning);
+        hMutexAppRunning = NULL;
+        return 0;
     }
 
@@ -565,5 +646,6 @@
 
     /* Release instance mutex. */
-    if (hMutexAppRunning != NULL) {
+    if (hMutexAppRunning != NULL)
+    {
         CloseHandle(hMutexAppRunning);
         hMutexAppRunning = NULL;
@@ -577,29 +659,30 @@
  * Window procedure for our tool window
  */
-LRESULT CALLBACK VBoxToolWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
-{
-    static UINT s_uTaskbarCreated = 0;
-
-    switch (msg)
+LRESULT CALLBACK VBoxToolWndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
+{
+    switch (uMsg)
     {
         case WM_CREATE:
+        {
             Log(("VBoxTray: Tool window created\n"));
-            s_uTaskbarCreated = RegisterWindowMessage(TEXT("TaskbarCreated"));
-            if (!s_uTaskbarCreated)
-                Log(("VBoxTray: Cannot register message \"TaskbarCreated\"! Error = %ld\n", GetLastError()));
-            break;
+
+            int rc = vboxTrayRegisterGlobalMessages(&s_vboxGlobalMessageTable[0]);
+            if (RT_FAILURE(rc))
+                Log(("VBoxTray: Error registering global window messages, rc=%Rrc\n", rc));
+            return 0;
+        }
 
         case WM_CLOSE:
-            break;
+            return 0;
 
         case WM_DESTROY:
             Log(("VBoxTray: Tool window destroyed\n"));
             KillTimer(gToolWindow, TIMERID_VBOXTRAY_CHECK_HOSTVERSION);
-            break;
+            return 0;
 
         case WM_TIMER:
             switch (wParam)
             {
-                case WM_VBOXTRAY_CHECK_HOSTVERSION:
+                case TIMERID_VBOXTRAY_CHECK_HOSTVERSION:
                     if (RT_SUCCESS(VBoxCheckHostVersion()))
                     {
@@ -612,6 +695,5 @@
                     break;
             }
-
-            break;
+            break; /* Make sure other timers get processed the usual way! */
 
         case WM_VBOXTRAY_TRAY_ICON:
@@ -624,35 +706,39 @@
                     break;
             }
-            break;
+            return 0;
 
         case WM_VBOX_INSTALL_SEAMLESS_HOOK:
             VBoxSeamlessInstallHook();
-            break;
+            return 0;
 
         case WM_VBOX_REMOVE_SEAMLESS_HOOK:
             VBoxSeamlessRemoveHook();
-            break;
+            return 0;
 
         case WM_VBOX_SEAMLESS_UPDATE:
             VBoxSeamlessCheckWindows();
-            break;
+            return 0;
 
         case WM_VBOXTRAY_VM_RESTORED:
             VBoxRestoreSession();
-            break;
+            return 0;
 
         case WM_VBOXTRAY_VRDP_CHECK:
             VBoxRestoreCheckVRDP();
-            break;
+            return 0;
 
         default:
 
-            if(msg == s_uTaskbarCreated)
-            {
-                Log(("VBoxTray: Taskbar (re-)created, installing tray icon ...\n"));
-                vboxTrayIconAdd();
-            }
-            break;
-    }
-    return DefWindowProc(hwnd, msg, wParam, lParam);
-}
+            /* Handle all globally registered window messages. */
+            if (vboxTrayHandleGlobalMessages(&s_vboxGlobalMessageTable[0], uMsg,
+                                             wParam, lParam))
+            {
+                return 0; /* We handled the message. @todo Add return value!*/
+            }
+            break; /* We did not handle the message, dispatch to DefWndProc. */
+    }
+
+    /* Only if message was *not* handled by our switch above, dispatch
+     * to DefWindowProc. */
+    return DefWindowProc(hWnd, uMsg, wParam, lParam);
+}
Index: trunk/src/VBox/Additions/WINNT/VBoxTray/VBoxTray.h
===================================================================
--- trunk/src/VBox/Additions/WINNT/VBoxTray/VBoxTray.h	(revision 34018)
+++ trunk/src/VBox/Additions/WINNT/VBoxTray/VBoxTray.h	(revision 34025)
@@ -44,5 +44,4 @@
  */
 #define WM_VBOXTRAY_TRAY_ICON                   WM_APP + 40
-#define WM_VBOXTRAY_TRAY_DISPLAY_BALLOON        WM_APP + 41
 /**
  * VM/VMMDev related messsages.
@@ -53,12 +52,8 @@
  */
 #define WM_VBOXTRAY_VRDP_CHECK                  WM_APP + 301
-/**
- * Misc. utility functions.
- */
-#define WM_VBOXTRAY_CHECK_HOSTVERSION           WM_APP + 1000
 
 
 /* The tray icon's ID. */
-#define ID_TRAYICON                     2000
+#define ID_TRAYICON                             2000
 
 
@@ -87,16 +82,27 @@
 
     /* Variables. */
-    HANDLE hThread;
-    void  *pInstance;
-    bool   fStarted;
-
+    HANDLE   hThread;
+    void    *pInstance;
+    bool     fStarted;
 } VBOXSERVICEINFO;
 
+/* Globally unique (system wide) message registration. */
+typedef struct _VBOXGLOBALMESSAGE
+{
+    /** Message name. */
+    char    *pszName;
+    /** Function pointer for handling the message. */
+    int      (* pfnHandler)          (LPARAM lParam, WPARAM wParam);
+
+    /* Variables. */
+
+    /** Message ID;
+     *  to be filled in when registering the actual message. */
+    UINT     uMsgID;
+} VBOXGLOBALMESSAGE, *PVBOXGLOBALMESSAGE;
 
 extern HWND         gToolWindow;
 extern HINSTANCE    gInstance;
 
-extern void VBoxServiceReloadCursor(void);
-
 #endif /* !___VBOXTRAY_H */
 
