PocketMatrix forums

A read-only archive of the PocketMatrix forums (2001–2014). Posting and accounts are closed.

Is it OK to minimize my window this way?

I use PocketFrog 0_8_1,
now I'm adding pause feature to my game, is it OK to minimize my window this way?:

HWND hWnd = FindWindow(NULL, _T("!PYROMANIA!"));
ShowWindow( hWnd, SW_MINIMIZE);

Where !PYROMANIA! is just my game title :)
I am not sure why you use FindWindow() since you already have the window handle (hwnd) available from ATL.

Actually, even easier, just call CWindow's ShowWindow() instead.

Code:

ShowWindow( SW_MINIMIZE) is probably all you need.
I'm not sure to understand where I have this hwnd handle? :oops:
Maybe somewhere here:

CComModule _Module; //For Windows CE

int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE, LPTSTR, int )
{
_Module.Init( 0, hInstance );
Pyromania game;
pPyr = &game;
game.Run();
return 0;
}

I know less than the basics of eVC++

Anyway, thanks for reply, now I know that even my method should work with PF :wink:
If you are outside "game":

Code:

game.ShowWindow( SW_MINIMIZE );


or

Code:

ShowWindow( game.GetWindow(), SW_MINIMIZE );



If you are inside "game" in a method of PyromaniaGame:

Code:

ShowWindow( SW_MINIMIZE );


or

Code:

ShowWindow( GetWindow(), SW_MINIMIZE );
:)))))

Thank you for such a much of methods :)))

But I've got another problem: couldn't avoid running multiple instanses of !PYROMANIA!
I've tried this, but it shows only for PC, on a PPC it only run one instance on background without showing it back:
Code:
int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE, LPTSTR, int )
{
HWND hWnd = FindWindow(NULL, _T("!PYROMANIA!"));
if(hWnd !=NULL)
{
ShowWindow( hWnd, SW_SHOWNORMAL);
}
else
{
_Module.Init( 0, hInstance );
Pyromania game;
pPyr = &game;
game.Run();
}
return 0;
}
Download PocketHAL and take a look at the samples. Somewhere in "win32\gamebase.cpp" or something like that, you will find code that detects running instances and active them.
Thank you, Thierry, now it works fine :D

For those, who interested in final result:

Code:
int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE, LPTSTR, int )
{
HWND hWnd = FindWindow(NULL, _T("!PYROMANIA!.exe"));
if(hWnd !=NULL)
{
SetForegroundWindow(hWnd);
ShowWindow( hWnd, SW_SHOWNORMAL);
}
else
{
_Module.Init( 0, hInstance );
Pyromania game;
pPyr = &game;
game.Run();
}
return 0;
}


Remarks: I've changed my game title because after minimizing and running the game again it activated !PYROMANIA! folder - just because it has the same name
:lol:
MMm. The code I had in mind is this one:

Code:

TCHAR uniqueName[MAX_PATH];
_stprintf( uniqueName, TEXT("PHAL_FRAMEWORK_%08X"), m_uid );

HANDLE hMutexOneInstance = ::CreateMutex( 0, FALSE, uniqueName );

bool bAlreadyRunning = (GetLastError() == ERROR_ALREADY_EXISTS);

if (bAlreadyRunning)
{
// If there is already an instance of this app running, give it focus and exit
HWND hOther = ::FindWindow( uniqueName, 0 );
if (hOther)
{
::SetForegroundWindow( hOther );

#if defined(PHAL_PLATFORM_WCE)
if (::IsWindowEnabled( hOther ))
#else
if (::IsIconic( hOther ))
#endif
::ShowWindow( hOther, SW_RESTORE );
}

return false;
}


This is what you want to do.