Index: /trunk/src/VBox/Additions/WINNT/VBoxTray/VBoxClipboard.cpp
===================================================================
--- /trunk/src/VBox/Additions/WINNT/VBoxTray/VBoxClipboard.cpp	(revision 78141)
+++ /trunk/src/VBox/Additions/WINNT/VBoxTray/VBoxClipboard.cpp	(revision 78142)
@@ -47,4 +47,9 @@
 #endif
 
+/** Sets announced clipboard formats from the host. */
+#define VBOX_WM_SHCLPB_SET_FORMATS      WM_USER
+/** Reads data from the clipboard and sends it to the host. */
+#define VBOX_WM_SHCLPB_READ_DATA        WM_USER + 1
+
 typedef struct _VBOXCLIPBOARDCONTEXT
 {
@@ -105,5 +110,5 @@
 
 
-static int vboxOpenClipboard(HWND hwnd)
+static int vboxOpenClipboard(HWND hWnd)
 {
     /* "OpenClipboard fails if another window has the clipboard open."
@@ -112,8 +117,10 @@
     BOOL fOpened = FALSE;
 
+    LogFlowFunc(("hWnd=%p\n", hWnd));
+
     int i = 0;
     for (;;)
     {
-        if (OpenClipboard(hwnd))
+        if (OpenClipboard(hWnd))
         {
             fOpened = TRUE;
@@ -130,5 +137,5 @@
 #ifdef LOG_ENABLED
     if (i > 0)
-        LogFlowFunc(("%d times tried to open clipboard.\n", i + 1));
+        LogFlowFunc(("%d times tried to open clipboard\n", i + 1));
 #endif
 
@@ -138,7 +145,7 @@
     else
     {
-        const DWORD err = GetLastError();
-        LogFlowFunc(("error %d\n", err));
-        rc = RTErrConvertFromWin32(err);
+        const DWORD dwLastErr = GetLastError();
+        rc = RTErrConvertFromWin32(dwLastErr);
+        LogRel(("Clipboard: Failed to open clipboard! Error=%ld (%Rrc)\n", dwLastErr, rc));
     }
 
@@ -195,8 +202,4 @@
         CloseClipboard();
         rc = VbglR3ClipboardReportFormats(pCtx->u32ClientID, u32Formats);
-    }
-    else
-    {
-        LogFlow(("vboxClipboardChanged: error in open clipboard. hwnd: %x. err: %Rrc\n", pCtx->hwnd, rc));
     }
     return rc;
@@ -530,15 +533,13 @@
                 CloseClipboard();
             }
-            else
-            {
-                LogFlowFunc(("WM_RENDERALLFORMATS: Failed to open clipboard! rc: %Rrc\n", vboxrc));
-            }
         } break;
 
-        case WM_USER:
+        case VBOX_WM_SHCLPB_SET_FORMATS:
         {
             /* Announce available formats. Do not insert data, they will be inserted in WM_RENDER*. */
             uint32_t u32Formats = (uint32_t)lParam;
 
+            LogFlowFunc(("VBOX_WM_SHCLPB_SET_FORMATS: u32Formats=0x%x\n", u32Formats));
+
             int vboxrc = vboxOpenClipboard(hwnd);
             if (RT_SUCCESS(vboxrc))
@@ -549,39 +550,29 @@
 
                 if (u32Formats & VBOX_SHARED_CLIPBOARD_FMT_UNICODETEXT)
-                {
-                    LogFlowFunc(("WM_USER: VBOX_SHARED_CLIPBOARD_FMT_UNICODETEXT\n"));
                     hClip = SetClipboardData(CF_UNICODETEXT, NULL);
+
+                if (u32Formats & VBOX_SHARED_CLIPBOARD_FMT_BITMAP)
+                    hClip = SetClipboardData(CF_DIB, NULL);
+
+                if (u32Formats & VBOX_SHARED_CLIPBOARD_FMT_HTML)
+                {
+                    UINT format = RegisterClipboardFormat ("HTML Format");
+                    if (format != 0)
+                        hClip = SetClipboardData(format, NULL);
                 }
 
-                if (u32Formats & VBOX_SHARED_CLIPBOARD_FMT_BITMAP)
-                {
-                    LogFlowFunc(("WM_USER: VBOX_SHARED_CLIPBOARD_FMT_BITMAP\n"));
-                    hClip = SetClipboardData(CF_DIB, NULL);
-                }
-
-                if (u32Formats & VBOX_SHARED_CLIPBOARD_FMT_HTML)
-                {
-                    UINT format = RegisterClipboardFormat ("HTML Format");
-                    LogFlowFunc(("WM_USER: VBOX_SHARED_CLIPBOARD_FMT_HTML 0x%04X\n", format));
-                    if (format != 0)
-                    {
-                        hClip = SetClipboardData(format, NULL);
-                    }
-                }
-
                 CloseClipboard();
-                LogFlowFunc(("WM_USER: hClip = %p, err = %ld\n", hClip, GetLastError ()));
-            }
-            else
-            {
-                LogFlowFunc(("WM_USER: Failed to open clipboard! error = %Rrc\n", vboxrc));
+
+                LogFlowFunc(("VBOX_WM_SHCLPB_SET_FORMATS: hClip=%p, lastErr=%ld\n", hClip, GetLastError()));
             }
         } break;
 
-        case WM_USER + 1:
+        case VBOX_WM_SHCLPB_READ_DATA:
         {
             /* Send data in the specified format to the host. */
             uint32_t u32Formats = (uint32_t)lParam;
             HANDLE hClip = NULL;
+
+            LogFlowFunc(("VBOX_WM_SHCLPB_READ_DATA: u32Formats=0x%x\n", u32Formats));
 
             int vboxrc = vboxOpenClipboard(hwnd);
@@ -597,5 +588,4 @@
                         if (lp != NULL)
                         {
-                            LogFlowFunc(("WM_USER + 1: CF_DIB\n"));
                             vboxrc = VbglR3ClipboardWriteData(pCtx->u32ClientID, VBOX_SHARED_CLIPBOARD_FMT_BITMAP,
                                                               lp, GlobalSize(hClip));
@@ -618,5 +608,4 @@
                         if (uniString != NULL)
                         {
-                            LogFlowFunc(("WM_USER + 1: CF_UNICODETEXT\n"));
                             vboxrc = VbglR3ClipboardWriteData(pCtx->u32ClientID, VBOX_SHARED_CLIPBOARD_FMT_UNICODETEXT,
                                                               uniString, (lstrlenW(uniString) + 1) * 2);
@@ -641,5 +630,4 @@
                             if (lp != NULL)
                             {
-                                LogFlowFunc(("WM_USER + 1: CF_HTML\n"));
                                 vboxrc = VbglR3ClipboardWriteData(pCtx->u32ClientID, VBOX_SHARED_CLIPBOARD_FMT_HTML,
                                                                   lp, GlobalSize(hClip));
@@ -656,8 +644,4 @@
                 CloseClipboard();
             }
-            else
-            {
-                LogFlowFunc(("WM_USER: Failed to open clipboard! rc: %Rrc\n", vboxrc));
-            }
 
             if (hClip == NULL)
@@ -857,5 +841,4 @@
             switch (u32Msg)
             {
-                /** @todo r=andy: Use a \#define for WM_USER (+1). */
                 case VBOX_SHARED_CLIPBOARD_HOST_MSG_FORMATS:
                 {
@@ -863,5 +846,5 @@
                      * Forward the information to the window, so it can later
                      * respond to WM_RENDERFORMAT message. */
-                    ::PostMessage(pCtx->hwnd, WM_USER, 0, u32Formats);
+                    ::PostMessage(pCtx->hwnd, VBOX_WM_SHCLPB_SET_FORMATS, 0, u32Formats);
                 } break;
 
@@ -869,5 +852,5 @@
                 {
                     /* The host needs data in the specified format. */
-                    ::PostMessage(pCtx->hwnd, WM_USER + 1, 0, u32Formats);
+                    ::PostMessage(pCtx->hwnd, VBOX_WM_SHCLPB_READ_DATA, 0, u32Formats);
                 } break;
 
