Index: trunk/src/VBox/Additions/WINNT/VBoxTray/VBoxDispIf.cpp
===================================================================
--- trunk/src/VBox/Additions/WINNT/VBoxTray/VBoxDispIf.cpp	(revision 44149)
+++ trunk/src/VBox/Additions/WINNT/VBoxTray/VBoxDispIf.cpp	(revision 44150)
@@ -418,338 +418,7 @@
 
 #ifdef VBOX_WITH_WDDM
-/**/
-typedef DECLCALLBACK(VOID) FNVBOXSCREENMONRUNNER_CB(void *pvCb);
-typedef FNVBOXSCREENMONRUNNER_CB *PFNVBOXSCREENMONRUNNER_CB;
-
-typedef struct VBOXSCREENMON
-{
-    HANDLE hThread;
-    DWORD idThread;
-    HANDLE hEvent;
-    HWND hWnd;
-    PFNVBOXSCREENMONRUNNER_CB pfnCb;
-    void *pvCb;
-} VBOXSCREENMON, *PVBOXSCREENMON;
-
-
-static VBOXSCREENMON g_VBoxScreenMon;
-
-
-#define VBOX_E_INSUFFICIENT_BUFFER HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER)
-#define VBOX_E_NOT_SUPPORTED HRESULT_FROM_WIN32(ERROR_NOT_SUPPORTED)
-
-
-static void vboxScreenMonOnChange()
-{
-    PVBOXSCREENMON pMon = &g_VBoxScreenMon;
-    pMon->pfnCb(pMon->pvCb);
-}
-
-static LRESULT CALLBACK vboxScreenMonWndProc(HWND hwnd,
-    UINT uMsg,
-    WPARAM wParam,
-    LPARAM lParam
-)
-{
-    switch(uMsg)
-    {
-        case WM_DISPLAYCHANGE:
-        {
-            vboxScreenMonOnChange();
-        }
-        case WM_CLOSE:
-            Log((__FUNCTION__": got WM_CLOSE for hwnd(0x%x)", hwnd));
-            return 0;
-        case WM_DESTROY:
-            Log((__FUNCTION__": got WM_DESTROY for hwnd(0x%x)", hwnd));
-            return 0;
-        case WM_NCHITTEST:
-            Log((__FUNCTION__": got WM_NCHITTEST for hwnd(0x%x)\n", hwnd));
-            return HTNOWHERE;
-    }
-
-    return DefWindowProc(hwnd, uMsg, wParam, lParam);
-}
-
-#define VBOXSCREENMONWND_NAME "VboxScreenMonWnd"
-
-static HRESULT vboxScreenMonWndCreate(HWND *phWnd)
-{
-    HRESULT hr = S_OK;
-    HINSTANCE hInstance = (HINSTANCE)GetModuleHandle(NULL);
-    /* Register the Window Class. */
-    WNDCLASS wc;
-    if (!GetClassInfo(hInstance, VBOXSCREENMONWND_NAME, &wc))
-    {
-        wc.style = 0;//CS_OWNDC;
-        wc.lpfnWndProc = vboxScreenMonWndProc;
-        wc.cbClsExtra = 0;
-        wc.cbWndExtra = 0;
-        wc.hInstance = hInstance;
-        wc.hIcon = NULL;
-        wc.hCursor = NULL;
-        wc.hbrBackground = NULL;
-        wc.lpszMenuName = NULL;
-        wc.lpszClassName = VBOXSCREENMONWND_NAME;
-        if (!RegisterClass(&wc))
-        {
-            DWORD winErr = GetLastError();
-            Log((__FUNCTION__": RegisterClass failed, winErr(%d)\n", winErr));
-            hr = E_FAIL;
-        }
-    }
-
-    if (hr == S_OK)
-    {
-        HWND hWnd = CreateWindowEx (WS_EX_TOOLWINDOW,
-                                        VBOXSCREENMONWND_NAME, VBOXSCREENMONWND_NAME,
-                                        WS_POPUP | WS_CLIPSIBLINGS | WS_CLIPCHILDREN | WS_DISABLED,
-                                        -100, -100,
-                                        10, 10,
-                                        NULL, //GetDesktopWindow() /* hWndParent */,
-                                        NULL /* hMenu */,
-                                        hInstance,
-                                        NULL /* lpParam */);
-        Assert(hWnd);
-        if (hWnd)
-        {
-            *phWnd = hWnd;
-        }
-        else
-        {
-            DWORD winErr = GetLastError();
-            Log((__FUNCTION__": CreateWindowEx failed, winErr(%d)\n", winErr));
-            hr = E_FAIL;
-        }
-    }
-
-    return hr;
-}
-
-static HRESULT vboxScreenMonWndDestroy(HWND hWnd)
-{
-    BOOL bResult = DestroyWindow(hWnd);
-    if (bResult)
-        return S_OK;
-
-    DWORD winErr = GetLastError();
-    Log((__FUNCTION__": DestroyWindow failed, winErr(%d) for hWnd(0x%x)\n", winErr, hWnd));
-    Assert(0);
-
-    return HRESULT_FROM_WIN32(winErr);
-}
-
-static HRESULT vboxScreenMonWndInit()
-{
-    PVBOXSCREENMON pMon = &g_VBoxScreenMon;
-    return vboxScreenMonWndCreate(&pMon->hWnd);
-}
-
-HRESULT vboxScreenMonWndTerm()
-{
-    PVBOXSCREENMON pMon = &g_VBoxScreenMon;
-    HRESULT tmpHr = vboxScreenMonWndDestroy(pMon->hWnd);
-    Assert(tmpHr == S_OK);
-
-    HINSTANCE hInstance = (HINSTANCE)GetModuleHandle(NULL);
-    UnregisterClass(VBOXSCREENMONWND_NAME, hInstance);
-
-    return S_OK;
-}
-
-#define WM_VBOXSCREENMON_INIT_QUIT (WM_APP+2)
-
-HRESULT vboxScreenMonRun()
-{
-    PVBOXSCREENMON pMon = &g_VBoxScreenMon;
-    MSG Msg;
-
-    HRESULT hr = S_FALSE;
-
-    PeekMessage(&Msg,
-            NULL /* HWND hWnd */,
-            WM_USER /* UINT wMsgFilterMin */,
-            WM_USER /* UINT wMsgFilterMax */,
-            PM_NOREMOVE);
-
-    BOOL bCheck = TRUE;
-
-    do
-    {
-        if (bCheck)
-        {
-            vboxScreenMonOnChange();
-
-            bCheck = FALSE;
-        }
-
-        BOOL bResult = GetMessage(&Msg,
-            0 /*HWND hWnd*/,
-            0 /*UINT wMsgFilterMin*/,
-            0 /*UINT wMsgFilterMax*/
-            );
-
-        if(!bResult) /* WM_QUIT was posted */
-        {
-            hr = S_FALSE;
-            break;
-        }
-
-        if(bResult == -1) /* error occurred */
-        {
-            DWORD winEr = GetLastError();
-            hr = HRESULT_FROM_WIN32(winEr);
-            Assert(0);
-            /* just ensure we never return success in this case */
-            Assert(hr != S_OK);
-            Assert(hr != S_FALSE);
-            if (hr == S_OK || hr == S_FALSE)
-                hr = E_FAIL;
-            break;
-        }
-
-        switch (Msg.message)
-        {
-            case WM_VBOXSCREENMON_INIT_QUIT:
-            case WM_CLOSE:
-            {
-                PostQuitMessage(0);
-                break;
-            }
-            case WM_DISPLAYCHANGE:
-                bCheck = TRUE;
-            default:
-                TranslateMessage(&Msg);
-                DispatchMessage(&Msg);
-                break;
-        }
-    } while (1);
-    return 0;
-}
-
-static DWORD WINAPI vboxScreenMonRunnerThread(void *pvUser)
-{
-    PVBOXSCREENMON pMon = &g_VBoxScreenMon;
-
-    BOOL bRc = SetEvent(pMon->hEvent);
-    if (!bRc)
-    {
-        DWORD winErr = GetLastError();
-        Log((__FUNCTION__": SetEvent failed, winErr = (%d)", winErr));
-        HRESULT tmpHr = HRESULT_FROM_WIN32(winErr);
-        Assert(0);
-        Assert(tmpHr != S_OK);
-    }
-
-    HRESULT hr = vboxScreenMonWndInit();
-    Assert(hr == S_OK);
-    if (hr == S_OK)
-    {
-        hr = vboxScreenMonRun();
-        Assert(hr == S_OK);
-
-        vboxScreenMonWndTerm();
-    }
-
-    return 0;
-}
-
-HRESULT VBoxScreenMonInit(PFNVBOXSCREENMONRUNNER_CB pfnCb, void *pvCb)
-{
-    HRESULT hr = E_FAIL;
-    PVBOXSCREENMON pMon = &g_VBoxScreenMon;
-    memset(pMon, 0, sizeof (*pMon));
-
-    pMon->pfnCb = pfnCb;
-    pMon->pvCb = pvCb;
-
-    pMon->hEvent = CreateEvent(NULL, /* LPSECURITY_ATTRIBUTES lpEventAttributes*/
-            TRUE, /* BOOL bManualReset*/
-            FALSE, /* BOOL bInitialState */
-            NULL /* LPCTSTR lpName */
-          );
-    if (pMon->hEvent)
-    {
-        pMon->hThread = CreateThread(NULL /* LPSECURITY_ATTRIBUTES lpThreadAttributes */,
-                                              0 /* SIZE_T dwStackSize */,
-                                              vboxScreenMonRunnerThread,
-                                              pMon,
-                                              0 /* DWORD dwCreationFlags */,
-                                              &pMon->idThread);
-        if (pMon->hThread)
-        {
-            DWORD dwResult = WaitForSingleObject(pMon->hEvent, INFINITE);
-            if (dwResult == WAIT_OBJECT_0)
-                return S_OK;
-            else
-            {
-                Log(("WaitForSingleObject failed!"));
-                hr = E_FAIL;
-            }
-        }
-        else
-        {
-            DWORD winErr = GetLastError();
-            Log((__FUNCTION__": CreateThread failed, winErr = (%d)", winErr));
-            hr = HRESULT_FROM_WIN32(winErr);
-            Assert(0);
-            Assert(hr != S_OK);
-        }
-        CloseHandle(pMon->hEvent);
-    }
-    else
-    {
-        DWORD winErr = GetLastError();
-        Log((__FUNCTION__": CreateEvent failed, winErr = (%d)", winErr));
-        hr = HRESULT_FROM_WIN32(winErr);
-        Assert(0);
-        Assert(hr != S_OK);
-    }
-
-    return hr;
-}
-
-VOID VBoxScreenMonTerm()
-{
-    HRESULT hr;
-    PVBOXSCREENMON pMon = &g_VBoxScreenMon;
-    if (!pMon->hThread)
-        return;
-
-    BOOL bResult = PostThreadMessage(pMon->idThread, WM_VBOXSCREENMON_INIT_QUIT, 0, 0);
-    DWORD winErr;
-    if (bResult
-            || (winErr = GetLastError()) == ERROR_INVALID_THREAD_ID) /* <- could be that the thread is terminated */
-    {
-        DWORD dwErr = WaitForSingleObject(pMon->hThread, INFINITE);
-        if (dwErr == WAIT_OBJECT_0)
-        {
-            hr = S_OK;
-        }
-        else
-        {
-            winErr = GetLastError();
-            hr = HRESULT_FROM_WIN32(winErr);
-            Assert(0);
-        }
-    }
-    else
-    {
-        hr = HRESULT_FROM_WIN32(winErr);
-        Assert(0);
-    }
-
-    CloseHandle(pMon->hThread);
-    pMon->hThread = 0;
-    CloseHandle(pMon->hEvent);
-    pMon->hThread = 0;
-}
-/**/
-
 typedef struct VBOXDISPIF_WDDM_INTERNAL
 {
     PCVBOXDISPIF pIf;
-
-    HANDLE hResizeEvent;
 } VBOXDISPIF_WDDM_INTERNAL, *PVBOXDISPIF_WDDM_INTERNAL;
 
