Browse Source

Win32: Fix message pump filtering during init

Fixes #886.
Camilla Löwy 6 năm trước cách đây
mục cha
commit
5292914ce1
1 tập tin đã thay đổi với 18 bổ sung16 xóa
  1. 18 16
      src/win32_init.c

+ 18 - 16
src/win32_init.c

@@ -329,27 +329,30 @@ static void createKeyTables(void)
 
 
 // Creates a dummy window for behind-the-scenes work
 // Creates a dummy window for behind-the-scenes work
 //
 //
-static HWND createHelperWindow(void)
+static GLFWbool createHelperWindow(void)
 {
 {
     MSG msg;
     MSG msg;
-    HWND window = CreateWindowExW(WS_EX_OVERLAPPEDWINDOW,
-                                  _GLFW_WNDCLASSNAME,
-                                  L"GLFW message window",
-                                  WS_CLIPSIBLINGS | WS_CLIPCHILDREN,
-                                  0, 0, 1, 1,
-                                  NULL, NULL,
-                                  GetModuleHandleW(NULL),
-                                  NULL);
-    if (!window)
+
+    _glfw.win32.helperWindowHandle =
+        CreateWindowExW(WS_EX_OVERLAPPEDWINDOW,
+                        _GLFW_WNDCLASSNAME,
+                        L"GLFW message window",
+                        WS_CLIPSIBLINGS | WS_CLIPCHILDREN,
+                        0, 0, 1, 1,
+                        NULL, NULL,
+                        GetModuleHandleW(NULL),
+                        NULL);
+
+    if (!_glfw.win32.helperWindowHandle)
     {
     {
         _glfwInputErrorWin32(GLFW_PLATFORM_ERROR,
         _glfwInputErrorWin32(GLFW_PLATFORM_ERROR,
                              "Win32: Failed to create helper window");
                              "Win32: Failed to create helper window");
-        return NULL;
+        return GLFW_FALSE;
     }
     }
 
 
     // HACK: The command to the first ShowWindow call is ignored if the parent
     // HACK: The command to the first ShowWindow call is ignored if the parent
     //       process passed along a STARTUPINFO, so clear that with a no-op call
     //       process passed along a STARTUPINFO, so clear that with a no-op call
-    ShowWindow(window, SW_HIDE);
+    ShowWindow(_glfw.win32.helperWindowHandle, SW_HIDE);
 
 
     // Register for HID device notifications
     // Register for HID device notifications
     {
     {
@@ -360,7 +363,7 @@ static HWND createHelperWindow(void)
         dbi.dbcc_classguid = GUID_DEVINTERFACE_HID;
         dbi.dbcc_classguid = GUID_DEVINTERFACE_HID;
 
 
         _glfw.win32.deviceNotificationHandle =
         _glfw.win32.deviceNotificationHandle =
-            RegisterDeviceNotificationW(window,
+            RegisterDeviceNotificationW(_glfw.win32.helperWindowHandle,
                                         (DEV_BROADCAST_HDR*) &dbi,
                                         (DEV_BROADCAST_HDR*) &dbi,
                                         DEVICE_NOTIFY_WINDOW_HANDLE);
                                         DEVICE_NOTIFY_WINDOW_HANDLE);
     }
     }
@@ -371,7 +374,7 @@ static HWND createHelperWindow(void)
         DispatchMessageW(&msg);
         DispatchMessageW(&msg);
     }
     }
 
 
-   return window;
+   return GLFW_TRUE;
 }
 }
 
 
 
 
@@ -571,8 +574,7 @@ int _glfwPlatformInit(void)
     if (!_glfwRegisterWindowClassWin32())
     if (!_glfwRegisterWindowClassWin32())
         return GLFW_FALSE;
         return GLFW_FALSE;
 
 
-    _glfw.win32.helperWindowHandle = createHelperWindow();
-    if (!_glfw.win32.helperWindowHandle)
+    if (!createHelperWindow())
         return GLFW_FALSE;
         return GLFW_FALSE;
 
 
     _glfwInitTimerWin32();
     _glfwInitTimerWin32();