Index: trunk/src/VBox/Additions/WINNT/VBoxTray/Makefile.kmk
===================================================================
--- trunk/src/VBox/Additions/WINNT/VBoxTray/Makefile.kmk	(revision 33951)
+++ trunk/src/VBox/Additions/WINNT/VBoxTray/Makefile.kmk	(revision 33966)
@@ -36,5 +36,5 @@
 	VBoxVRDP.cpp \
 	VBoxRestore.cpp \
-	helpers.cpp \
+	VBoxHelpers.cpp \
 	VBoxTray.rc
 ifdef VBOX_WITH_GUEST_PROPS
Index: trunk/src/VBox/Additions/WINNT/VBoxTray/VBoxClipboard.cpp
===================================================================
--- trunk/src/VBox/Additions/WINNT/VBoxTray/VBoxClipboard.cpp	(revision 33951)
+++ trunk/src/VBox/Additions/WINNT/VBoxTray/VBoxClipboard.cpp	(revision 33966)
@@ -18,5 +18,5 @@
 
 #include "VBoxTray.h"
-#include "helpers.h"
+#include "VBoxHelpers.h"
 
 #include <VBox/HostServices/VBoxClipboardSvc.h>
Index: trunk/src/VBox/Additions/WINNT/VBoxTray/VBoxDisplay.cpp
===================================================================
--- trunk/src/VBox/Additions/WINNT/VBoxTray/VBoxDisplay.cpp	(revision 33951)
+++ trunk/src/VBox/Additions/WINNT/VBoxTray/VBoxDisplay.cpp	(revision 33966)
@@ -18,4 +18,5 @@
 #include <windows.h>
 #include "VBoxTray.h"
+#include "VBoxHelpers.h"
 #include "VBoxSeamless.h"
 #include <VBoxHook.h>
@@ -23,5 +24,4 @@
 #include <VBox/VMMDev.h>
 #include <iprt/assert.h>
-#include "helpers.h"
 #include <malloc.h>
 #include <VBoxGuestInternal.h>
@@ -367,9 +367,9 @@
         && paDeviceModes[Id].dmBitsPerPel == BitsPerPixel)
     {
-        Log(("VBoxTray: ResizeDisplayDevice: Already at desired resolution.\n"));
+        Log(("VBoxTray: ResizeDisplayDevice: Already at desired resolution\n"));
         return FALSE;
     }
 
-    resizeRect(paRects, NumDevices, DevPrimaryNum, Id, Width, Height);
+    hlpResizeRect(paRects, NumDevices, DevPrimaryNum, Id, Width, Height);
 #ifdef Log
     for (i = 0; i < NumDevices; i++)
