From e3361f3c1be88c94751059948d3ed442f3499c2c Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Tue, 14 Mar 2006 04:00:03 +0000 Subject: [PATCH] (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 | 18 ++++++------------ src/video/wincommon/SDL_lowvideo.h | 2 ++ src/video/wincommon/SDL_sysevents.c | 15 +++++++++++++++ src/video/wincommon/SDL_wingl.c | 7 +++++++ src/video/windib/SDL_dibevents.c | 13 +++++++++++++ src/video/windib/SDL_dibvideo.c | 18 +++++++----------- src/video/windx5/SDL_dx5events.c | 12 ++++++++++++ src/video/windx5/SDL_dx5video.c | 18 +++++++----------- 8 files changed, 69 insertions(+), 34 deletions(-) diff --git a/src/video/gapi/SDL_gapivideo.c b/src/video/gapi/SDL_gapivideo.c index f8dd46097..ca074bfc4 100644 --- a/src/video/gapi/SDL_gapivideo.c +++ b/src/video/gapi/SDL_gapivideo.c @@ -731,6 +731,12 @@ SDL_Surface *GAPI_SetVideoMode(_THIS, SDL_Surface *current, ShowWindow(SDL_Window, SW_SHOW); SetForegroundWindow(SDL_Window); + /* JC 14 Mar 2006 + Flush the message loop or this can cause big problems later + Especially if the user decides to use dialog boxes or assert()! + */ + WIN_FlushMessageQueue(); + /* Open GAPI display */ if( !gapi->useVga && this->hidden->useGXOpenDisplay ) if( !gapi->gxFunc.GXOpenDisplay(SDL_Window, GX_FULLSCREEN) ) @@ -1103,17 +1109,6 @@ static void GAPI_UpdateRects(_THIS, int numrects, SDL_Rect *rects) gapi->gxFunc.GXEndDraw(); } -static void FlushMessageQueue() -{ - MSG msg; - while ( PeekMessage(&msg, NULL, 0, 0, PM_REMOVE) ) { - if ( msg.message == WM_QUIT ) break; - TranslateMessage( &msg ); - DispatchMessage( &msg ); - } -} - - /* Note: If we are terminated, this could be called in the middle of another SDL video routine -- notably UpdateRects. */ @@ -1138,7 +1133,6 @@ void GAPI_VideoQuit(_THIS) DIB_DestroyWindow(this); SDL_UnregisterApp(); - FlushMessageQueue(); SDL_Window = NULL; #if defined(_WIN32_WCE) diff --git a/src/video/wincommon/SDL_lowvideo.h b/src/video/wincommon/SDL_lowvideo.h index ed1d52781..eb8d9581b 100644 --- a/src/video/wincommon/SDL_lowvideo.h +++ b/src/video/wincommon/SDL_lowvideo.h @@ -79,6 +79,8 @@ extern BOOL SDL_windowid; /* Variables and functions exported to other parts of the native video subsystem (SDL_sysevents.c) */ +extern void WIN_FlushMessageQueue(); + /* Called by windows message loop when system palette is available */ extern void (*WIN_RealizePalette)(_THIS); diff --git a/src/video/wincommon/SDL_sysevents.c b/src/video/wincommon/SDL_sysevents.c index 00bd8b1b7..584c18463 100644 --- a/src/video/wincommon/SDL_sysevents.c +++ b/src/video/wincommon/SDL_sysevents.c @@ -169,6 +169,21 @@ static void GapiTransform(SDL_ScreenOrientation rotate, char hires, Sint16 *x, S #endif +/* JC 14 Mar 2006 + This is used all over the place, in the windib driver and in the dx5 driver + So we may as well stick it here instead of having multiple copies scattered + about +*/ +void WIN_FlushMessageQueue() +{ + MSG msg; + while ( PeekMessage(&msg, NULL, 0, 0, PM_REMOVE) ) { + if ( msg.message == WM_QUIT ) break; + TranslateMessage( &msg ); + DispatchMessage( &msg ); + } +} + static void SDL_RestoreGameMode(void) { #ifdef _WIN32_WCE diff --git a/src/video/wincommon/SDL_wingl.c b/src/video/wincommon/SDL_wingl.c index 2efb69821..ca2ecc324 100644 --- a/src/video/wincommon/SDL_wingl.c +++ b/src/video/wincommon/SDL_wingl.c @@ -48,12 +48,16 @@ static int WIN_GL_ResetWindow(_THIS) style = GetWindowLong(SDL_Window, GWL_STYLE); GetWindowRect(SDL_Window, &rect); DestroyWindow(SDL_Window); + WIN_FlushMessageQueue(); + SDL_Window = CreateWindow(SDL_Appname, SDL_Appname, style, rect.left, rect.top, (rect.right-rect.left)+1, (rect.top-rect.bottom)+1, NULL, NULL, SDL_Instance, NULL); + WIN_FlushMessageQueue(); + if ( SDL_Window ) { this->SetCaption(this, this->wm_title, this->wm_icon); } else { @@ -118,6 +122,8 @@ static void Init_WGL_ARB_extensions(_THIS) hwnd = CreateWindow(SDL_Appname, SDL_Appname, WS_POPUP | WS_DISABLED, 0, 0, 10, 10, NULL, NULL, SDL_Instance, NULL); + WIN_FlushMessageQueue(); + hdc = GetDC(hwnd); pformat = ChoosePixelFormat(hdc, &GL_pfd); @@ -158,6 +164,7 @@ static void Init_WGL_ARB_extensions(_THIS) } ReleaseDC(hwnd, hdc); DestroyWindow(hwnd); + WIN_FlushMessageQueue(); } #endif /* SDL_VIDEO_OPENGL */ diff --git a/src/video/windib/SDL_dibevents.c b/src/video/windib/SDL_dibevents.c index 7d4d9fda9..9a8226b3c 100644 --- a/src/video/windib/SDL_dibevents.c +++ b/src/video/windib/SDL_dibevents.c @@ -438,6 +438,13 @@ int DIB_CreateWindow(_THIS) } ShowWindow(SDL_Window, SW_HIDE); } + + /* JC 14 Mar 2006 + Flush the message loop or this can cause big problems later + Especially if the user decides to use dialog boxes or assert()! + */ + WIN_FlushMessageQueue(); + return(0); } @@ -449,4 +456,10 @@ void DIB_DestroyWindow(_THIS) DestroyWindow(SDL_Window); } SDL_UnregisterApp(); + + /* JC 14 Mar 2006 + Flush the message loop or this can cause big problems later + Especially if the user decides to use dialog boxes or assert()! + */ + WIN_FlushMessageQueue(); } diff --git a/src/video/windib/SDL_dibvideo.c b/src/video/windib/SDL_dibvideo.c index 9e78f0111..582b6ed36 100644 --- a/src/video/windib/SDL_dibvideo.c +++ b/src/video/windib/SDL_dibvideo.c @@ -291,6 +291,7 @@ int DIB_VideoInit(_THIS, SDL_PixelFormat *vformat) if ( DIB_CreateWindow(this) < 0 ) { return(-1); } + #if !SDL_AUDIO_DISABLED DX5_SoundFocus(SDL_Window); #endif @@ -818,6 +819,12 @@ SDL_Surface *DIB_SetVideoMode(_THIS, SDL_Surface *current, video->flags |= SDL_OPENGL; } + /* JC 14 Mar 2006 + Flush the message loop or this can cause big problems later + Especially if the user decides to use dialog boxes or assert()! + */ + WIN_FlushMessageQueue(); + /* We're live! */ return(video); } @@ -1014,16 +1021,6 @@ int DIB_GetGammaRamp(_THIS, Uint16 *ramp) #endif /* !NO_GAMMA_SUPPORT */ } -static void FlushMessageQueue() -{ - MSG msg; - while ( PeekMessage(&msg, NULL, 0, 0, PM_REMOVE) ) { - if ( msg.message == WM_QUIT ) break; - TranslateMessage( &msg ); - DispatchMessage( &msg ); - } -} - void DIB_VideoQuit(_THIS) { /* Destroy the window and everything associated with it */ @@ -1051,7 +1048,6 @@ void DIB_VideoQuit(_THIS) } DIB_QuitGamma(this); DIB_DestroyWindow(this); - FlushMessageQueue(); SDL_Window = NULL; diff --git a/src/video/windx5/SDL_dx5events.c b/src/video/windx5/SDL_dx5events.c index ab8fc1a12..b2c14c870 100644 --- a/src/video/windx5/SDL_dx5events.c +++ b/src/video/windx5/SDL_dx5events.c @@ -892,6 +892,12 @@ int DX5_CreateWindow(_THIS) return(-1); } + /* JC 14 Mar 2006 + Flush the message loop or this can cause big problems later + Especially if the user decides to use dialog boxes or assert()! + */ + WIN_FlushMessageQueue(); + /* Ready to roll */ return(0); } @@ -908,4 +914,10 @@ void DX5_DestroyWindow(_THIS) DestroyWindow(SDL_Window); } SDL_UnregisterApp(); + + /* JC 14 Mar 2006 + Flush the message loop or this can cause big problems later + Especially if the user decides to use dialog boxes or assert()! + */ + WIN_FlushMessageQueue(); } diff --git a/src/video/windx5/SDL_dx5video.c b/src/video/windx5/SDL_dx5video.c index 94b73a8a4..8f322750e 100644 --- a/src/video/windx5/SDL_dx5video.c +++ b/src/video/windx5/SDL_dx5video.c @@ -902,6 +902,7 @@ int DX5_VideoInit(_THIS, SDL_PixelFormat *vformat) if ( DX5_CreateWindow(this) < 0 ) { return(-1); } + #if !SDL_AUDIO_DISABLED DX5_SoundFocus(SDL_Window); #endif @@ -1604,6 +1605,12 @@ SDL_Surface *DX5_SetVideoMode(_THIS, SDL_Surface *current, SetForegroundWindow(SDL_Window); SDL_resizing = 0; + /* JC 14 Mar 2006 + Flush the message loop or this can cause big problems later + Especially if the user decides to use dialog boxes or assert()! + */ + WIN_FlushMessageQueue(); + /* We're live! */ return(video); } @@ -2345,16 +2352,6 @@ static int DX5_GetGammaRamp(_THIS, Uint16 *ramp) #endif /* !IDirectDrawGammaControl_SetGammaRamp */ } -static void FlushMessageQueue() -{ - MSG msg; - while ( PeekMessage(&msg, NULL, 0, 0, PM_REMOVE) ) { - if ( msg.message == WM_QUIT ) break; - TranslateMessage( &msg ); - DispatchMessage( &msg ); - } -} - void DX5_VideoQuit(_THIS) { int i, j; @@ -2398,7 +2395,6 @@ void DX5_VideoQuit(_THIS) DIB_QuitGamma(this); if ( SDL_Window ) { DX5_DestroyWindow(this); - FlushMessageQueue(); } /* Free our window icon */