Window class cleanup.

This commit is contained in:
Camilla Berglund 2014-08-31 14:17:31 +02:00
parent 82dc6c8b8f
commit c85294e0b2
3 changed files with 56 additions and 54 deletions

View File

@ -211,6 +211,9 @@ int _glfwPlatformInit(void)
_control87(MCW_EM, MCW_EM);
#endif
if (!_glfwRegisterWindowClass())
return GL_FALSE;
if (!_glfwInitContextAPI())
return GL_FALSE;
@ -222,11 +225,7 @@ int _glfwPlatformInit(void)
void _glfwPlatformTerminate(void)
{
if (_glfw.win32.classAtom)
{
UnregisterClassW(_GLFW_WNDCLASSNAME, GetModuleHandleW(NULL));
_glfw.win32.classAtom = 0;
}
_glfwUnregisterWindowClass();
// Restore previous foreground lock timeout system setting
SystemParametersInfoW(SPI_SETFOREGROUNDLOCKTIMEOUT, 0,

View File

@ -130,10 +130,6 @@ typedef HRESULT (WINAPI * DWMISCOMPOSITIONENABLED_T)(BOOL*);
#define _glfw_DwmIsCompositionEnabled _glfw.win32.dwmapi.DwmIsCompositionEnabled
// We use versioned window class names in order not to cause conflicts
// between applications using different versions of GLFW
#define _GLFW_WNDCLASSNAME L"GLFW30"
#define _GLFW_RECREATION_NOT_NEEDED 0
#define _GLFW_RECREATION_REQUIRED 1
#define _GLFW_RECREATION_IMPOSSIBLE 2
@ -188,7 +184,6 @@ typedef struct _GLFWwindowWin32
//------------------------------------------------------------------------
typedef struct _GLFWlibraryWin32
{
ATOM classAtom;
DWORD foregroundLockTimeout;
char* clipboardString;
@ -255,6 +250,10 @@ typedef struct _GLFWtimeWin32
// Prototypes for platform specific internal functions
//========================================================================
// Window class
GLboolean _glfwRegisterWindowClass(void);
void _glfwUnregisterWindowClass(void);
// Desktop compositing
BOOL _glfwIsCompositionEnabled(void);

View File

@ -34,6 +34,8 @@
#define _GLFW_KEY_INVALID -2
#define _GLFW_WNDCLASSNAME L"GLFW30"
// Updates the cursor clip rect
//
@ -838,43 +840,6 @@ static void getFullWindowSize(_GLFWwindow* window,
*fullHeight = rect.bottom - rect.top;
}
// Registers the GLFW window class
//
static ATOM registerWindowClass(void)
{
WNDCLASSW wc;
ATOM classAtom;
// Set window class parameters
wc.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC;
wc.lpfnWndProc = (WNDPROC) windowProc;
wc.cbClsExtra = 0; // No extra class data
wc.cbWndExtra = sizeof(void*) + sizeof(int); // Make room for one pointer
wc.hInstance = GetModuleHandleW(NULL);
wc.hCursor = LoadCursorW(NULL, IDC_ARROW);
wc.hbrBackground = NULL; // No background
wc.lpszMenuName = NULL; // No menu
wc.lpszClassName = _GLFW_WNDCLASSNAME;
// Load user-provided icon if available
wc.hIcon = LoadIconW(GetModuleHandleW(NULL), L"GLFW_ICON");
if (!wc.hIcon)
{
// No user-provided icon found, load default icon
wc.hIcon = LoadIconW(NULL, IDI_WINLOGO);
}
classAtom = RegisterClassW(&wc);
if (!classAtom)
{
_glfwInputError(GLFW_PLATFORM_ERROR,
"Win32: Failed to register window class");
return 0;
}
return classAtom;
}
// Creates the GLFW window and rendering context
//
static int createWindow(_GLFWwindow* window,
@ -986,6 +951,52 @@ static void destroyWindow(_GLFWwindow* window)
}
//////////////////////////////////////////////////////////////////////////
////// GLFW internal API //////
//////////////////////////////////////////////////////////////////////////
// Registers the GLFW window class
//
GLboolean _glfwRegisterWindowClass(void)
{
WNDCLASSW wc;
wc.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC;
wc.lpfnWndProc = (WNDPROC) windowProc;
wc.cbClsExtra = 0; // No extra class data
wc.cbWndExtra = sizeof(void*) + sizeof(int); // Make room for one pointer
wc.hInstance = GetModuleHandleW(NULL);
wc.hCursor = LoadCursorW(NULL, IDC_ARROW);
wc.hbrBackground = NULL; // No background
wc.lpszMenuName = NULL; // No menu
wc.lpszClassName = _GLFW_WNDCLASSNAME;
// Load user-provided icon if available
wc.hIcon = LoadIconW(GetModuleHandleW(NULL), L"GLFW_ICON");
if (!wc.hIcon)
{
// No user-provided icon found, load default icon
wc.hIcon = LoadIconW(NULL, IDI_WINLOGO);
}
if (!RegisterClassW(&wc))
{
_glfwInputError(GLFW_PLATFORM_ERROR,
"Win32: Failed to register window class");
return GL_FALSE;
}
return GL_TRUE;
}
// Unregisters the GLFW window class
//
void _glfwUnregisterWindowClass(void)
{
UnregisterClassW(_GLFW_WNDCLASSNAME, GetModuleHandleW(NULL));
}
//////////////////////////////////////////////////////////////////////////
////// GLFW platform API //////
//////////////////////////////////////////////////////////////////////////
@ -997,13 +1008,6 @@ int _glfwPlatformCreateWindow(_GLFWwindow* window,
{
int status;
if (!_glfw.win32.classAtom)
{
_glfw.win32.classAtom = registerWindowClass();
if (!_glfw.win32.classAtom)
return GL_FALSE;
}
if (!createWindow(window, wndconfig, ctxconfig, fbconfig))
return GL_FALSE;