Index: trunk/src/VBox/Additions/WINNT/VBoxTray/VBoxHelpers.cpp
===================================================================
--- trunk/src/VBox/Additions/WINNT/VBoxTray/VBoxHelpers.cpp	(revision 33966)
+++ trunk/src/VBox/Additions/WINNT/VBoxTray/VBoxHelpers.cpp	(revision 33966)
@@ -0,0 +1,251 @@
+/** @file
+ * helpers - Guest Additions Service helper functions
+ */
+
+/*
+ * Copyright (C) 2006-2010 Oracle Corporation
+ *
+ * This file is part of VirtualBox Open Source Edition (OSE), as
+ * available from http://www.virtualbox.org. This file is free software;
+ * you can redistribute it and/or modify it under the terms of the GNU
+ * General Public License (GPL) as published by the Free Software
+ * Foundation, in version 2 as it comes in the "COPYING" file of the
+ * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
+ * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
+ */
+
+#include <malloc.h>
+#include <windows.h>
+
+#include <iprt/string.h>
+#include <VBox/VBoxGuestLib.h>
+
+#include <VBoxGuestInternal.h>
+
+#include "VBoxHelpers.h"
+#include "resource.h"
+
+static unsigned hlpNextAdjacentRectXP(RECTL *paRects, unsigned nRects, unsigned uRect)
+{
+    unsigned i;
+    for (i = 0; i < nRects; i++)
+    {
+        if (paRects[uRect].right == paRects[i].left)
+            return i;
+    }
+    return ~0;
+}
+
+static unsigned hlpNextAdjacentRectXN(RECTL *paRects, unsigned nRects, unsigned uRect)
+{
+    unsigned i;
+    for (i = 0; i < nRects; i++)
+    {
+        if (paRects[uRect].left == paRects[i].right)
+            return i;
+    }
+    return ~0;
+}
+
+static unsigned hlpNextAdjacentRectYP(RECTL *paRects, unsigned nRects, unsigned uRect)
+{
+    unsigned i;
+    for (i = 0; i < nRects; i++)
+    {
+        if (paRects[uRect].bottom == paRects[i].top)
+            return i;
+    }
+    return ~0;
+}
+
+static unsigned hlpNextAdjacentRectYN(RECTL *paRects, unsigned nRects, unsigned uRect)
+{
+    unsigned i;
+    for (i = 0; i < nRects; i++)
+    {
+        if (paRects[uRect].top == paRects[i].bottom)
+            return i;
+    }
+    return ~0;
+}
+
+void hlpResizeRect(RECTL *paRects, unsigned nRects, unsigned uPrimary,
+                   unsigned uResized, int iNewWidth, int iNewHeight)
+{
+    DDCLOG(("nRects %d, iPrimary %d, iResized %d, NewWidth %d, NewHeight %d\n", nRects, uPrimary, uResized, iNewWidth, iNewHeight));
+
+    RECTL *paNewRects = (RECTL *)alloca (sizeof (RECTL) * nRects);
+    memcpy (paNewRects, paRects, sizeof (RECTL) * nRects);
+    paNewRects[uResized].right += iNewWidth - (paNewRects[uResized].right - paNewRects[uResized].left);
+    paNewRects[uResized].bottom += iNewHeight - (paNewRects[uResized].bottom - paNewRects[uResized].top);
+
+    /* Verify all pairs of originally adjacent rectangles for all 4 directions.
+     * If the pair has a "good" delta (that is the first rectangle intersects the second)
+     * at a direction and the second rectangle is not primary one (which can not be moved),
+     * move the second rectangle to make it adjacent to the first one.
+     */
+
+    /* X positive. */
+    unsigned iRect;
+    for (iRect = 0; iRect < nRects; iRect++)
+    {
+        /* Find the next adjacent original rect in x positive direction. */
+        unsigned iNextRect = hlpNextAdjacentRectXP(paRects, nRects, iRect);
+        DDCLOG(("next %d -> %d\n", iRect, iNextRect));
+
+        if (iNextRect == ~0 || iNextRect == uPrimary)
+        {
+            continue;
+        }
+
+        /* Check whether there is an X intersection between these adjacent rects in the new rectangles
+         * and fix the intersection if delta is "good".
+         */
+        int delta = paNewRects[iRect].right - paNewRects[iNextRect].left;
+
+        if (delta != 0)
+        {
+            DDCLOG(("XP intersection right %d left %d, diff %d\n",
+                     paNewRects[iRect].right, paNewRects[iNextRect].left,
+                     delta));
+
+            paNewRects[iNextRect].left += delta;
+            paNewRects[iNextRect].right += delta;
+        }
+    }
+
+    /* X negative. */
+    for (iRect = 0; iRect < nRects; iRect++)
+    {
+        /* Find the next adjacent original rect in x negative direction. */
+        unsigned iNextRect = hlpNextAdjacentRectXN(paRects, nRects, iRect);
+        DDCLOG(("next %d -> %d\n", iRect, iNextRect));
+
+        if (iNextRect == ~0 || iNextRect == uPrimary)
+        {
+            continue;
+        }
+
+        /* Check whether there is an X intersection between these adjacent rects in the new rectangles
+         * and fix the intersection if delta is "good".
+         */
+        int delta = paNewRects[iRect].left - paNewRects[iNextRect].right;
+
+        if (delta != 0)
+        {
+            DDCLOG(("XN intersection left %d right %d, diff %d\n",
+                     paNewRects[iRect].left, paNewRects[iNextRect].right,
+                     delta));
+
+            paNewRects[iNextRect].left += delta;
+            paNewRects[iNextRect].right += delta;
+        }
+    }
+
+    /* Y positive (in the computer sense, top->down). */
+    for (iRect = 0; iRect < nRects; iRect++)
+    {
+        /* Find the next adjacent original rect in y positive direction. */
+        unsigned iNextRect = hlpNextAdjacentRectYP(paRects, nRects, iRect);
+        DDCLOG(("next %d -> %d\n", iRect, iNextRect));
+
+        if (iNextRect == ~0 || iNextRect == uPrimary)
+        {
+            continue;
+        }
+
+        /* Check whether there is an Y intersection between these adjacent rects in the new rectangles
+         * and fix the intersection if delta is "good".
+         */
+        int delta = paNewRects[iRect].bottom - paNewRects[iNextRect].top;
+
+        if (delta != 0)
+        {
+            DDCLOG(("YP intersection bottom %d top %d, diff %d\n",
+                     paNewRects[iRect].bottom, paNewRects[iNextRect].top,
+                     delta));
+
+            paNewRects[iNextRect].top += delta;
+            paNewRects[iNextRect].bottom += delta;
+        }
+    }
+
+    /* Y negative (in the computer sense, down->top). */
+    for (iRect = 0; iRect < nRects; iRect++)
+    {
+        /* Find the next adjacent original rect in x negative direction. */
+        unsigned iNextRect = hlpNextAdjacentRectYN(paRects, nRects, iRect);
+        DDCLOG(("next %d -> %d\n", iRect, iNextRect));
+
+        if (iNextRect == ~0 || iNextRect == uPrimary)
+        {
+            continue;
+        }
+
+        /* Check whether there is an Y intersection between these adjacent rects in the new rectangles
+         * and fix the intersection if delta is "good".
+         */
+        int delta = paNewRects[iRect].top - paNewRects[iNextRect].bottom;
+
+        if (delta != 0)
+        {
+            DDCLOG(("YN intersection top %d bottom %d, diff %d\n",
+                     paNewRects[iRect].top, paNewRects[iNextRect].bottom,
+                     delta));
+
+            paNewRects[iNextRect].top += delta;
+            paNewRects[iNextRect].bottom += delta;
+        }
+    }
+
+    memcpy (paRects, paNewRects, sizeof (RECTL) * nRects);
+    return;
+}
+
+int hlpShowBalloonTip(HINSTANCE hInst, HWND hWnd, UINT uID,
+                      const char *pszMsg, const char *pszTitle,
+                      UINT uTimeout, DWORD dwInfoFlags)
+{
+    NOTIFYICONDATA niData;
+    niData.cbSize = sizeof(NOTIFYICONDATA);
+    niData.uFlags = NIF_INFO;
+    niData.hWnd = hWnd;
+    niData.uID = uID;
+    niData.uTimeout = uTimeout;
+    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 : "");
+
+    if (!Shell_NotifyIcon(NIM_MODIFY, &niData))
+        return GetLastError();
+    return 0;
+}
+
Index: trunk/src/VBox/Additions/WINNT/VBoxTray/VBoxHelpers.h
===================================================================
--- trunk/src/VBox/Additions/WINNT/VBoxTray/VBoxHelpers.h	(revision 33966)
+++ trunk/src/VBox/Additions/WINNT/VBoxTray/VBoxHelpers.h	(revision 33966)
@@ -0,0 +1,33 @@
+/* $Id$ */
+/** @file
+ * helpers - Guest Additions Service helper functions header.
+ */
+
+/*
+ * Copyright (C) 2006-2010 Oracle Corporation
+ *
+ * This file is part of VirtualBox Open Source Edition (OSE), as
+ * available from http://www.virtualbox.org. This file is free software;
+ * you can redistribute it and/or modify it under the terms of the GNU
+ * General Public License (GPL) as published by the Free Software
+ * Foundation, in version 2 as it comes in the "COPYING" file of the
+ * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
+ * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
+ */
+
+#ifndef ___VBOXTRAY_HELPERS_H
+#define ___VBOXTRAY_HELPERS_H
+
+// #define DEBUG_DISPLAY_CHANGE
+
+#ifdef DEBUG_DISPLAY_CHANGE
+#   define DDCLOG(a) Log(a)
+#else
+#   define DDCLOG(a) do {} while (0)
+#endif /* !DEBUG_DISPLAY_CHANGE */
+
+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);
+
+#endif /* !___VBOXTRAY_HELPERS_H */
+
Index: trunk/src/VBox/Additions/WINNT/VBoxTray/VBoxHostVersion.cpp
===================================================================
--- trunk/src/VBox/Additions/WINNT/VBoxTray/VBoxHostVersion.cpp	(revision 33951)
+++ trunk/src/VBox/Additions/WINNT/VBoxTray/VBoxHostVersion.cpp	(revision 33966)
@@ -19,5 +19,5 @@
 #include "VBoxHostVersion.h"
 #include "VBoxTray.h"
