Win32: Fix message pump filtering during init

Fixes #886.
This commit is contained in:
Camilla Löwy 2019-03-21 02:05:49 +01:00
parent 8d4fd40b64
commit 5292914ce1

View File

@ -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, _glfw.win32.helperWindowHandle =
L"GLFW message window", CreateWindowExW(WS_EX_OVERLAPPEDWINDOW,
WS_CLIPSIBLINGS | WS_CLIPCHILDREN, _GLFW_WNDCLASSNAME,
0, 0, 1, 1, L"GLFW message window",
NULL, NULL, WS_CLIPSIBLINGS | WS_CLIPCHILDREN,
GetModuleHandleW(NULL), 0, 0, 1, 1,
NULL); NULL, NULL,
if (!window) 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 (!createHelperWindow())
if (!_glfw.win32.helperWindowHandle)
return GLFW_FALSE; return GLFW_FALSE;
_glfwInitTimerWin32(); _glfwInitTimerWin32();