@@ -920,38 +589,13 @@
 }
 
-static DECLCALLBACK(VOID) vboxDispIfWddmScreenMonCb(void *pvCb)
-{
-    PVBOXDISPIF_WDDM_INTERNAL pData = (PVBOXDISPIF_WDDM_INTERNAL)pvCb;
-
-    SetEvent(pData->hResizeEvent);
-}
-
 static DWORD vboxDispIfWddmInit(PCVBOXDISPIF pIf)
 {
     memset(&g_VBoxDispIfWddm, 0, sizeof (g_VBoxDispIfWddm));
     g_VBoxDispIfWddm.pIf = pIf;
-    g_VBoxDispIfWddm.hResizeEvent = CreateEvent(NULL,
-                FALSE, /* BOOL bManualReset */
-                FALSE, /* BOOL bInitialState */
-                NULL /* LPCTSTR lpName */
-          );
-    if (g_VBoxDispIfWddm.hResizeEvent)
-    {
-        HRESULT hr = VBoxScreenMonInit(vboxDispIfWddmScreenMonCb, &g_VBoxDispIfWddm);
-        if (SUCCEEDED(hr))
-        {
-            /* ensure event is reset */
-            WaitForSingleObject(g_VBoxDispIfWddm.hResizeEvent, 0);
-            return ERROR_SUCCESS;
-        }
-        CloseHandle(g_VBoxDispIfWddm.hResizeEvent);
-    }
-    return ERROR_GEN_FAILURE;
+    return ERROR_SUCCESS;
 }
 
 static void vboxDispIfWddmTerm(PCVBOXDISPIF pIf)
 {
-    VBoxScreenMonTerm();
-    CloseHandle(g_VBoxDispIfWddm.hResizeEvent);
     memset(&g_VBoxDispIfWddm, 0, sizeof (g_VBoxDispIfWddm));
 }
@@ -1182,7 +826,4 @@
          * make the driver invalidate VidPn,
          * which is done by emulating a monitor re-plug currently */
-        /* ensure event is reset */
-        WaitForSingleObject(g_VBoxDispIfWddm.hResizeEvent, 0);
-
         uint8_t ScreenMask[VBOXWDDM_SCREENMASK_SIZE] = {0};
         ASMBitSet(ScreenMask, iChangedMode);
@@ -1190,12 +831,4 @@
 
         winEr = vboxDispIfWddmValidateFixResize(pIf, paDisplayDevices, paDeviceModes, cDevModes);
-
-//        for (UINT i = 0; i < 4; ++i)
-//        {
-//            WaitForSingleObject(g_VBoxDispIfWddm.hResizeEvent, 500);
-//            winEr = vboxDispIfWddmValidateFixResize(pIf, paDisplayDevices, paDeviceModes, cDevModes);
-//            if (winEr == NO_ERROR)
-//                break;
-//        }
 
         Assert(winEr == NO_ERROR);