-#include "helpers.h"
+#include "VBoxHelpers.h"
 
 #include <VBox/VBoxGuestLib.h>
@@ -26,5 +26,5 @@
 /** @todo Move this part in VbglR3 and just provide a callback for the platform-specific
           notification stuff, since this is very similar to the VBoxClient code. */
-int VBoxCheckHostVersion ()
+int VBoxCheckHostVersion()
 {
     int rc;
@@ -51,5 +51,5 @@
                                                 "install option from the Devices menu.", pszGuestVersion, pszHostVersion);
 
-                rc = showBalloonTip(gInstance, gToolWindow, ID_TRAYICON, szMsg, szTitle, 5000, 0);
+                rc = hlpShowBalloonTip(gInstance, gToolWindow, ID_TRAYICON, szMsg, szTitle, 5000, 0);
                 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/VBoxRestore.cpp
===================================================================
--- trunk/src/VBox/Additions/WINNT/VBoxTray/VBoxRestore.cpp	(revision 33951)
+++ trunk/src/VBox/Additions/WINNT/VBoxTray/VBoxRestore.cpp	(revision 33966)
@@ -5,5 +5,5 @@
 
 /*
- * Copyright (C) 2006-2007 Oracle Corporation
+ * Copyright (C) 2006-2010 Oracle Corporation
  *
  * This file is part of VirtualBox Open Source Edition (OSE), as
@@ -18,4 +18,5 @@
 #include <windows.h>
 #include "VBoxTray.h"
+#include "VBoxHelpers.h"
 #include "VBoxRestore.h"
 #include <VBoxDisplay.h>
@@ -23,5 +24,5 @@
 #include <VBoxGuestInternal.h>
 #include <iprt/assert.h>
-#include "helpers.h"
+
 
 typedef struct _VBOXRESTORECONTEXT
@@ -64,22 +65,24 @@
 void VBoxRestoreCheckVRDP()
 {
-    DWORD ret;
     VBOXDISPIFESCAPE escape = {0};
     escape.escapeCode = VBOXESC_ISVRDPACTIVE;
-    /* Check VRDP activity */
+    /* Check VRDP activity. */
 
