瀏覽代碼

Add Win32 helper window

Camilla Berglund 10 年之前
父節點
當前提交
4cd493dd9a
共有 3 個文件被更改,包括 52 次插入15 次删除
  1. 31 0
      src/win32_init.c
  2. 3 0
      src/win32_platform.h
  3. 18 15
      src/win32_window.c

+ 31 - 0
src/win32_init.c

@@ -263,6 +263,28 @@ static void createKeyTables(void)
     }
 }
 
+// Creates a dummy window for behind-the-scenes work
+//
+static HWND createHelperWindow(void)
+{
+    HWND window = CreateWindowExW(WS_EX_OVERLAPPEDWINDOW,
+                                  _GLFW_WNDCLASSNAME,
+                                  L"GLFW helper window",
+                                  WS_CLIPSIBLINGS | WS_CLIPCHILDREN,
+                                  0, 0, 1, 1,
+                                  NULL, NULL,
+                                  GetModuleHandleW(NULL),
+                                  NULL);
+    if (!window)
+    {
+        _glfwInputError(GLFW_PLATFORM_ERROR,
+                        "Win32: Failed to create helper window");
+        return NULL;
+    }
+
+    return window;
+}
+
 
 //////////////////////////////////////////////////////////////////////////
 //////                       GLFW internal API                      //////
@@ -355,6 +377,12 @@ int _glfwPlatformInit(void)
     if (!_glfwRegisterWindowClass())
         return GLFW_FALSE;
 
+    _glfw.win32.helperWindow = createHelperWindow();
+    if (!_glfw.win32.helperWindow)
+        return GLFW_FALSE;
+
+    _glfwPlatformPollEvents();
+
     if (!_glfwInitContextAPI())
         return GLFW_FALSE;
 
@@ -378,6 +406,9 @@ void _glfwPlatformTerminate(void)
     _glfwTerminateJoysticks();
     _glfwTerminateContextAPI();
 
+    if (_glfw.win32.helperWindow)
+        DestroyWindow(_glfw.win32.helperWindow);
+
     freeLibraries();
 }
 

+ 3 - 0
src/win32_platform.h

@@ -153,6 +153,8 @@ typedef HRESULT (WINAPI * SETPROCESSDPIAWARENESS_T)(PROCESS_DPI_AWARENESS);
  #error "No supported context creation API selected"
 #endif
 
+#define _GLFW_WNDCLASSNAME L"GLFW30"
+
 #define _GLFW_PLATFORM_WINDOW_STATE         _GLFWwindowWin32  win32
 #define _GLFW_PLATFORM_LIBRARY_WINDOW_STATE _GLFWlibraryWin32 win32
 #define _GLFW_PLATFORM_LIBRARY_TIME_STATE   _GLFWtimeWin32    win32_time
@@ -183,6 +185,7 @@ typedef struct _GLFWwindowWin32
 //
 typedef struct _GLFWlibraryWin32
 {
+    HWND                helperWindow;
     DWORD               foregroundLockTimeout;
     char*               clipboardString;
     char                keyName[64];

+ 18 - 15
src/win32_window.c

@@ -35,8 +35,6 @@
 
 #define _GLFW_KEY_INVALID -2
 
-#define _GLFW_WNDCLASSNAME L"GLFW30"
-
 // Returns the window style for the specified window
 //
 static DWORD getWindowStyle(const _GLFWwindow* window)
@@ -257,10 +255,25 @@ static LRESULT CALLBACK windowProc(HWND hWnd, UINT uMsg,
     _GLFWwindow* window = (_GLFWwindow*) GetWindowLongPtrW(hWnd, 0);
     if (!window)
     {
-        if (uMsg == WM_NCCREATE)
+        switch (uMsg)
         {
-            CREATESTRUCTW* cs = (CREATESTRUCTW*) lParam;
-            SetWindowLongPtrW(hWnd, 0, (LONG_PTR) cs->lpCreateParams);
+            case WM_NCCREATE:
+            {
+                CREATESTRUCTW* cs = (CREATESTRUCTW*) lParam;
+                SetWindowLongPtrW(hWnd, 0, (LONG_PTR) cs->lpCreateParams);
+                break;
+            }
+
+            case WM_DEVICECHANGE:
+            {
+                if (wParam == DBT_DEVNODES_CHANGED)
+                {
+                    _glfwInputMonitorChange();
+                    return TRUE;
+                }
+
+                break;
+            }
         }
 
         return DefWindowProcW(hWnd, uMsg, wParam, lParam);
@@ -596,16 +609,6 @@ static LRESULT CALLBACK windowProc(HWND hWnd, UINT uMsg,
             break;
         }
 
-        case WM_DEVICECHANGE:
-        {
-            if (DBT_DEVNODES_CHANGED == wParam)
-            {
-                _glfwInputMonitorChange();
-                return TRUE;
-            }
-            break;
-        }
-
         case WM_DROPFILES:
         {
             HDROP drop = (HDROP) wParam;