(patch tweaked a bit)
authorSam Lantinga <slouken@libsdl.org>
Tue, 14 Mar 2006 04:00:03 +0000
changeset 152321b1fbb53f4a
parent 1522 1078552c83a0
child 1524 38a12fd1a2c1
(patch tweaked a bit)

Date: Tue, 14 Mar 2006 03:30:11 +0000
From: Peter Mulholland
Subject: [SDL] Windows MessageBox() strangeness fixes

Hello all,

I *think* this should fix the issues that people were seeing with
MessageBox() not working and therefore assert() on mingw/msvc. Forgive
me if i've screwed up making the diff file - I'm a total newb when it
comes to things like CVS and diff.

It modifies a few files as I saw that FlushMessageQueue() was in both
the windx5 and windib driver, so I moved this into wincommon. It was
also in the gapi driver, so I changed that too. The function is now
WIN_FlushMessageQueue() in src/video/wincommon/SDL_syswm.c
src/video/gapi/SDL_gapivideo.c
src/video/wincommon/SDL_lowvideo.h
src/video/wincommon/SDL_sysevents.c
src/video/wincommon/SDL_wingl.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/gapi/SDL_gapivideo.c	Tue Mar 14 03:04:50 2006 +0000
     1.2 +++ b/src/video/gapi/SDL_gapivideo.c	Tue Mar 14 04:00:03 2006 +0000
     1.3 @@ -731,6 +731,12 @@
     1.4  	ShowWindow(SDL_Window, SW_SHOW);
     1.5  	SetForegroundWindow(SDL_Window);
     1.6  
     1.7 +	/* JC 14 Mar 2006
     1.8 +		Flush the message loop or this can cause big problems later
     1.9 +		Especially if the user decides to use dialog boxes or assert()!
    1.10 +	*/
    1.11 +	WIN_FlushMessageQueue();
    1.12 +
    1.13  	/* Open GAPI display */
    1.14  	if( !gapi->useVga && this->hidden->useGXOpenDisplay )
    1.15  		if( !gapi->gxFunc.GXOpenDisplay(SDL_Window, GX_FULLSCREEN) )
    1.16 @@ -1103,17 +1109,6 @@
    1.17  		gapi->gxFunc.GXEndDraw();
    1.18  }
    1.19  
    1.20 -static void FlushMessageQueue()
    1.21 -{
    1.22 -	MSG  msg;
    1.23 -	while ( PeekMessage(&msg, NULL, 0, 0, PM_REMOVE) ) {
    1.24 -		if ( msg.message == WM_QUIT ) break;
    1.25 -		TranslateMessage( &msg );
    1.26 -		DispatchMessage( &msg );
    1.27 -	}
    1.28 -}
    1.29 -
    1.30 -
    1.31  /* Note:  If we are terminated, this could be called in the middle of
    1.32     another SDL video routine -- notably UpdateRects.
    1.33  */
    1.34 @@ -1138,7 +1133,6 @@
    1.35  
    1.36  		DIB_DestroyWindow(this);
    1.37  		SDL_UnregisterApp();
    1.38 -		FlushMessageQueue();
    1.39  
    1.40  		SDL_Window = NULL;
    1.41  #if defined(_WIN32_WCE)
     2.1 --- a/src/video/wincommon/SDL_lowvideo.h	Tue Mar 14 03:04:50 2006 +0000
     2.2 +++ b/src/video/wincommon/SDL_lowvideo.h	Tue Mar 14 04:00:03 2006 +0000
     2.3 @@ -79,6 +79,8 @@
     2.4  /* Variables and functions exported to other parts of the native video
     2.5     subsystem (SDL_sysevents.c)
     2.6  */
     2.7 +extern void WIN_FlushMessageQueue();
     2.8 +
     2.9  /* Called by windows message loop when system palette is available */
    2.10  extern void (*WIN_RealizePalette)(_THIS);
    2.11  
     3.1 --- a/src/video/wincommon/SDL_sysevents.c	Tue Mar 14 03:04:50 2006 +0000
     3.2 +++ b/src/video/wincommon/SDL_sysevents.c	Tue Mar 14 04:00:03 2006 +0000
     3.3 @@ -169,6 +169,21 @@
     3.4  
     3.5  #endif
     3.6  
     3.7 +/* JC 14 Mar 2006
     3.8 +   This is used all over the place, in the windib driver and in the dx5 driver
     3.9 +   So we may as well stick it here instead of having multiple copies scattered
    3.10 +   about
    3.11 +*/
    3.12 +void WIN_FlushMessageQueue()
    3.13 +{
    3.14 +	MSG  msg;
    3.15 +	while ( PeekMessage(&msg, NULL, 0, 0, PM_REMOVE) ) {
    3.16 +		if ( msg.message == WM_QUIT ) break;
    3.17 +		TranslateMessage( &msg );
    3.18 +		DispatchMessage( &msg );
    3.19 +	}
    3.20 +}
    3.21 +
    3.22  static void SDL_RestoreGameMode(void)
    3.23  {
    3.24  #ifdef _WIN32_WCE
     4.1 --- a/src/video/wincommon/SDL_wingl.c	Tue Mar 14 03:04:50 2006 +0000
     4.2 +++ b/src/video/wincommon/SDL_wingl.c	Tue Mar 14 04:00:03 2006 +0000
     4.3 @@ -48,12 +48,16 @@
     4.4  		style = GetWindowLong(SDL_Window, GWL_STYLE);
     4.5  		GetWindowRect(SDL_Window, &rect);
     4.6  		DestroyWindow(SDL_Window);
     4.7 +		WIN_FlushMessageQueue();
     4.8 +
     4.9  		SDL_Window = CreateWindow(SDL_Appname, SDL_Appname,
    4.10  		                          style,
    4.11  		                          rect.left, rect.top,
    4.12  		                          (rect.right-rect.left)+1,
    4.13  		                          (rect.top-rect.bottom)+1,
    4.14  		                          NULL, NULL, SDL_Instance, NULL);
    4.15 +		WIN_FlushMessageQueue();
    4.16 +
    4.17  		if ( SDL_Window ) {
    4.18  			this->SetCaption(this, this->wm_title, this->wm_icon);
    4.19  		} else {
    4.20 @@ -118,6 +122,8 @@
    4.21  	hwnd = CreateWindow(SDL_Appname, SDL_Appname, WS_POPUP | WS_DISABLED,
    4.22  	                    0, 0, 10, 10,
    4.23  	                    NULL, NULL, SDL_Instance, NULL);
    4.24 +	WIN_FlushMessageQueue();
    4.25 +
    4.26  	hdc = GetDC(hwnd);
    4.27  
    4.28  	pformat = ChoosePixelFormat(hdc, &GL_pfd);
    4.29 @@ -158,6 +164,7 @@
    4.30  	}
    4.31  	ReleaseDC(hwnd, hdc);
    4.32  	DestroyWindow(hwnd);
    4.33 +	WIN_FlushMessageQueue();
    4.34  }
    4.35  
    4.36  #endif /* SDL_VIDEO_OPENGL */
     5.1 --- a/src/video/windib/SDL_dibevents.c	Tue Mar 14 03:04:50 2006 +0000
     5.2 +++ b/src/video/windib/SDL_dibevents.c	Tue Mar 14 04:00:03 2006 +0000
     5.3 @@ -438,6 +438,13 @@
     5.4  		}
     5.5  		ShowWindow(SDL_Window, SW_HIDE);
     5.6  	}
     5.7 +
     5.8 +	/* JC 14 Mar 2006
     5.9 +		Flush the message loop or this can cause big problems later
    5.10 +		Especially if the user decides to use dialog boxes or assert()!
    5.11 +	*/
    5.12 +	WIN_FlushMessageQueue();
    5.13 +
    5.14  	return(0);
    5.15  }
    5.16  
    5.17 @@ -449,4 +456,10 @@
    5.18  		DestroyWindow(SDL_Window);
    5.19  	}
    5.20  	SDL_UnregisterApp();
    5.21 +
    5.22 +	/* JC 14 Mar 2006
    5.23 +		Flush the message loop or this can cause big problems later
    5.24 +		Especially if the user decides to use dialog boxes or assert()!
    5.25 +	*/
    5.26 +	WIN_FlushMessageQueue();
    5.27  }
     6.1 --- a/src/video/windib/SDL_dibvideo.c	Tue Mar 14 03:04:50 2006 +0000
     6.2 +++ b/src/video/windib/SDL_dibvideo.c	Tue Mar 14 04:00:03 2006 +0000
     6.3 @@ -291,6 +291,7 @@
     6.4  	if ( DIB_CreateWindow(this) < 0 ) {
     6.5  		return(-1);
     6.6  	}
     6.7 +
     6.8  #if !SDL_AUDIO_DISABLED
     6.9  	DX5_SoundFocus(SDL_Window);
    6.10  #endif
    6.11 @@ -818,6 +819,12 @@
    6.12  		video->flags |= SDL_OPENGL;
    6.13  	}
    6.14  
    6.15 +	/* JC 14 Mar 2006
    6.16 +		Flush the message loop or this can cause big problems later
    6.17 +		Especially if the user decides to use dialog boxes or assert()!
    6.18 +	*/
    6.19 +	WIN_FlushMessageQueue();
    6.20 +
    6.21  	/* We're live! */
    6.22  	return(video);
    6.23  }
    6.24 @@ -1014,16 +1021,6 @@
    6.25  #endif /* !NO_GAMMA_SUPPORT */
    6.26  }
    6.27  
    6.28 -static void FlushMessageQueue()
    6.29 -{
    6.30 -	MSG  msg;
    6.31 -	while ( PeekMessage(&msg, NULL, 0, 0, PM_REMOVE) ) {
    6.32 -		if ( msg.message == WM_QUIT ) break;
    6.33 -		TranslateMessage( &msg );
    6.34 -		DispatchMessage( &msg );
    6.35 -	}
    6.36 -}
    6.37 -
    6.38  void DIB_VideoQuit(_THIS)
    6.39  {
    6.40  	/* Destroy the window and everything associated with it */
    6.41 @@ -1051,7 +1048,6 @@
    6.42  		}
    6.43  		DIB_QuitGamma(this);
    6.44  		DIB_DestroyWindow(this);
    6.45 -		FlushMessageQueue();
    6.46  
    6.47  		SDL_Window = NULL;
    6.48  
     7.1 --- a/src/video/windx5/SDL_dx5events.c	Tue Mar 14 03:04:50 2006 +0000
     7.2 +++ b/src/video/windx5/SDL_dx5events.c	Tue Mar 14 04:00:03 2006 +0000
     7.3 @@ -892,6 +892,12 @@
     7.4  		return(-1);
     7.5  	}
     7.6  
     7.7 +	/* JC 14 Mar 2006
     7.8 +		Flush the message loop or this can cause big problems later
     7.9 +		Especially if the user decides to use dialog boxes or assert()!
    7.10 +	*/
    7.11 +	WIN_FlushMessageQueue();
    7.12 +
    7.13  	/* Ready to roll */
    7.14  	return(0);
    7.15  }
    7.16 @@ -908,4 +914,10 @@
    7.17  		DestroyWindow(SDL_Window);
    7.18  	}
    7.19  	SDL_UnregisterApp();
    7.20 +
    7.21 +	/* JC 14 Mar 2006
    7.22 +		Flush the message loop or this can cause big problems later
    7.23 +		Especially if the user decides to use dialog boxes or assert()!
    7.24 +	*/
    7.25 +	WIN_FlushMessageQueue();
    7.26  }
     8.1 --- a/src/video/windx5/SDL_dx5video.c	Tue Mar 14 03:04:50 2006 +0000
     8.2 +++ b/src/video/windx5/SDL_dx5video.c	Tue Mar 14 04:00:03 2006 +0000
     8.3 @@ -902,6 +902,7 @@
     8.4  	if ( DX5_CreateWindow(this) < 0 ) {
     8.5  		return(-1);
     8.6  	}
     8.7 +
     8.8  #if !SDL_AUDIO_DISABLED
     8.9  	DX5_SoundFocus(SDL_Window);
    8.10  #endif
    8.11 @@ -1604,6 +1605,12 @@
    8.12  	SetForegroundWindow(SDL_Window);
    8.13  	SDL_resizing = 0;
    8.14  
    8.15 +	/* JC 14 Mar 2006
    8.16 +		Flush the message loop or this can cause big problems later
    8.17 +		Especially if the user decides to use dialog boxes or assert()!
    8.18 +	*/
    8.19 +	WIN_FlushMessageQueue();
    8.20 +
    8.21  	/* We're live! */
    8.22  	return(video);
    8.23  }
    8.24 @@ -2345,16 +2352,6 @@
    8.25  #endif /* !IDirectDrawGammaControl_SetGammaRamp */
    8.26  }
    8.27  
    8.28 -static void FlushMessageQueue()
    8.29 -{
    8.30 -	MSG  msg;
    8.31 -	while ( PeekMessage(&msg, NULL, 0, 0, PM_REMOVE) ) {
    8.32 -		if ( msg.message == WM_QUIT ) break;
    8.33 -		TranslateMessage( &msg );
    8.34 -		DispatchMessage( &msg );
    8.35 -	}
    8.36 -}
    8.37 -
    8.38  void DX5_VideoQuit(_THIS)
    8.39  {
    8.40  	int i, j;
    8.41 @@ -2398,7 +2395,6 @@
    8.42  	DIB_QuitGamma(this);
    8.43  	if ( SDL_Window ) {
    8.44  		DX5_DestroyWindow(this);
    8.45 -		FlushMessageQueue();
    8.46  	}
    8.47  
    8.48  	/* Free our window icon */