Add Win32 helper window

This commit is contained in:
Camilla Berglund 2015-11-03 15:28:56 +01:00
parent b4b210526a
commit 4cd493dd9a
3 changed files with 52 additions and 15 deletions

View File

@ -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 ////// ////// GLFW internal API //////
@ -355,6 +377,12 @@ int _glfwPlatformInit(void)
if (!_glfwRegisterWindowClass()) if (!_glfwRegisterWindowClass())
return GLFW_FALSE; return GLFW_FALSE;
_glfw.win32.helperWindow = createHelperWindow();
if (!_glfw.win32.helperWindow)
return GLFW_FALSE;
_glfwPlatformPollEvents();
if (!_glfwInitContextAPI()) if (!_glfwInitContextAPI())
return GLFW_FALSE; return GLFW_FALSE;
@ -378,6 +406,9 @@ void _glfwPlatformTerminate(void)
_glfwTerminateJoysticks(); _glfwTerminateJoysticks();
_glfwTerminateContextAPI(); _glfwTerminateContextAPI();
if (_glfw.win32.helperWindow)
DestroyWindow(_glfw.win32.helperWindow);
freeLibraries(); freeLibraries();
} }

View File

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

View File

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