Register
Site Login
Site Search
Forums
Advertisement
Welcome to PocketMatrix. PocketMatrix is dedicated to providing the best online community for mobile device developers and enthusiests. What's new?

Is it OK to minimize my window this way?


Is it OK to minimize my window this way?

Postby BIGBEN » Apr 27, 2005 @ 11:20pm

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 :)
Last edited by BIGBEN on Apr 27, 2005 @ 11:59pm, edited 1 time in total.
User avatar
BIGBEN
pm Member
 
Posts: 281
Joined: Mar 18, 2003 @ 10:18pm
Location: Saint-Petersburg, Russia


Postby Kzinti » Apr 27, 2005 @ 11:24pm

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: Select all

ShowWindow( SW_MINIMIZE) is probably all you need.
1 lines; 0 keywds; 0 nums; 3 ops; 0 strs; 0 coms    Syntactic Coloring v0.4 - Dan East  
Last edited by Kzinti on Apr 28, 2005 @ 12:39am, edited 1 time in total.
Kzinti
pm Member
 
Posts: 3238
Joined: Jan 13, 2002 @ 5:23am


Postby BIGBEN » Apr 28, 2005 @ 12:09am

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:
User avatar
BIGBEN
pm Member
 
Posts: 281
Joined: Mar 18, 2003 @ 10:18pm
Location: Saint-Petersburg, Russia


Postby Kzinti » Apr 28, 2005 @ 12:42am

If you are outside "game":

Code: Select all

game.ShowWindow( SW_MINIMIZE );
1 lines; 0 keywds; 0 nums; 4 ops; 0 strs; 0 coms    Syntactic Coloring v0.4 - Dan East  


or

Code: Select all

ShowWindow( game.GetWindow(), SW_MINIMIZE );
1 lines; 0 keywds; 0 nums; 7 ops; 0 strs; 0 coms    Syntactic Coloring v0.4 - Dan East  



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

Code: Select all

ShowWindow( SW_MINIMIZE );
1 lines; 0 keywds; 0 nums; 3 ops; 0 strs; 0 coms    Syntactic Coloring v0.4 - Dan East  


or

Code: Select all

ShowWindow( GetWindow(), SW_MINIMIZE );
1 lines; 0 keywds; 0 nums; 6 ops; 0 strs; 0 coms    Syntactic Coloring v0.4 - Dan East  
Kzinti
pm Member
 
Posts: 3238
Joined: Jan 13, 2002 @ 5:23am


Postby BIGBEN » Apr 28, 2005 @ 12:51am

:)))))

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: Select all









10 
11 
12 
13 
14 
15 
16 
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;
}
16 lines; 5 keywds; 2 nums; 40 ops; 1 strs; 0 coms    Syntactic Coloring v0.4 - Dan East  
User avatar
BIGBEN
pm Member
 
Posts: 281
Joined: Mar 18, 2003 @ 10:18pm
Location: Saint-Petersburg, Russia


Postby Kzinti » Apr 28, 2005 @ 1:27am

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.
Kzinti
pm Member
 
Posts: 3238
Joined: Jan 13, 2002 @ 5:23am


Postby BIGBEN » Apr 28, 2005 @ 11:33am

Thank you, Thierry, now it works fine :D

For those, who interested in final result:

Code: Select all









10 
11 
12 
13 
14 
15 
16 
17 
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;
}
17 lines; 5 keywds; 2 nums; 43 ops; 1 strs; 0 coms    Syntactic Coloring v0.4 - Dan East  


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:
User avatar
BIGBEN
pm Member
 
Posts: 281
Joined: Mar 18, 2003 @ 10:18pm
Location: Saint-Petersburg, Russia


Postby Kzinti » Apr 28, 2005 @ 5:05pm

MMm. The code I had in mind is this one:

Code: Select all









10 
11 
12 
13 
14 
15 
16 
17 
18 
19 
20 
21 
22 
23 
24 
25 
    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;
    }
25 lines; 11 keywds; 2 nums; 67 ops; 1 strs; 1 coms    Syntactic Coloring v0.4 - Dan East  


This is what you want to do.
Kzinti
pm Member
 
Posts: 3238
Joined: Jan 13, 2002 @ 5:23am


Return to PocketFrog & PocketHAL


Sort


Forum Description

SDKs for fast and robust device-independent access to Pocket PC display hardware.

Moderators:

sponge, Kzinti

Forum permissions

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

cron