diff --git a/src/win32_init.c b/src/win32_init.c index 8542803f..c176e006 100644 --- a/src/win32_init.c +++ b/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(); } diff --git a/src/win32_platform.h b/src/win32_platform.h index e329c493..9124b440 100644 --- a/src/win32_platform.h +++ b/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]; diff --git a/src/win32_window.c b/src/win32_window.c index 756f4aa4..35e3a7d1 100644 --- a/src/win32_window.c +++ b/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;