[LoadingWindow_Win32] Make the StepMania window gain focus after the loading window closes. Fixes issue 424.

This commit is contained in:
AJ Kelly
2011-09-22 20:19:27 -05:00
parent 1adbad7713
commit 8d528625de
3 changed files with 24 additions and 161 deletions
+2
View File
@@ -12,6 +12,8 @@ StepMania 5.0 $next | 2011????
---------- ----------
* [ScreenDebugOverlay] Replaced hardcoded toggle command with * [ScreenDebugOverlay] Replaced hardcoded toggle command with
ButtonTextToggledCommand metric. [AJ] ButtonTextToggledCommand metric. [AJ]
* [LoadingWindow_Win32] Make the StepMania window gain focus after the
loading window closes. Fixes issue 424. [AJ]
2011/09/21 2011/09/21
---------- ----------
+17 -137
View File
@@ -19,9 +19,7 @@
#include "RageSurfaceUtils_Zoom.h" #include "RageSurfaceUtils_Zoom.h"
static HBITMAP g_hBitmap = NULL; static HBITMAP g_hBitmap = NULL;
#pragma comment(linker,"\"/manifestdependency:type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'\"") /* Load a RageSurface into a GDI surface. */
// Load a RageSurface into a GDI surface.
static HBITMAP LoadWin32Surface( RageSurface *&s ) static HBITMAP LoadWin32Surface( RageSurface *&s )
{ {
RageSurfaceUtils::ConvertSurface( s, s->w, s->h, 32, 0xFF000000, 0x00FF0000, 0x0000FF00, 0 ); RageSurfaceUtils::ConvertSurface( s, s->w, s->h, 32, 0xFF000000, 0x00FF0000, 0x0000FF00, 0 );
@@ -35,7 +33,7 @@ static HBITMAP LoadWin32Surface( RageSurface *&s )
HDC BitmapDC = CreateCompatibleDC( hScreen ); HDC BitmapDC = CreateCompatibleDC( hScreen );
SelectObject( BitmapDC, bitmap ); SelectObject( BitmapDC, bitmap );
// This is silly, but simple. We only do this once, on a small image. /* This is silly, but simple. We only do this once, on a small image. */
for( int y = 0; y < s->h; ++y ) for( int y = 0; y < s->h; ++y )
{ {
unsigned const char *line = ((unsigned char *) s->pixels) + (y * s->pitch); unsigned const char *line = ((unsigned char *) s->pixels) + (y * s->pitch);
@@ -62,7 +60,7 @@ static HBITMAP LoadWin32Surface( RString sFile, HWND hWnd )
if( pSurface == NULL ) if( pSurface == NULL )
return NULL; return NULL;
/* Resize the splash image to fit the dialog. Stretch to fit horizontally, /* Resize the splash image to fit the dialog. Stretch to fit horizontally,
* maintaining aspect ratio. */ * maintaining aspect ratio. */
{ {
RECT r; RECT r;
@@ -80,43 +78,8 @@ static HBITMAP LoadWin32Surface( RString sFile, HWND hWnd )
return ret; return ret;
} }
INT_PTR CALLBACK LoadingWindow_Win32::DlgProc( HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam ) BOOL CALLBACK LoadingWindow_Win32::WndProc( 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);
}
/*
#if WINVER >= 0x0601
if (self && msg == self->taskbarCreatedEvent && !self->pTaskbarList) {
HRESULT hr = CoCreateInstance(CLSID_TaskbarList, NULL, CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&self->pTaskbarList));
if (SUCCEEDED(hr)) {
self->pTaskbarList->HrInit();
if (FAILED(hr)) {
self->pTaskbarList->Release();
self->pTaskbarList = NULL;
} else {
if(self->m_indeterminate) {
self->pTaskbarList->SetProgressState(hWnd, TBPF_INDETERMINATE);
} else {
self->pTaskbarList->SetProgressState(hWnd, TBPF_NORMAL);
self->pTaskbarList->SetProgressValue(hWnd, self->m_progress, self->m_totalWork);
}
}
}
}
#endif
*/
switch( msg ) switch( msg )
{ {
case WM_INITDIALOG: case WM_INITDIALOG:
@@ -134,36 +97,11 @@ INT_PTR CALLBACK LoadingWindow_Win32::DlgProc( HWND hWnd, UINT msg, WPARAM wPara
(WPARAM) IMAGE_BITMAP, (WPARAM) IMAGE_BITMAP,
(LPARAM) (HANDLE) g_hBitmap ); (LPARAM) (HANDLE) g_hBitmap );
SetWindowTextA( hWnd, PRODUCT_ID ); SetWindowTextA( hWnd, PRODUCT_ID );
break; break;
case WM_CLOSE:
HOOKS->SetUserQuit();
return FALSE;
case WM_DESTROY: case WM_DESTROY:
/*
#if(WINVER >= 0x0601)
if (self->pTaskbarList) {
self->pTaskbarList->Release();
self->pTaskbarList = NULL;
}
#endif
*/
DeleteObject( g_hBitmap ); DeleteObject( g_hBitmap );
g_hBitmap = NULL; g_hBitmap = NULL;
self->runMessageLoop=false;
self->hwnd=NULL;
return TRUE;
break;
case WM_APP:
DestroyWindow(hWnd);
self->runMessageLoop=false;
ExitThread(0);
return TRUE;
break; break;
} }
@@ -172,7 +110,7 @@ INT_PTR CALLBACK LoadingWindow_Win32::DlgProc( HWND hWnd, UINT msg, WPARAM wPara
void LoadingWindow_Win32::SetIcon( const RageSurface *pIcon ) void LoadingWindow_Win32::SetIcon( const RageSurface *pIcon )
{ {
if( g_hBitmap != NULL ) if( m_hIcon != NULL )
DestroyIcon( m_hIcon ); DestroyIcon( m_hIcon );
m_hIcon = IconFromSurface( pIcon ); m_hIcon = IconFromSurface( pIcon );
@@ -202,63 +140,34 @@ void LoadingWindow_Win32::SetSplash( const RString sPath )
LoadingWindow_Win32::LoadingWindow_Win32() LoadingWindow_Win32::LoadingWindow_Win32()
{ {
INITCOMMONCONTROLSEX cceData;
cceData.dwSize=sizeof(INITCOMMONCONTROLSEX);
cceData.dwICC=ICC_PROGRESS_CLASS;
InitCommonControlsEx(&cceData);
/*
#if(WINVER >= 0x0601)
pTaskbarList=NULL;
taskbarCreatedEvent=RegisterWindowMessage("TaskbarButtonCreated");
#endif
*/
m_hIcon = NULL; m_hIcon = NULL;
hwnd = CreateDialog( handle.Get(), MAKEINTRESOURCE(IDD_LOADING_DIALOG), NULL, WndProc );
runMessageLoop=true;
guiReadyEvent=CreateEvent(NULL,FALSE,FALSE,NULL);
pumpThread=CreateThread(NULL, NULL, MessagePump, (void *)this, 0, &pumpThreadId);
WaitForSingleObject(guiReadyEvent,INFINITE);
for( unsigned i = 0; i < 3; ++i ) for( unsigned i = 0; i < 3; ++i )
text[i] = "ABC"; /* always set on first call */ text[i] = "ABC"; /* always set on first call */
SetText( "" ); SetText( "" );
Paint();
} }
LoadingWindow_Win32::~LoadingWindow_Win32() LoadingWindow_Win32::~LoadingWindow_Win32()
{ {
SendMessage(hwnd,WM_APP,0,0); if( hwnd )
//SendMessage(hwnd,WM_NULL,0,0); DestroyWindow( hwnd );
WaitForSingleObject(pumpThread,INFINITE);
if(guiReadyEvent)
CloseHandle(guiReadyEvent);
if( m_hIcon != NULL ) if( m_hIcon != NULL )
DestroyIcon( m_hIcon ); DestroyIcon( m_hIcon );
} }
DWORD WINAPI LoadingWindow_Win32::MessagePump(LPVOID thisAsVoidPtr) void LoadingWindow_Win32::Paint()
{ {
LoadingWindow_Win32 *self=(LoadingWindow_Win32 *)thisAsVoidPtr; SendMessage( hwnd, WM_PAINT, 0, 0 );
self->hwnd = CreateDialogParam( self->handle.Get(), MAKEINTRESOURCE(IDD_LOADING_DIALOG), NULL, DlgProc, (LPARAM)thisAsVoidPtr); /* Process all queued messages since the last paint. This allows the window to
* come back if it loses focus during load. */
SetEvent(self->guiReadyEvent);
// Run the message loop in a separate thread to keep the gui responsive during the loading
MSG msg; MSG msg;
while(self->runMessageLoop && GetMessage(&msg, self->hwnd, 0, 0 ) ) while( PeekMessage( &msg, hwnd, 0, 0, PM_NOREMOVE ) )
{ {
if(IsDialogMessage(self->hwnd,&msg)) continue; GetMessage(&msg, hwnd, 0, 0 );
DispatchMessage( &msg ); DispatchMessage( &msg );
} }
return msg.wParam;
} }
void LoadingWindow_Win32::SetText( RString sText ) void LoadingWindow_Win32::SetText( RString sText )
@@ -276,7 +185,6 @@ void LoadingWindow_Win32::SetText( RString sText )
text[i] = asMessageLines[i]; text[i] = asMessageLines[i];
HWND hwndItem = ::GetDlgItem( hwnd, msgid[i] ); HWND hwndItem = ::GetDlgItem( hwnd, msgid[i] );
::SetWindowText( hwndItem, ConvertUTF8ToACP(asMessageLines[i]).c_str() ); ::SetWindowText( hwndItem, ConvertUTF8ToACP(asMessageLines[i]).c_str() );
} }
} }
@@ -286,13 +194,6 @@ void LoadingWindow_Win32::SetProgress(const int progress)
m_progress=progress; m_progress=progress;
HWND hwndItem = ::GetDlgItem( hwnd, IDC_PROGRESS ); HWND hwndItem = ::GetDlgItem( hwnd, IDC_PROGRESS );
::SendMessage(hwndItem,PBM_SETPOS,progress,0); ::SendMessage(hwndItem,PBM_SETPOS,progress,0);
/*
#if(WINVER >= 0x0601)
if(pTaskbarList) {
pTaskbarList->SetProgressValue(hwnd, m_progress, m_totalWork);
}
#endif
*/
} }
void LoadingWindow_Win32::SetTotalWork(const int totalWork) void LoadingWindow_Win32::SetTotalWork(const int totalWork)
@@ -300,42 +201,21 @@ void LoadingWindow_Win32::SetTotalWork(const int totalWork)
m_totalWork=totalWork; m_totalWork=totalWork;
HWND hwndItem = ::GetDlgItem( hwnd, IDC_PROGRESS ); HWND hwndItem = ::GetDlgItem( hwnd, IDC_PROGRESS );
SendMessage(hwndItem,PBM_SETRANGE32,0,totalWork); SendMessage(hwndItem,PBM_SETRANGE32,0,totalWork);
/*
#if(WINVER >= 0x0601)
if(pTaskbarList) {
pTaskbarList->SetProgressValue(hwnd, m_progress, m_totalWork);
}
#endif
*/
} }
void LoadingWindow_Win32::SetIndeterminate(bool indeterminate) { void LoadingWindow_Win32::SetIndeterminate(bool indeterminate)
{
m_indeterminate=indeterminate; m_indeterminate=indeterminate;
HWND hwndItem = ::GetDlgItem( hwnd, IDC_PROGRESS ); HWND hwndItem = ::GetDlgItem( hwnd, IDC_PROGRESS );
if(indeterminate) { if(indeterminate) {
/*
#if(WINVER >= 0x0601)
if(pTaskbarList) {
pTaskbarList->SetProgressState(hwnd, TBPF_INDETERMINATE);
}
#endif
*/
SetWindowLong(hwndItem,GWL_STYLE, PBS_MARQUEE | GetWindowLong(hwndItem,GWL_STYLE)); SetWindowLong(hwndItem,GWL_STYLE, PBS_MARQUEE | GetWindowLong(hwndItem,GWL_STYLE));
SendMessage(hwndItem,PBM_SETMARQUEE,1,0); SendMessage(hwndItem,PBM_SETMARQUEE,1,0);
} else { } else {
SendMessage(hwndItem,PBM_SETMARQUEE,0,0); SendMessage(hwndItem,PBM_SETMARQUEE,0,0);
SetWindowLong(hwndItem,GWL_STYLE, (~PBS_MARQUEE) & GetWindowLong(hwndItem,GWL_STYLE)); SetWindowLong(hwndItem,GWL_STYLE, (~PBS_MARQUEE) & GetWindowLong(hwndItem,GWL_STYLE));
/*
#if(WINVER >= 0x0601)
if(pTaskbarList) {
pTaskbarList->SetProgressState(hwnd, TBPF_NORMAL);
}
#endif
*/
} }
} }
/* /*
+2 -21
View File
@@ -3,22 +3,17 @@
#ifndef LOADING_WINDOW_WIN32_H #ifndef LOADING_WINDOW_WIN32_H
#define LOADING_WINDOW_WIN32_H #define LOADING_WINDOW_WIN32_H
#include "global.h"
#include "LoadingWindow.h" #include "LoadingWindow.h"
#include <windows.h> #include <windows.h>
#include "archutils/Win32/AppInstance.h" #include "archutils/Win32/AppInstance.h"
#if(WINVER >= 0x0601)
#include "Shobjidl.h"
#endif
class LoadingWindow_Win32: public LoadingWindow class LoadingWindow_Win32: public LoadingWindow
{ {
public: public:
LoadingWindow_Win32(); LoadingWindow_Win32();
~LoadingWindow_Win32(); ~LoadingWindow_Win32();
void Paint();
void SetText( RString sText ); void SetText( RString sText );
void SetIcon( const RageSurface *pIcon ); void SetIcon( const RageSurface *pIcon );
void SetSplash( const RString sPath ); void SetSplash( const RString sPath );
@@ -31,22 +26,8 @@ private:
HWND hwnd; HWND hwnd;
RString text[3]; RString text[3];
HICON m_hIcon; HICON m_hIcon;
HANDLE pumpThread;
DWORD pumpThreadId;
HANDLE guiReadyEvent;
/* static BOOL CALLBACK WndProc( HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam );
#if WINVER >= 0x0601
UINT taskbarCreatedEvent;
ITaskbarList3 *pTaskbarList;
#endif
*/
volatile bool runMessageLoop;
static DWORD WINAPI MessagePump(LPVOID thisAsVoidPtr);
static INT_PTR CALLBACK DlgProc( HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam );
}; };
#define USE_LOADING_WINDOW_WIN32 #define USE_LOADING_WINDOW_WIN32