src/video/wincommon/SDL_sysevents.c
changeset 145 29a638dc26db
parent 61 994ed1d668e7
child 149 0e66fd980014
     1.1 --- a/src/video/wincommon/SDL_sysevents.c	Thu Aug 09 06:14:06 2001 +0000
     1.2 +++ b/src/video/wincommon/SDL_sysevents.c	Thu Aug 09 12:21:32 2001 +0000
     1.3 @@ -145,8 +145,10 @@
     1.4  #endif /* !NO_GETKEYBOARDSTATE */
     1.5  }
     1.6  
     1.7 -/* The main Win32 event handler */
     1.8 -static LONG CALLBACK WinMessage(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
     1.9 +/* The main Win32 event handler
    1.10 +DJM: This is no longer static as (DX5/DIB)_CreateWindow needs it
    1.11 +*/
    1.12 +LONG CALLBACK WinMessage(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
    1.13  {
    1.14  	SDL_VideoDevice *this = current_video;
    1.15  	static int mouse_pressed = 0;
    1.16 @@ -265,6 +267,13 @@
    1.17  				Sint16 x, y;
    1.18  				Uint8 button, state;
    1.19  
    1.20 +				/* DJM:
    1.21 +				   We want the SDL window to take focus so that
    1.22 +				   it acts like a normal windows "component"
    1.23 +				   (e.g. gains keyboard focus on a mouse click).
    1.24 +				 */
    1.25 +				SetFocus(SDL_Window);
    1.26 +
    1.27  				/* Figure out which button to use */
    1.28  				switch (msg) {
    1.29  					case WM_LBUTTONDOWN:
    1.30 @@ -465,10 +474,11 @@
    1.31  		}
    1.32  		return(0);
    1.33  
    1.34 +		/* DJM: Send an expose event in this case */
    1.35  		case WM_ERASEBKGND: {
    1.36 -			/* Just do nothing */ ;
    1.37 +			posted = SDL_PrivateExpose();
    1.38  		}
    1.39 -		return(1);
    1.40 +		return(0);
    1.41  
    1.42  		case WM_CLOSE: {
    1.43  			if ( (posted = SDL_PrivateQuit()) )
    1.44 @@ -493,11 +503,35 @@
    1.45  	return(DefWindowProc(hwnd, msg, wParam, lParam));
    1.46  }
    1.47  
    1.48 +/* Allow the application handle to be stored and retrieved later */
    1.49 +static HMODULE SDL_handle = NULL;
    1.50 +
    1.51 +void SDL_SetModuleHandle(HMODULE handle)
    1.52 +{
    1.53 +	SDL_handle = handle;
    1.54 +}
    1.55 +HMODULE SDL_GetModuleHandle(void)
    1.56 +{
    1.57 +	void *handle;
    1.58 +
    1.59 +	if ( SDL_handle ) {
    1.60 +		handle = SDL_handle;
    1.61 +	} else {
    1.62 +		/* Warning:
    1.63 +		   If SDL is built as a DLL, this will return a handle to
    1.64 +		   the DLL, not the application, and DirectInput may fail
    1.65 +		   to initialize.
    1.66 +		 */
    1.67 +		handle = GetModuleHandle(NULL);
    1.68 +	}
    1.69 +	return(handle);
    1.70 +}
    1.71 +
    1.72  /* This allows the SDL_WINDOWID hack */
    1.73  const char *SDL_windowid = NULL;
    1.74  
    1.75  /* Register the class for this application -- exported for winmain.c */
    1.76 -int SDL_RegisterApp(char *name, Uint32 style, void *hInst)
    1.77 +int SDL_RegisterApp(char *name, Uint32 style, HMODULE hInst)
    1.78  {
    1.79  	static int initialized = 0;
    1.80  	WNDCLASS class;
    1.81 @@ -511,12 +545,10 @@
    1.82  	}
    1.83  
    1.84  	/* This function needs to be passed the correct process handle
    1.85 -	   by the application.  The following call just returns a handle
    1.86 -	   to the SDL DLL, which is useless for our purposes and causes
    1.87 -	   DirectInput to fail to initialize.
    1.88 +	   by the application.
    1.89  	 */
    1.90  	if ( ! hInst ) {
    1.91 -		hInst = GetModuleHandle(NULL);
    1.92 +		hInst = SDL_GetModuleHandle();
    1.93  	}
    1.94  
    1.95  	/* Register the application class */