From 86cc2818e0e535f18d00b2f9bafec94a55069864 Mon Sep 17 00:00:00 2001 From: Henrik Andersson Date: Sat, 4 Jun 2011 02:12:08 +0200 Subject: [PATCH] [loading window] Now the loading window has it's own thread. As such, the paint method is no longer needed. --- src/SongManager.cpp | 2 - src/arch/LoadingWindow/LoadingWindow.h | 1 - .../LoadingWindow/LoadingWindow_Win32.cpp | 47 +++++++++++++++---- src/arch/LoadingWindow/LoadingWindow_Win32.h | 7 ++- src/archutils/Win32/WindowsResources.rc | 8 ++-- 5 files changed, 46 insertions(+), 19 deletions(-) diff --git a/src/SongManager.cpp b/src/SongManager.cpp index 48a7d3c5eb..1423a13498 100644 --- a/src/SongManager.cpp +++ b/src/SongManager.cpp @@ -266,7 +266,6 @@ void SongManager::LoadStepManiaSongDir( RString sDir, LoadingWindow *ld ) ld->SetText( LOADING_SONGS.GetValue()+ssprintf("\n%s\n%s", Basename(sGroupDirName).c_str(), Basename(sSongDirName).c_str())); - ld->Paint(); } Song* pNewSong = new Song; if( !pNewSong->LoadFromSongDir( sSongDirName ) ) @@ -755,7 +754,6 @@ void SongManager::InitCoursesFromDisk( LoadingWindow *ld ) ld->SetText( LOADING_COURSES.GetValue()+ssprintf("\n%s\n%s", Basename(*sCourseGroup).c_str(), Basename(*sCoursePath).c_str())); - ld->Paint(); } Course* pCourse = new Course; diff --git a/src/arch/LoadingWindow/LoadingWindow.h b/src/arch/LoadingWindow/LoadingWindow.h index 1ddfa7e110..952c469ab8 100644 --- a/src/arch/LoadingWindow/LoadingWindow.h +++ b/src/arch/LoadingWindow/LoadingWindow.h @@ -11,7 +11,6 @@ public: virtual RString Init() { return RString(); } virtual ~LoadingWindow() { } - virtual void Paint() { } virtual void SetText( RString str ) = 0; virtual void SetIcon( const RageSurface *pIcon ) { } virtual void SetProgress( const int progress ) { m_progress=progress; } diff --git a/src/arch/LoadingWindow/LoadingWindow_Win32.cpp b/src/arch/LoadingWindow/LoadingWindow_Win32.cpp index 9148e15db8..d776156855 100644 --- a/src/arch/LoadingWindow/LoadingWindow_Win32.cpp +++ b/src/arch/LoadingWindow/LoadingWindow_Win32.cpp @@ -80,8 +80,18 @@ static HBITMAP LoadWin32Surface( RString sFile, HWND hWnd ) return ret; } -BOOL CALLBACK LoadingWindow_Win32::WndProc( HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam ) +INT_PTR CALLBACK LoadingWindow_Win32::DlgProc( HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam ) { + + LoadingWindow_Win32 *self; + + if(msg==WM_INITDIALOG) { + self=(LoadingWindow_Win32 *)lParam; + SetWindowLong(hWnd,DWL_USER,(LONG)self); + } else { + self=(LoadingWindow_Win32 *)GetWindowLong(hWnd,DWL_USER); + } + switch( msg ) { case WM_INITDIALOG: @@ -99,12 +109,21 @@ BOOL CALLBACK LoadingWindow_Win32::WndProc( HWND hWnd, UINT msg, WPARAM wParam, (WPARAM) IMAGE_BITMAP, (LPARAM) (HANDLE) g_hBitmap ); SetWindowTextA( hWnd, PRODUCT_ID ); + + { + HWND progressCtrl=GetDlgItem( hWnd, IDC_PROGRESS ); + SetWindowLong(progressCtrl,GWL_STYLE, PBS_MARQUEE | GetWindowLong(progressCtrl,GWL_STYLE)); + SendMessage(progressCtrl,PBM_SETMARQUEE,1,0); + } break; case WM_DESTROY: DeleteObject( g_hBitmap ); g_hBitmap = NULL; break; + + case WM_ENTERIDLE: + SetEvent(self->guiReadyEvent); } return FALSE; @@ -128,33 +147,43 @@ LoadingWindow_Win32::LoadingWindow_Win32() InitCommonControlsEx(&cceData); m_hIcon = NULL; - hwnd = CreateDialog( handle.Get(), MAKEINTRESOURCE(IDD_LOADING_DIALOG), NULL, WndProc ); + + guiReadyEvent=CreateEvent(NULL,FALSE,FALSE,NULL); + + CreateThread(NULL, NULL, MessagePump, (void *)this, 0, NULL); + + WaitForSingleObject(guiReadyEvent,0); + for( unsigned i = 0; i < 3; ++i ) text[i] = "ABC"; /* always set on first call */ SetText( "" ); - Paint(); } LoadingWindow_Win32::~LoadingWindow_Win32() { + if(guiReadyEvent) + CloseHandle(guiReadyEvent); if( hwnd ) DestroyWindow( hwnd ); if( m_hIcon != NULL ) DestroyIcon( m_hIcon ); } -void LoadingWindow_Win32::Paint() +DWORD WINAPI LoadingWindow_Win32::MessagePump(LPVOID thisAsVoidPtr) { - SendMessage( hwnd, WM_PAINT, 0, 0 ); + LoadingWindow_Win32 *self=(LoadingWindow_Win32 *)thisAsVoidPtr; - /* Process all queued messages since the last paint. This allows the window to - * come back if it loses focus during load. */ + self->hwnd = CreateDialogParam( self->handle.Get(), MAKEINTRESOURCE(IDD_LOADING_DIALOG), NULL, DlgProc, (LPARAM)thisAsVoidPtr); + + // Run the message loop in a separate thread to keep the gui responsive during the loading MSG msg; - while( PeekMessage( &msg, hwnd, 0, 0, PM_NOREMOVE ) ) + while( GetMessage(&msg, self->hwnd, 0, 0 ) ) { - GetMessage(&msg, hwnd, 0, 0 ); + if(IsDialogMessage(self->hwnd,&msg)) continue; DispatchMessage( &msg ); } + + return msg.wParam; } void LoadingWindow_Win32::SetText( RString sText ) diff --git a/src/arch/LoadingWindow/LoadingWindow_Win32.h b/src/arch/LoadingWindow/LoadingWindow_Win32.h index 365a7ee2bc..c9e0cf4bb1 100644 --- a/src/arch/LoadingWindow/LoadingWindow_Win32.h +++ b/src/arch/LoadingWindow/LoadingWindow_Win32.h @@ -14,7 +14,6 @@ public: ~LoadingWindow_Win32(); void SetText( RString sText ); - void Paint(); void SetIcon( const RageSurface *pIcon ); void SetProgress( const int progress ); void SetTotalWork( const int totalWork ); @@ -24,8 +23,12 @@ private: HWND hwnd; RString text[3]; HICON m_hIcon; + HANDLE pumpThread; + HANDLE guiReadyEvent; - static BOOL CALLBACK WndProc( HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam ); + static DWORD WINAPI MessagePump(LPVOID thisAsVoidPtr); + + static INT_PTR CALLBACK DlgProc( HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam ); }; #define USE_LOADING_WINDOW_WIN32 diff --git a/src/archutils/Win32/WindowsResources.rc b/src/archutils/Win32/WindowsResources.rc index 494c422801..18e8cb2d41 100644 --- a/src/archutils/Win32/WindowsResources.rc +++ b/src/archutils/Win32/WindowsResources.rc @@ -7,10 +7,7 @@ // // Generated from the TEXTINCLUDE 2 resource. // - -#define _WIN32_WINNT 0x0501 #include "winres.h" -#include "CommCtrl.h" ///////////////////////////////////////////////////////////////////////////// #undef APSTUDIO_READONLY_SYMBOLS @@ -45,15 +42,16 @@ BEGIN END IDD_LOADING_DIALOG DIALOGEX 0, 0, 317, 94 -STYLE DS_SETFONT | DS_MODALFRAME | DS_CENTER | WS_VISIBLE | WS_CAPTION | WS_SYSMENU +STYLE DS_SETFONT | DS_CENTER | WS_VISIBLE | WS_CAPTION | WS_SYSMENU EXSTYLE WS_EX_APPWINDOW +CAPTION "Stepmania" FONT 8, "MS Sans Serif", 0, 0, 0x0 BEGIN CTEXT "line1",IDC_STATIC_MESSAGE1,0,67,310,10,SS_NOPREFIX | SS_CENTERIMAGE CTEXT "line2",IDC_STATIC_MESSAGE2,0,76,310,10,SS_NOPREFIX | SS_CENTERIMAGE CTEXT "line3",IDC_STATIC_MESSAGE3,0,84,310,10,SS_NOPREFIX | SS_CENTERIMAGE CONTROL "",IDC_SPLASH,"Static",SS_BITMAP,0,0,310,25 - CONTROL "",IDC_PROGRESS,"msctls_progress32",PBS_MARQUEE,7,51,298,14 + CONTROL "",IDC_PROGRESS,"msctls_progress32",0x0,7,51,298,14 END IDD_DISASM_CRASH DIALOGEX 0, 0, 332, 114