Commit f708868d authored by Sam Lantinga's avatar Sam Lantinga

Cleaned up the app registration stuff a bit

--HG--
extra : convert_revision : svn%3Ac70aab31-4412-0410-b14c-859654838e24/trunk%401291
parent 31d40ce8
...@@ -58,6 +58,7 @@ LPWSTR SDL_Appname = NULL; ...@@ -58,6 +58,7 @@ LPWSTR SDL_Appname = NULL;
#else #else
LPSTR SDL_Appname = NULL; LPSTR SDL_Appname = NULL;
#endif #endif
Uint32 SDL_Appstyle = 0;
HINSTANCE SDL_Instance = NULL; HINSTANCE SDL_Instance = NULL;
HWND SDL_Window = NULL; HWND SDL_Window = NULL;
RECT SDL_bounds = {0, 0, 0, 0}; RECT SDL_bounds = {0, 0, 0, 0};
...@@ -693,36 +694,40 @@ int SDL_RegisterApp(char *name, Uint32 style, void *hInst) ...@@ -693,36 +694,40 @@ int SDL_RegisterApp(char *name, Uint32 style, void *hInst)
return(0); return(0);
} }
/* This function needs to be passed the correct process handle #ifndef CS_BYTEALIGNCLIENT
by the application. #define CS_BYTEALIGNCLIENT 0
*/ #endif
if ( ! hInst ) { if ( ! name && ! SDL_Appname ) {
hInst = SDL_GetModuleHandle(); name = "SDL_app";
SDL_Appstyle = CS_BYTEALIGNCLIENT;
SDL_Instance = hInst ? hInst : SDL_GetModuleHandle();
} }
/* Register the application class */ if ( name ) {
class.hCursor = NULL;
#ifdef _WIN32_WCE #ifdef _WIN32_WCE
{
/* WinCE uses the UNICODE version */ /* WinCE uses the UNICODE version */
int nLen = strlen(name)+1; int nLen = strlen(name)+1;
SDL_Appname = malloc(nLen*2); SDL_Appname = malloc(nLen*2);
MultiByteToWideChar(CP_ACP, 0, name, -1, SDL_Appname, nLen); MultiByteToWideChar(CP_ACP, 0, name, -1, SDL_Appname, nLen);
}
#else #else
{
int nLen = strlen(name)+1; int nLen = strlen(name)+1;
SDL_Appname = malloc(nLen); SDL_Appname = malloc(nLen);
strcpy(SDL_Appname, name); strcpy(SDL_Appname, name);
}
#endif /* _WIN32_WCE */ #endif /* _WIN32_WCE */
class.hIcon = LoadImage(hInst, SDL_Appname, IMAGE_ICON, SDL_Appstyle = style;
SDL_Instance = hInst ? hInst : SDL_GetModuleHandle();
}
/* Register the application class */
class.hCursor = NULL;
class.hIcon = LoadImage(SDL_Instance, SDL_Appname,
IMAGE_ICON,
0, 0, LR_DEFAULTCOLOR); 0, 0, LR_DEFAULTCOLOR);
class.lpszMenuName = NULL; class.lpszMenuName = NULL;
class.lpszClassName = SDL_Appname; class.lpszClassName = SDL_Appname;
class.hbrBackground = NULL; class.hbrBackground = NULL;
class.hInstance = hInst; class.hInstance = SDL_Instance;
class.style = style; class.style = SDL_Appstyle;
#ifdef HAVE_OPENGL #ifdef HAVE_OPENGL
class.style |= CS_OWNDC; class.style |= CS_OWNDC;
#endif #endif
...@@ -733,7 +738,6 @@ int SDL_RegisterApp(char *name, Uint32 style, void *hInst) ...@@ -733,7 +738,6 @@ int SDL_RegisterApp(char *name, Uint32 style, void *hInst)
SDL_SetError("Couldn't register application class"); SDL_SetError("Couldn't register application class");
return(-1); return(-1);
} }
SDL_Instance = hInst;
#ifdef WM_MOUSELEAVE #ifdef WM_MOUSELEAVE
/* Get the version of TrackMouseEvent() we use */ /* Get the version of TrackMouseEvent() we use */
...@@ -757,23 +761,19 @@ int SDL_RegisterApp(char *name, Uint32 style, void *hInst) ...@@ -757,23 +761,19 @@ int SDL_RegisterApp(char *name, Uint32 style, void *hInst)
return(0); return(0);
} }
/* /* Unregisters the windowclass registered in SDL_RegisterApp above. */
* Unregisters the windowclass registered in SDL_RegisterApp above.
* Called from DIB_VideoQuit and DX5_VideoQuit when
* SDL_QuitSubSystem(INIT_VIDEO) is called.
*/
void SDL_UnregisterApp() void SDL_UnregisterApp()
{ {
WNDCLASS class; WNDCLASS class;
/* SDL_RegisterApp might not have been called before */ /* SDL_RegisterApp might not have been called before */
if (app_registered) { if ( app_registered ) {
/* Check for any registered windowclasses. */ /* Check for any registered window classes. */
if (GetClassInfo(SDL_Instance, SDL_Appname, &class)) { if ( GetClassInfo(SDL_Instance, SDL_Appname, &class) ) {
UnregisterClass(SDL_Appname, SDL_Instance); UnregisterClass(SDL_Appname, SDL_Instance);
} }
app_registered = 0;
} }
app_registered = 0;
} }
#ifndef NO_GETKEYBOARDSTATE #ifndef NO_GETKEYBOARDSTATE
......
...@@ -406,10 +406,7 @@ int DIB_CreateWindow(_THIS) ...@@ -406,10 +406,7 @@ int DIB_CreateWindow(_THIS)
{ {
char *windowid = getenv("SDL_WINDOWID"); char *windowid = getenv("SDL_WINDOWID");
#ifndef CS_BYTEALIGNCLIENT SDL_RegisterApp(NULL, 0, 0);
#define CS_BYTEALIGNCLIENT 0
#endif
SDL_RegisterApp("SDL_app", CS_BYTEALIGNCLIENT, 0);
SDL_windowid = (windowid != NULL); SDL_windowid = (windowid != NULL);
if ( SDL_windowid ) { if ( SDL_windowid ) {
...@@ -452,4 +449,5 @@ void DIB_DestroyWindow(_THIS) ...@@ -452,4 +449,5 @@ void DIB_DestroyWindow(_THIS)
} else { } else {
DestroyWindow(SDL_Window); DestroyWindow(SDL_Window);
} }
SDL_UnregisterApp();
} }
...@@ -958,7 +958,6 @@ void DIB_VideoQuit(_THIS) ...@@ -958,7 +958,6 @@ void DIB_VideoQuit(_THIS)
} }
DIB_QuitGamma(this); DIB_QuitGamma(this);
DIB_DestroyWindow(this); DIB_DestroyWindow(this);
SDL_UnregisterApp();
FlushMessageQueue(); FlushMessageQueue();
SDL_Window = NULL; SDL_Window = NULL;
......
...@@ -858,10 +858,7 @@ int DX5_CreateWindow(_THIS) ...@@ -858,10 +858,7 @@ int DX5_CreateWindow(_THIS)
SDL_DIfun[i] = NULL; SDL_DIfun[i] = NULL;
} }
#ifndef CS_BYTEALIGNCLIENT SDL_RegisterApp(NULL, 0, 0);
#define CS_BYTEALIGNCLIENT 0
#endif
SDL_RegisterApp("SDL_app", CS_BYTEALIGNCLIENT, 0);
SDL_windowid = (windowid != NULL); SDL_windowid = (windowid != NULL);
if ( SDL_windowid ) { if ( SDL_windowid ) {
...@@ -907,4 +904,5 @@ void DX5_DestroyWindow(_THIS) ...@@ -907,4 +904,5 @@ void DX5_DestroyWindow(_THIS)
} else { } else {
DestroyWindow(SDL_Window); DestroyWindow(SDL_Window);
} }
SDL_UnregisterApp();
} }
...@@ -2387,7 +2387,6 @@ void DX5_VideoQuit(_THIS) ...@@ -2387,7 +2387,6 @@ void DX5_VideoQuit(_THIS)
DIB_QuitGamma(this); DIB_QuitGamma(this);
if ( SDL_Window ) { if ( SDL_Window ) {
DX5_DestroyWindow(this); DX5_DestroyWindow(this);
SDL_UnregisterApp();
FlushMessageQueue(); FlushMessageQueue();
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment