Cleaned up the app registration stuff a bit
authorSam Lantinga <slouken@libsdl.org>
Sun, 29 Jan 2006 09:13:36 +0000
changeset 1288ea3888b472bf
parent 1287 15a89a0c52bf
child 1289 c07c6ef7c93e
Cleaned up the app registration stuff a bit
src/video/wincommon/SDL_sysevents.c
src/video/windib/SDL_dibevents.c
src/video/windib/SDL_dibvideo.c
src/video/windx5/SDL_dx5events.c
src/video/windx5/SDL_dx5video.c
     1.1 --- a/src/video/wincommon/SDL_sysevents.c	Sun Jan 29 08:50:06 2006 +0000
     1.2 +++ b/src/video/wincommon/SDL_sysevents.c	Sun Jan 29 09:13:36 2006 +0000
     1.3 @@ -58,6 +58,7 @@
     1.4  #else
     1.5  LPSTR SDL_Appname = NULL;
     1.6  #endif
     1.7 +Uint32 SDL_Appstyle = 0;
     1.8  HINSTANCE SDL_Instance = NULL;
     1.9  HWND SDL_Window = NULL;
    1.10  RECT SDL_bounds = {0, 0, 0, 0};
    1.11 @@ -693,36 +694,40 @@
    1.12  		return(0);
    1.13  	}
    1.14  
    1.15 -	/* This function needs to be passed the correct process handle
    1.16 -	   by the application.
    1.17 -	 */
    1.18 -	if ( ! hInst ) {
    1.19 -		hInst = SDL_GetModuleHandle();
    1.20 +#ifndef CS_BYTEALIGNCLIENT
    1.21 +#define CS_BYTEALIGNCLIENT	0
    1.22 +#endif
    1.23 +	if ( ! name && ! SDL_Appname ) {
    1.24 +		name = "SDL_app";
    1.25 +		SDL_Appstyle = CS_BYTEALIGNCLIENT;
    1.26 +		SDL_Instance = hInst ? hInst : SDL_GetModuleHandle();
    1.27 +	}
    1.28 +
    1.29 +	if ( name ) {
    1.30 +#ifdef _WIN32_WCE
    1.31 +		/* WinCE uses the UNICODE version */
    1.32 +		int nLen = strlen(name)+1;
    1.33 +		SDL_Appname = malloc(nLen*2);
    1.34 +		MultiByteToWideChar(CP_ACP, 0, name, -1, SDL_Appname, nLen);
    1.35 +#else
    1.36 +		int nLen = strlen(name)+1;
    1.37 +		SDL_Appname = malloc(nLen);
    1.38 +		strcpy(SDL_Appname, name);
    1.39 +#endif /* _WIN32_WCE */
    1.40 +		SDL_Appstyle = style;
    1.41 +		SDL_Instance = hInst ? hInst : SDL_GetModuleHandle();
    1.42  	}
    1.43  
    1.44  	/* Register the application class */
    1.45  	class.hCursor		= NULL;
    1.46 -#ifdef _WIN32_WCE
    1.47 -	{
    1.48 -		/* WinCE uses the UNICODE version */
    1.49 -		int nLen = strlen(name)+1;
    1.50 -		SDL_Appname = malloc(nLen*2);
    1.51 -		MultiByteToWideChar(CP_ACP, 0, name, -1, SDL_Appname, nLen);
    1.52 -	}
    1.53 -#else
    1.54 -	{
    1.55 -		int nLen = strlen(name)+1;
    1.56 -		SDL_Appname = malloc(nLen);
    1.57 -		strcpy(SDL_Appname, name);
    1.58 -	}
    1.59 -#endif /* _WIN32_WCE */
    1.60 -	class.hIcon		= LoadImage(hInst, SDL_Appname, IMAGE_ICON,
    1.61 +	class.hIcon		= LoadImage(SDL_Instance, SDL_Appname,
    1.62 +				            IMAGE_ICON,
    1.63  	                                    0, 0, LR_DEFAULTCOLOR);
    1.64  	class.lpszMenuName	= NULL;
    1.65  	class.lpszClassName	= SDL_Appname;
    1.66  	class.hbrBackground	= NULL;
    1.67 -	class.hInstance		= hInst;
    1.68 -	class.style		= style;
    1.69 +	class.hInstance		= SDL_Instance;
    1.70 +	class.style		= SDL_Appstyle;
    1.71  #ifdef HAVE_OPENGL
    1.72  	class.style		|= CS_OWNDC;
    1.73  #endif
    1.74 @@ -733,7 +738,6 @@
    1.75  		SDL_SetError("Couldn't register application class");
    1.76  		return(-1);
    1.77  	}
    1.78 -	SDL_Instance = hInst;
    1.79  
    1.80  #ifdef WM_MOUSELEAVE
    1.81  	/* Get the version of TrackMouseEvent() we use */
    1.82 @@ -757,23 +761,19 @@
    1.83  	return(0);
    1.84  }
    1.85  
    1.86 -/*
    1.87 - * Unregisters the windowclass registered in SDL_RegisterApp above.
    1.88 - *  Called from DIB_VideoQuit and DX5_VideoQuit when
    1.89 - *  SDL_QuitSubSystem(INIT_VIDEO) is called.
    1.90 - */
    1.91 +/* Unregisters the windowclass registered in SDL_RegisterApp above. */
    1.92  void SDL_UnregisterApp()
    1.93  {
    1.94  	WNDCLASS class;
    1.95  
    1.96  	/* SDL_RegisterApp might not have been called before */
    1.97 -	if (app_registered) {
    1.98 -		/* Check for any registered windowclasses. */
    1.99 -		if (GetClassInfo(SDL_Instance, SDL_Appname, &class)) {
   1.100 +	if ( app_registered ) {
   1.101 +		/* Check for any registered window classes. */
   1.102 +		if ( GetClassInfo(SDL_Instance, SDL_Appname, &class) ) {
   1.103  			UnregisterClass(SDL_Appname, SDL_Instance);
   1.104  		}
   1.105 +		app_registered = 0;
   1.106  	}
   1.107 -	app_registered = 0;
   1.108  }
   1.109  
   1.110  #ifndef NO_GETKEYBOARDSTATE
     2.1 --- a/src/video/windib/SDL_dibevents.c	Sun Jan 29 08:50:06 2006 +0000
     2.2 +++ b/src/video/windib/SDL_dibevents.c	Sun Jan 29 09:13:36 2006 +0000
     2.3 @@ -406,10 +406,7 @@
     2.4  {
     2.5  	char *windowid = getenv("SDL_WINDOWID");
     2.6  
     2.7 -#ifndef CS_BYTEALIGNCLIENT
     2.8 -#define CS_BYTEALIGNCLIENT	0
     2.9 -#endif
    2.10 -	SDL_RegisterApp("SDL_app", CS_BYTEALIGNCLIENT, 0);
    2.11 +	SDL_RegisterApp(NULL, 0, 0);
    2.12  
    2.13  	SDL_windowid = (windowid != NULL);
    2.14  	if ( SDL_windowid ) {
    2.15 @@ -452,4 +449,5 @@
    2.16  	} else {
    2.17  		DestroyWindow(SDL_Window);
    2.18  	}
    2.19 +	SDL_UnregisterApp();
    2.20  }
     3.1 --- a/src/video/windib/SDL_dibvideo.c	Sun Jan 29 08:50:06 2006 +0000
     3.2 +++ b/src/video/windib/SDL_dibvideo.c	Sun Jan 29 09:13:36 2006 +0000
     3.3 @@ -958,7 +958,6 @@
     3.4  		}
     3.5  		DIB_QuitGamma(this);
     3.6  		DIB_DestroyWindow(this);
     3.7 -		SDL_UnregisterApp();
     3.8  		FlushMessageQueue();
     3.9  
    3.10  		SDL_Window = NULL;
     4.1 --- a/src/video/windx5/SDL_dx5events.c	Sun Jan 29 08:50:06 2006 +0000
     4.2 +++ b/src/video/windx5/SDL_dx5events.c	Sun Jan 29 09:13:36 2006 +0000
     4.3 @@ -858,10 +858,7 @@
     4.4  		SDL_DIfun[i] = NULL;
     4.5  	}
     4.6  
     4.7 -#ifndef CS_BYTEALIGNCLIENT
     4.8 -#define CS_BYTEALIGNCLIENT	0
     4.9 -#endif
    4.10 -	SDL_RegisterApp("SDL_app", CS_BYTEALIGNCLIENT, 0);
    4.11 +	SDL_RegisterApp(NULL, 0, 0);
    4.12  
    4.13  	SDL_windowid = (windowid != NULL);
    4.14  	if ( SDL_windowid ) {
    4.15 @@ -907,4 +904,5 @@
    4.16  	} else {
    4.17  		DestroyWindow(SDL_Window);
    4.18  	}
    4.19 +	SDL_UnregisterApp();
    4.20  }
     5.1 --- a/src/video/windx5/SDL_dx5video.c	Sun Jan 29 08:50:06 2006 +0000
     5.2 +++ b/src/video/windx5/SDL_dx5video.c	Sun Jan 29 09:13:36 2006 +0000
     5.3 @@ -2387,7 +2387,6 @@
     5.4  	DIB_QuitGamma(this);
     5.5  	if ( SDL_Window ) {
     5.6  		DX5_DestroyWindow(this);
     5.7 -		SDL_UnregisterApp();
     5.8  		FlushMessageQueue();
     5.9  	}
    5.10