-    /* send to display driver */
-    ret = VBoxDispIfEscape(&gCtx.pEnv->dispIf, &escape, 0);
-    Log(("VBoxTray: VBoxRestoreSession -> VRDP activate state = %d\n", ret));
+    /* Send to display driver. */
+    DWORD dwRet = VBoxDispIfEscape(&gCtx.pEnv->dispIf, &escape, 0);
+    Log(("VBoxTray: VBoxRestoreCheckVRDP -> VRDP activate state = %d\n", dwRet));
 
-    if (ret != gCtx.fRDPState)
+    if (dwRet != gCtx.fRDPState)
     {
-        DWORD cbReturned;
-
-        if (!DeviceIoControl (gCtx.pEnv->hDriver, ret == NO_ERROR ? VBOXGUEST_IOCTL_ENABLE_VRDP_SESSION : VBOXGUEST_IOCTL_DISABLE_VRDP_SESSION, NULL, 0, NULL, 0, &cbReturned, NULL))
+        DWORD cbReturnIgnored;
+        if (!DeviceIoControl(gCtx.pEnv->hDriver,
+                             dwRet == NO_ERROR
+                             ? VBOXGUEST_IOCTL_ENABLE_VRDP_SESSION
+                             : VBOXGUEST_IOCTL_DISABLE_VRDP_SESSION,
+                             NULL, 0, NULL, 0, &cbReturnIgnored, NULL))
         {
-            Log(("VBoxTray: VBoxRestoreThread: DeviceIOControl(CtlMask) failed, SeamlessChangeThread exited\n"));
+            Log(("VBoxTray: VBoxRestoreCheckVRDP: DeviceIOControl failed, error = %ld\n", GetLastError()));
         }
-        gCtx.fRDPState = ret;
+        gCtx.fRDPState = dwRet;
     }
 }
@@ -127,8 +130,8 @@
             /* did we get the right event? */
             if (waitEvent.u32EventFlagsOut & VMMDEV_EVENT_RESTORED)
-                PostMessage(gToolWindow, WM_VBOX_RESTORED, 0, 0);
+                PostMessage(gToolWindow, WM_VBOXTRAY_VM_RESTORED, 0, 0);
             else
                 /** @todo Don't poll, but wait for connect/disconnect events */
-                PostMessage(gToolWindow, WM_VBOX_CHECK_VRDP, 0, 0);
+                PostMessage(gToolWindow, WM_VBOXTRAY_VRDP_CHECK, 0, 0);
         }
         else
Index: trunk/src/VBox/Additions/WINNT/VBoxTray/VBoxSeamless.cpp
===================================================================
--- trunk/src/VBox/Additions/WINNT/VBoxTray/VBoxSeamless.cpp	(revision 33951)
+++ trunk/src/VBox/Additions/WINNT/VBoxTray/VBoxSeamless.cpp	(revision 33966)
@@ -18,4 +18,5 @@
 #include <windows.h>
 #include "VBoxTray.h"
+#include "VBoxHelpers.h"
 #include "VBoxSeamless.h"
 #include <VBoxHook.h>
@@ -24,5 +25,4 @@
 #include <iprt/assert.h>
 #include <VBoxGuestInternal.h>
-#include "helpers.h"
 
 typedef struct _VBOXSEAMLESSCONTEXT
@@ -324,5 +324,5 @@
             if (waitEvent.u32EventFlagsOut & VMMDEV_EVENT_SEAMLESS_MODE_CHANGE_REQUEST)
             {
-                Log(("VBoxTray: VBoxTray: going to get seamless change information.\n"));
+                Log(("VBoxTray: VBoxTray: going to get seamless change information\n"));
 
                 /* We got at least one event. Read the requested resolution
Index: trunk/src/VBox/Additions/WINNT/VBoxTray/VBoxSharedFolders.cpp
===================================================================
--- trunk/src/VBox/Additions/WINNT/VBoxTray/VBoxSharedFolders.cpp	(revision 33951)
+++ trunk/src/VBox/Additions/WINNT/VBoxTray/VBoxSharedFolders.cpp	(revision 33966)
@@ -18,5 +18,5 @@
 #include "VBoxSharedFolders.h"
 #include "VBoxTray.h"
-#include "helpers.h"
+#include "VBoxHelpers.h"
 
 #include <iprt/mem.h>
@@ -105,5 +105,5 @@
                             if (chDrive > 'Z')
                             {
-                                LogRel(("VBoxTray: No free driver letter found to assign shared folder \"%s\", aborting.\n", pszName));
+                                LogRel(("VBoxTray: No free driver letter found to assign shared folder \"%s\", aborting\n", pszName));
                                 break;
                             }
Index: trunk/src/VBox/Additions/WINNT/VBoxTray/VBoxTray.cpp
===================================================================
--- trunk/src/VBox/Additions/WINNT/VBoxTray/VBoxTray.cpp	(revision 33951)
+++ trunk/src/VBox/Additions/WINNT/VBoxTray/VBoxTray.cpp	(revision 33966)
@@ -15,5 +15,10 @@
  */
 
+
+/*******************************************************************************
+*   Header Files                                                               *
+*******************************************************************************/
 #include "VBoxTray.h"
+#include "VBoxHelpers.h"
 #include "VBoxSeamless.h"
 #include "VBoxClipboard.h"
@@ -28,10 +33,12 @@
 #include <VBoxGuestInternal.h>
 
-#include "helpers.h"
 #include <sddl.h>
 
 #include <iprt/buildconfig.h>
 
-/* global variables */
+
+/*******************************************************************************
+*   Global Variables                                                           *
+*******************************************************************************/
 HANDLE                gVBoxDriver;
 HANDLE                gStopSem;
@@ -103,5 +110,5 @@
     gNotifyIconData.uID              = ID_TRAYICON;
     gNotifyIconData.uFlags           = NIF_ICON | NIF_MESSAGE | NIF_TIP;
-    gNotifyIconData.uCallbackMessage = WM_VBOX_TRAY;
+    gNotifyIconData.uCallbackMessage = WM_VBOXTRAY_TRAY_ICON;
     gNotifyIconData.hIcon            = hIcon;
 
@@ -140,5 +147,5 @@
 static int vboxStartServices(VBOXSERVICEENV *pEnv, VBOXSERVICEINFO *pTable)
 {
-    Log(("VBoxTray: Starting services...\n"));
+    Log(("VBoxTray: Starting services ...\n"));
 
     pEnv->hStopEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
@@ -152,5 +159,5 @@
     while (pTable->pszName)
     {
-        Log(("VBoxTray: Starting %s...\n", pTable->pszName));
+        Log(("VBoxTray: Starting %s ...\n", pTable->pszName));
 
         int rc = VINF_SUCCESS;
@@ -163,11 +170,9 @@
 
         if (pTable->pfnInit)
-        {
             rc = pTable->pfnInit (pEnv, &pTable->pInstance, &fStartThread);
-        }
-
-        if (RT_FAILURE (rc))
-        {
-            Log(("VBoxTray: Failed to initialize rc = %Rrc.\n", rc));
+
+        if (RT_FAILURE(rc))
+        {
+            Log(("VBoxTray: Failed to initialize rc = %Rrc\n", rc));
         }
         else
@@ -176,5 +181,4 @@
             {
                 unsigned threadid;
-
                 pTable->hThread = (HANDLE)_beginthreadex (NULL,  /* security */
                                                           0,     /* stacksize */
@@ -185,21 +189,14 @@
 
                 if (pTable->hThread == (HANDLE)(0))
-                {
                     rc = VERR_NOT_SUPPORTED;
-                }
-            }
-
-            if (RT_FAILURE (rc))
-            {
-                Log(("VBoxTray: Failed to start the thread.\n"));
-
+            }
+
+            if (RT_SUCCESS(rc))
+                pTable->fStarted = true;
+            else
+            {
+                Log(("VBoxTray: Failed to start the thread\n"));
                 if (pTable->pfnDestroy)
-                {
-                    pTable->pfnDestroy (pEnv, pTable->pInstance);
-                }
-            }
-            else
-            {
-                pTable->fStarted = true;
+                    pTable->pfnDestroy(pEnv, pTable->pInstance);
             }
         }
@@ -215,7 +212,5 @@
 {
     if (!pEnv->hStopEvent)
-    {
         return;
-    }
 
     /* Signal to all threads. */
@@ -231,13 +226,10 @@
                 WaitForSingleObject(pTable->hThread, INFINITE);
 
-                CloseHandle (pTable->hThread);
+                CloseHandle(pTable->hThread);
                 pTable->hThread = 0;
             }
 
             if (pTable->pfnDestroy)
-            {
                 pTable->pfnDestroy (pEnv, pTable->pInstance);
-            }
-
             pTable->fStarted = false;
         }
@@ -247,14 +239,16 @@
     }
 
-    CloseHandle (pEnv->hStopEvent);
-}
-
-
-/** Attempt to force Windows to reload the cursor image by attaching to the
+    CloseHandle(pEnv->hStopEvent);
+}
+
+
+/**
+ * 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. */
+ * at some point anyway.
+ */
 void VBoxServiceReloadCursor(void)
 {
@@ -340,5 +334,5 @@
     if (GetVersionEx(&info))
     {
-        Log(("VBoxTray: Windows version major %d minor %d.\n", info.dwMajorVersion, info.dwMinorVersion));
+        Log(("VBoxTray: Windows version major %d minor %d\n", info.dwMajorVersion, info.dwMinorVersion));
         gMajorVersion = info.dwMajorVersion;
     }
@@ -451,5 +445,5 @@
         /* Check in 10 seconds (@todo make seconds configurable) ... */
         SetTimer(gToolWindow,
-                 WM_VBOX_CHECK_HOSTVERSION,
+                 TIMERID_VBOXTRAY_CHECK_HOSTVERSION,
                  10 * 1000, /* 10 seconds */
                  NULL       /* No timerproc */);
@@ -479,9 +473,9 @@
 
         /* Only enable for message debugging, lots of traffic! */
-        //Log(("VBoxTray: Wait result  = %ld.\n", waitResult));
+        //Log(("VBoxTray: Wait result  = %ld\n", waitResult));
 
         if (waitResult == 0)
         {
-            Log(("VBoxTray: Event 'Exit' triggered.\n"));
+            Log(("VBoxTray: Event 'Exit' triggered\n"));
             /* exit */
             break;
@@ -490,5 +484,5 @@
                  && (ghSeamlessNotifyEvent!=0)) /* Only jump in, if seamless is active! */
         {
-            Log(("VBoxTray: Event 'Seamless' triggered.\n"));
+            Log(("VBoxTray: Event 'Seamless' triggered\n"));
 
             /* seamless window notification */
@@ -563,10 +557,10 @@
         return rc;
 
-    LogRel(("VBoxTray: %s r%s started.\n", RTBldCfgVersion(), RTBldCfgRevisionStr()));
+    LogRel(("VBoxTray: %s r%s started\n", RTBldCfgVersion(), RTBldCfgRevisionStr()));
 
     gInstance = hInstance;
     VBoxServiceStart();
 
-    LogRel(("VBoxTray: Ended.\n"));
+    LogRel(("VBoxTray: Ended\n"));
 
     /* Release instance mutex. */
@@ -590,5 +584,5 @@
     {
         case WM_CREATE:
-            Log(("VBoxTray: Tool window created.\n"));
+            Log(("VBoxTray: Tool window created\n"));
             s_uTaskbarCreated = RegisterWindowMessage(TEXT("TaskbarCreated"));
             if (!s_uTaskbarCreated)
@@ -600,6 +594,6 @@
 
         case WM_DESTROY:
-            Log(("VBoxTray: Tool window destroyed.\n"));
-            KillTimer(gToolWindow, WM_VBOX_CHECK_HOSTVERSION);
+            Log(("VBoxTray: Tool window destroyed\n"));
+            KillTimer(gToolWindow, TIMERID_VBOXTRAY_CHECK_HOSTVERSION);
             break;
 
@@ -607,9 +601,9 @@
             switch (wParam)
             {
-                case WM_VBOX_CHECK_HOSTVERSION:
+                case WM_VBOXTRAY_CHECK_HOSTVERSION:
                     if (RT_SUCCESS(VBoxCheckHostVersion()))
                     {
                         /* After successful run we don't need to check again. */
-                        KillTimer(gToolWindow, WM_VBOX_CHECK_HOSTVERSION);
+                        KillTimer(gToolWindow, TIMERID_VBOXTRAY_CHECK_HOSTVERSION);
                     }
                     return 0;
@@ -621,5 +615,5 @@
             break;
 
-        case WM_VBOX_TRAY:
+        case WM_VBOXTRAY_TRAY_ICON:
             switch (lParam)
             {
@@ -644,9 +638,9 @@
             break;
 
-        case WM_VBOX_RESTORED:
+        case WM_VBOXTRAY_VM_RESTORED:
             VBoxRestoreSession();
             break;
 
-        case WM_VBOX_CHECK_VRDP:
+        case WM_VBOXTRAY_VRDP_CHECK:
             VBoxRestoreCheckVRDP();
             break;
Index: trunk/src/VBox/Additions/WINNT/VBoxTray/VBoxTray.h
===================================================================
--- trunk/src/VBox/Additions/WINNT/VBoxTray/VBoxTray.h	(revision 33951)
+++ trunk/src/VBox/Additions/WINNT/VBoxTray/VBoxTray.h	(revision 33966)
@@ -36,11 +36,35 @@
 #include "VBoxDispIf.h"
 
-#define WM_VBOX_RESTORED                WM_APP + 1
-#define WM_VBOX_CHECK_VRDP              WM_APP + 2
-#define WM_VBOX_CHECK_HOSTVERSION       WM_APP + 3
-#define WM_VBOX_TRAY                    WM_APP + 4
+/*
+ * Windows messsages.
+ */
 
+/**
+ * General VBoxTray messages.
+ */
+#define WM_VBOXTRAY_TRAY_ICON                   WM_APP + 40
+#define WM_VBOXTRAY_TRAY_DISPLAY_BALLOON        WM_APP + 41
+/**
+ * VM/VMMDev related messsages.
+ */
+#define WM_VBOXTRAY_VM_RESTORED                 WM_APP + 100
+/**
+ * VRDP messages.
+ */
+#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
 
+
+/*
+ * Timer IDs.
+ */
+#define TIMERID_VBOXTRAY_CHECK_HOSTVERSION      1000
 
 /* The environment information for services. */
Index: trunk/src/VBox/Additions/WINNT/VBoxTray/VBoxVRDP.cpp
===================================================================
--- trunk/src/VBox/Additions/WINNT/VBoxTray/VBoxVRDP.cpp	(revision 33951)
+++ trunk/src/VBox/Additions/WINNT/VBoxTray/VBoxVRDP.cpp	(revision 33966)
@@ -5,5 +5,5 @@
 
 /*
- * Copyright (C) 2006-2007 Oracle Corporation
+ * Copyright (C) 2006-2010 Oracle Corporation
  *
  * This file is part of VirtualBox Open Source Edition (OSE), as
@@ -20,9 +20,9 @@
 #include <windows.h>
 #include "VBoxTray.h"
+#include "VBoxHelpers.h"
 #include "VBoxVRDP.h"
 #include <VBox/VMMDev.h>
 #include <VBoxGuestInternal.h>
 #include <iprt/assert.h>
-#include "helpers.h"
 
 
Index: trunk/src/VBox/Additions/WINNT/VBoxTray/helpers.cpp
===================================================================
--- trunk/src/VBox/Additions/WINNT/VBoxTray/helpers.cpp	(revision 33951)
+++ 	(revision )
@@ -1,256 +1,0 @@
-/** @file
- * helpers - Guest Additions Service helper functions
- */
-
-/*
- * Copyright (C) 2006-2007 Oracle Corporation
- *
- * This file is part of VirtualBox Open Source Edition (OSE), as
- * available from http://www.virtualbox.org. This file is free software;
- * you can redistribute it and/or modify it under the terms of the GNU
- * General Public License (GPL) as published by the Free Software
- * Foundation, in version 2 as it comes in the "COPYING" file of the
- * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
- * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
- */
-
-#include <malloc.h>
-#include <windows.h>
-
-#include <iprt/string.h>
-#include <VBox/VBoxGuestLib.h>
-
-#include <VBoxGuestInternal.h>
-
-#include "helpers.h"
-#include "resource.h"
-
-static unsigned nextAdjacentRectXP (RECTL *paRects, unsigned nRects, unsigned iRect)
-{
-    unsigned i;
-    for (i = 0; i < nRects; i++)
-    {
-        if (paRects[iRect].right == paRects[i].left)
-        {
-            return i;
-        }
-    }
-    return ~0;
-}
-
-static unsigned nextAdjacentRectXN (RECTL *paRects, unsigned nRects, unsigned iRect)
-{
-    unsigned i;
-    for (i = 0; i < nRects; i++)
-    {
-        if (paRects[iRect].left == paRects[i].right)
-        {
-            return i;
-        }
-    }
-    return ~0;
-}
-
-static unsigned nextAdjacentRectYP (RECTL *paRects, unsigned nRects, unsigned iRect)
-{
-    unsigned i;
-    for (i = 0; i < nRects; i++)
-    {
-        if (paRects[iRect].bottom == paRects[i].top)
-        {
-            return i;
-        }
-    }
-    return ~0;
-}
-
-unsigned nextAdjacentRectYN (RECTL *paRects, unsigned nRects, unsigned iRect)
-{
-    unsigned i;
-    for (i = 0; i < nRects; i++)
-    {
-        if (paRects[iRect].top == paRects[i].bottom)
-        {
-            return i;
-        }
-    }
-    return ~0;
-}
-
-void resizeRect(RECTL *paRects, unsigned nRects, unsigned iPrimary, unsigned iResized, int NewWidth, int NewHeight)
-{
-    DDCLOG(("nRects %d, iPrimary %d, iResized %d, NewWidth %d, NewHeight %d\n", nRects, iPrimary, iResized, NewWidth, NewHeight));
-
-    RECTL *paNewRects = (RECTL *)alloca (sizeof (RECTL) * nRects);
-    memcpy (paNewRects, paRects, sizeof (RECTL) * nRects);
-    paNewRects[iResized].right += NewWidth - (paNewRects[iResized].right - paNewRects[iResized].left);
-    paNewRects[iResized].bottom += NewHeight - (paNewRects[iResized].bottom - paNewRects[iResized].top);
-
-    /* Verify all pairs of originally adjacent rectangles for all 4 directions.
-     * If the pair has a "good" delta (that is the first rectangle intersects the second)
-     * at a direction and the second rectangle is not primary one (which can not be moved),
-     * move the second rectangle to make it adjacent to the first one.
-     */
-
-    /* X positive. */
-    unsigned iRect;
-    for (iRect = 0; iRect < nRects; iRect++)
-    {
-        /* Find the next adjacent original rect in x positive direction. */
-        unsigned iNextRect = nextAdjacentRectXP (paRects, nRects, iRect);
-        DDCLOG(("next %d -> %d\n", iRect, iNextRect));
-
-        if (iNextRect == ~0 || iNextRect == iPrimary)
-        {
-            continue;
-        }
-
-        /* Check whether there is an X intersection between these adjacent rects in the new rectangles
-         * and fix the intersection if delta is "good".
-         */
-        int delta = paNewRects[iRect].right - paNewRects[iNextRect].left;
-
-        if (delta != 0)
-        {
-            DDCLOG(("XP intersection right %d left %d, diff %d\n",
-                     paNewRects[iRect].right, paNewRects[iNextRect].left,
-                     delta));
-
-            paNewRects[iNextRect].left += delta;
-            paNewRects[iNextRect].right += delta;
-        }
-    }
-
-    /* X negative. */
-    for (iRect = 0; iRect < nRects; iRect++)
-    {
-        /* Find the next adjacent original rect in x negative direction. */
-        unsigned iNextRect = nextAdjacentRectXN (paRects, nRects, iRect);
-        DDCLOG(("next %d -> %d\n", iRect, iNextRect));
-
-        if (iNextRect == ~0 || iNextRect == iPrimary)
-        {
-            continue;
-        }
-
-        /* Check whether there is an X intersection between these adjacent rects in the new rectangles
-         * and fix the intersection if delta is "good".
-         */
-        int delta = paNewRects[iRect].left - paNewRects[iNextRect].right;
-
-        if (delta != 0)
-        {
-            DDCLOG(("XN intersection left %d right %d, diff %d\n",
-                     paNewRects[iRect].left, paNewRects[iNextRect].right,
-                     delta));
-
-            paNewRects[iNextRect].left += delta;
-            paNewRects[iNextRect].right += delta;
-        }
-    }
-
-    /* Y positive (in the computer sense, top->down). */
-    for (iRect = 0; iRect < nRects; iRect++)
-    {
-        /* Find the next adjacent original rect in y positive direction. */
-        unsigned iNextRect = nextAdjacentRectYP (paRects, nRects, iRect);
-        DDCLOG(("next %d -> %d\n", iRect, iNextRect));
-
-        if (iNextRect == ~0 || iNextRect == iPrimary)
-        {
-            continue;
-        }
-
-        /* Check whether there is an Y intersection between these adjacent rects in the new rectangles
-         * and fix the intersection if delta is "good".
-         */
-        int delta = paNewRects[iRect].bottom - paNewRects[iNextRect].top;
-
-        if (delta != 0)
-        {
-            DDCLOG(("YP intersection bottom %d top %d, diff %d\n",
-                     paNewRects[iRect].bottom, paNewRects[iNextRect].top,
-                     delta));
-
-            paNewRects[iNextRect].top += delta;
-            paNewRects[iNextRect].bottom += delta;
-        }
-    }
-
-    /* Y negative (in the computer sense, down->top). */
-    for (iRect = 0; iRect < nRects; iRect++)
-    {
-        /* Find the next adjacent original rect in x negative direction. */
-        unsigned iNextRect = nextAdjacentRectYN (paRects, nRects, iRect);
-        DDCLOG(("next %d -> %d\n", iRect, iNextRect));
-
-        if (iNextRect == ~0 || iNextRect == iPrimary)
-        {
-            continue;
-        }
-
-        /* Check whether there is an Y intersection between these adjacent rects in the new rectangles
-         * and fix the intersection if delta is "good".
-         */
-        int delta = paNewRects[iRect].top - paNewRects[iNextRect].bottom;
-
-        if (delta != 0)
-        {
-            DDCLOG(("YN intersection top %d bottom %d, diff %d\n",
-                     paNewRects[iRect].top, paNewRects[iNextRect].bottom,
-                     delta));
-
-            paNewRects[iNextRect].top += delta;
-            paNewRects[iNextRect].bottom += delta;
-        }
-    }
-
-    memcpy (paRects, paNewRects, sizeof (RECTL) * nRects);
-    return;
-}
-
-int showBalloonTip (HINSTANCE hInst, HWND hWnd, UINT uID, const char *pszMsg, const char *pszTitle, UINT uTimeout, DWORD dwInfoFlags)
-{
-    NOTIFYICONDATA niData;
-    niData.cbSize = sizeof(NOTIFYICONDATA);
-    niData.uFlags = NIF_INFO;
-    niData.hWnd = hWnd;
-    niData.uID = uID;
-    niData.uTimeout = uTimeout;
-    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 : "");
-
-    if (!Shell_NotifyIcon(NIM_MODIFY, &niData))
-        return GetLastError();
-    return 0;
-}
-
Index: trunk/src/VBox/Additions/WINNT/VBoxTray/helpers.h
===================================================================
--- trunk/src/VBox/Additions/WINNT/VBoxTray/helpers.h	(revision 33951)
+++ 	(revision )
@@ -1,33 +1,0 @@
-/* $Id$ */
-/** @file
- * helpers - Guest Additions Service helper functions header
- */
-
-/*
- * Copyright (C) 2006-2007 Oracle Corporation
- *
- * This file is part of VirtualBox Open Source Edition (OSE), as
- * available from http://www.virtualbox.org. This file is free software;
- * you can redistribute it and/or modify it under the terms of the GNU
- * General Public License (GPL) as published by the Free Software
- * Foundation, in version 2 as it comes in the "COPYING" file of the
- * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
- * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
- */
-
-#ifndef ___VBOXTRAY_HELPERS_H
-#define ___VBOXTRAY_HELPERS_H
-
-// #define DEBUG_DISPLAY_CHANGE
-
-#ifdef DEBUG_DISPLAY_CHANGE
-#   define DDCLOG(a) Log(a)
-#else
-#   define DDCLOG(a) do {} while (0)
-#endif /* !DEBUG_DISPLAY_CHANGE */
-
-void resizeRect(RECTL *paRects, unsigned nRects, unsigned iPrimary, unsigned iResized, int NewWidth, int NewHeight);
-int showBalloonTip (HINSTANCE hInst, HWND hWnd, UINT uID, const char *pszMsg, const char *pszTitle, UINT uTimeout, DWORD dwInfoFlags);
-
-#endif /* !___VBOXTRAY_HELPERS_H */
-
