Index: /trunk/src/VBox/Additions/WINNT/VBoxTray/VBoxDisplay.cpp
===================================================================
--- /trunk/src/VBox/Additions/WINNT/VBoxTray/VBoxDisplay.cpp	(revision 19835)
+++ /trunk/src/VBox/Additions/WINNT/VBoxTray/VBoxDisplay.cpp	(revision 19836)
@@ -233,4 +233,8 @@
             paDisplayDevices[DevNum] = DisplayDevice;
             
+            /* First try to get the video mode stored in registry (ENUM_REGISTRY_SETTINGS).
+             * A secondary display could be not active at the moment and would not have
+             * a current video mode (ENUM_CURRENT_SETTINGS).
+             */
             ZeroMemory(&paDeviceModes[DevNum], sizeof(DEVMODE));
             paDeviceModes[DevNum].dmSize = sizeof(DEVMODE);
@@ -242,7 +246,24 @@
             }
             
-            Log(("ResizeDisplayDevice: %dx%d at %d,%d\n",
+            if (   paDeviceModes[DevNum].dmPelsWidth == 0
+                || paDeviceModes[DevNum].dmPelsHeight == 0)
+            {
+                /* No ENUM_REGISTRY_SETTINGS yet. Seen on Vista after installation.
+                 * Get the current video mode then.
+                 */
+                ZeroMemory(&paDeviceModes[DevNum], sizeof(DEVMODE));
+                paDeviceModes[DevNum].dmSize = sizeof(DEVMODE);
+                if (!EnumDisplaySettings((LPSTR)DisplayDevice.DeviceName,
+                     ENUM_CURRENT_SETTINGS, &paDeviceModes[DevNum]))
+                {
+                    Log(("EnumDisplaySettings(ENUM_CURRENT_SETTINGS) err %d\n", GetLastError ()));
+                    return FALSE;
+                }
+            }
+            
+            Log(("ResizeDisplayDevice: %dx%dx%d at %d,%d\n",
                     paDeviceModes[DevNum].dmPelsWidth,
                     paDeviceModes[DevNum].dmPelsHeight,
+                    paDeviceModes[DevNum].dmBitsPerPel,
                     paDeviceModes[DevNum].dmPosition.x,
                     paDeviceModes[DevNum].dmPosition.y));
@@ -303,6 +324,4 @@
     tempDevMode.dmSize = sizeof(DEVMODE);
     EnumDisplaySettings(NULL, 0xffffff, &tempDevMode);
-    BOOL bUpdateMonitor = FALSE;
-    LONG status = 0;
 
     /* Assign the new rectangles to displays. */
@@ -314,52 +333,40 @@
         paDeviceModes[i].dmPelsHeight = paRects[i].bottom - paRects[i].top;
         
-        paDeviceModes[i].dmFields = DM_POSITION | DM_PELSHEIGHT | DM_PELSWIDTH;
+        /* On Vista one must specify DM_BITSPERPEL.
+         * Note that the current mode dmBitsPerPel is already in the DEVMODE structure.
+         */
+        paDeviceModes[i].dmFields = DM_POSITION | DM_PELSHEIGHT | DM_PELSWIDTH | DM_BITSPERPEL;
         
         if (   i == Id
             && BitsPerPixel != 0)
         {
-            paDeviceModes[i].dmFields |= DM_BITSPERPEL;
+            /* Change dmBitsPerPel if requested. */
             paDeviceModes[i].dmBitsPerPel = BitsPerPixel;
         }
 
-        /* Test if the mode can be set. */
-        Log(("ResizeDisplayDevice: Testing if the mode can be set ...\n"));
-        SetLastError(0);
-        status = gCtx.pfnChangeDisplaySettingsEx((LPSTR)paDisplayDevices[i].DeviceName, 
-                                                 &paDeviceModes[i], NULL, CDS_TEST, NULL);
-        if (status == DISP_CHANGE_SUCCESSFUL)
-        {
-            Log(("ResizeDisplayDevice: Mode can be set! Calling pfnChangeDisplaySettingsEx %x\n", gCtx.pfnChangeDisplaySettingsEx));         
-            gCtx.pfnChangeDisplaySettingsEx((LPSTR)paDisplayDevices[i].DeviceName, 
-                                            &paDeviceModes[i], NULL, CDS_NORESET | CDS_UPDATEREGISTRY, NULL);    
-            Log(("ResizeDisplayDevice: ChangeDisplaySettingsEx position err %d\n", GetLastError ()));
-            bUpdateMonitor = TRUE;
-        }
-        else
-        {
-            if (status == DISP_CHANGE_BADMODE)
-            {
-                Log(("ResizeDisplayDevice: Unsupported mode specified. No changes made.\n"));
-            }
-            else Log(("ResizeDisplayDevice: Mode can NOT be set! Error: %d\n", status));
-        }
+        Log(("ResizeDisplayDevice: pfnChangeDisplaySettingsEx %x: %dx%dx%d at %d,%d\n",
+              gCtx.pfnChangeDisplaySettingsEx,
+              paDeviceModes[i].dmPelsWidth,
+              paDeviceModes[i].dmPelsHeight,
+              paDeviceModes[i].dmBitsPerPel,
+              paDeviceModes[i].dmPosition.x,
+              paDeviceModes[i].dmPosition.y));
+
+        gCtx.pfnChangeDisplaySettingsEx((LPSTR)paDisplayDevices[i].DeviceName,
+                                        &paDeviceModes[i], NULL, CDS_NORESET | CDS_UPDATEREGISTRY, NULL);
+        Log(("ResizeDisplayDevice: ChangeDisplaySettingsEx position err %d\n", GetLastError ()));
     }
     
     /* A second call to ChangeDisplaySettings updates the monitor. */
-    if (bUpdateMonitor)
-    {
-        status = ChangeDisplaySettings(NULL, 0); 
-        Log(("ResizeDisplayDevice: ChangeDisplaySettings update status %d\n", status));
-        if (status == DISP_CHANGE_SUCCESSFUL || status == DISP_CHANGE_BADMODE)
-        {
-            /* Successfully set new video mode or our driver can not set the requested mode. Stop trying. */
-            return FALSE;
-        }
-
-        /* Retry the request. */
-        return TRUE;
-    }
-
-    return FALSE; /* Don't retry; maybe something went wrong. */
+    LONG status = ChangeDisplaySettings(NULL, 0); 
+    Log(("ResizeDisplayDevice: ChangeDisplaySettings update status %d\n", status));
+    if (status == DISP_CHANGE_SUCCESSFUL || status == DISP_CHANGE_BADMODE)
+    {
+        /* Successfully set new video mode or our driver can not set the requested mode. Stop trying. */
+        return FALSE;
+    }
+
+    /* Retry the request. */
+    return TRUE;
 }
 
