PocketMatrix forums

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

szWindowName doesn't actually correctly set the window name?

I've tried ripping apart all the window create stuff, and replaced with code from various sources, with differing degrees of success (some would name the app window correctly, but left me with an app that was overdrawn by the apps behind)

getting nowhere fast :(

any suggestions anyone?

(p.s the reason for wanting this to accurately set the name of the window is that I was trying to add a simple function to restore minimised app versions when the app is relaunched. something that is usually done with window names without any problems - hence finding that the window names were not working correctly)
Assuming you are talking about PocketFrog... PF uses ATL to create it's window. I see no reason why this wouldn't work though.

You can take a look at the PocketHAL samples (common/win32/gamebase.cpp) that does it properly in function GameBase::Initialize:

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;
}


// Register a window class
HINSTANCE hInstance = GetModuleHandle(0);

WNDCLASS wc;
wc.style = CS_HREDRAW | CS_VREDRAW;
wc.lpfnWndProc = MessageHandler;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = hInstance;
wc.hIcon = 0;
wc.hCursor = 0;
wc.hbrBackground = 0;
wc.lpszMenuName = 0;
wc.lpszClassName = uniqueName;

if (!RegisterClass(&wc;))
return EXIT_FAILURE;

...
thanks for the swift reply Thierry - but alas whilst that looks like it should work, for some reason the app window still has the wrong name :(

it's very similar to the various versions of code that I've tried

I'm messing around with PF 0.70 if that makes any difference (tho I can't see why)

I'm going to take a breather away from it - try to come back with a clear head - see if I can spot what I'm doing wrong

thanks again

muff
What do you mean by the "app has the wrong window name"? What's wrong with it?
when using the CEPVIEW remote process viewer to watch the processes running on smartphone or PPC, there is a column for the name of the window

atm games made with PocketFrog seem to give the window the name of FAKEIMEUI

on other apps I've made (without PF) the names show up correctly

and as it is these names that the search for duplicate windows is relying on, it's obviously important that they are correct



of course I could be being really dense, in which case, please feel free to point me in the right direciont :D
I don't have the code in front of me, but this is probably something ATL does. If you create the window yourself and specify a name to CreateWindowEx(), it should work.

Have you tried calling SetWindowText( hwnd, L"appname") after the window is created? Might be worth a try...
hiya

yeah, I've tried messing with the CreateWindowEx method, and even ported the code from the pockethal examples in as a framework for setting up the windows (and several variants from other locations)

all with differing degrees of success - once the name showed up correctly, but the window was 'behind' the main application in term of focus, but not drawing :/

I'm sure it's possible, just need to play with it some more is all

once I get it working I'll be sure to let you know how ;)

thanks for the suggestions

muff
Well it works perfectly here. Are you using more then one window?
hmm, maybe I'm looking at the wrong thing then :/

that's the problem with smartphone / ppc dev, no easy way to send system commands to them, or to change focus to test all the things you need to test :(

oh, and only 1 window - just a standard fullscreen PF game really
I just looked with the 'remote process viewer' in evc3.0 at two devices...

The wm2003se device lists 'FAKEIMEUI' as the window name of my PF app (for both a v0.7 and PHal build).

The 2002 device lists nothing in the window name column for all processes.

I was going to try to see if my minizimation code worked, but I don't think it is set up for PHAL. What should one do to minimize a PF/PHAL app? I think before, I just called 'ShowWindow(SW_HIDE);'

Doing this seems to cause the screen to lose focus, but not the buttons. Strange, since you can operate the game from the buttons, but clicking on the screen gets you back to the other windows.
I am not sure what this "FAKEIMEUI" thing is. muff wanted a way to guarantee his app was only running once (that's my understanding), so I posted the code that did it.

As for the buttons... I am not explicitely releasing control of them when your app is desactivated. But this should be done automatically by the OS. I have the feeling that hiding a window the way you do it does just that: hide it. It doesn't desactivate it. The right solution is to use "SW_MINIMIZE", but alas it is not supported on WinCE. In any case, I will do some testing and see what can be done to minimize an app.
I guess I should have been more descriptive...

executing the ShowWindow(SW_HIDE) DOES exit to the regular desktop. Funny thing is that it is NOT listed in the running programs tab in the memory control panel!

Starting the app again does bring it back up where it left off (so I know it was minimized, and also that the FindWindow() must have worked...)

The only problem is that the desktop has the focus on the stylus at this point, but the keys are sent to the PF app. Clicking on the screen just goes back to the desktop...

I hope that makes sense.
Yes. I think I know what is wrong. As for the window name and it not showing in the memory tab, mmm. Will have to find that one too.
<wonders if muff ever got it working...>


Some points of interest...
*Even though the remote process viewer has that bogus name, the FindWindow(...) code does work correctly. There was another program that had the same bogus window name at one point.

*Calling ShowWindow(SW_HIDE) does not cause the GameSuspended function to fire off...at least the user overridden one. And GameResume() is not called autmatically durind what I have in my 'bAlreadyRunning' section (I need to make sure I try the exact code - I'm not doing the IsIconic )

*And lastly, the main message loop of PF doesn't include any sleep time when the game is suspended (look for m_bSuspended I believe). It needs to be an if/else with something like Sleep(250) when it's not active. Originally, minimizing my app would slow the system down. I thought this had been added a while back - but it didn't make it into the last release.


edit: one more thing...
When using a SendMessage(... WA_INACTIVE), the program DOES show up in the running programs tab of the system/memory. So, SW_HIDE really hides well.
fast_rx wrote:Some points of interest...
*Even though the remote process viewer has that bogus name, the FindWindow(...) code does work correctly. There was another program that had the same bogus window name at one point.


I couldn't find what this bogus name is, but read on:

fast_rx wrote:*Calling ShowWindow(SW_HIDE) does not cause the GameSuspended function to fire off...at least the user overridden one. And GameResume() is not called autmatically durind what I have in my 'bAlreadyRunning' section (I need to make sure I try the exact code - I'm not doing the IsIconic )


I am unable to reproduce your button problem with PHAL 0.8.4. I do get a call to OnGameSuspend(). Did you implement the "focus fix" for PF0.7.0 by removing the WM_SETFOCUS and WM_KILLFOCUS handlers?

Calling ShowWindow(SW_HIDE) or SetWindowPos( ... SWP_HIDEWINDOW ) indeed hides the window. This is why it is not showing up in the task list. I am still investigating the proper way of "minimizing" an app, but consider that the following code brings you to the today screen and works perfectly (ie your app will show in the task list):

Code:

HWND hwnd = GetDesktopWindow();
SetForegroundWindow( hwnd );


It seems that in your case, hiding the window doesn't activate the app. This is somewhat expected and would explain your button problem. Stylus input on the other hand will go to the topmost visible window. Can you try "minimizing" the app using this snippet of code and see what happen? If it still doesn't work, can you send me some code that exhibits the problem?

fast_rx wrote:*And lastly, the main message loop of PF doesn't include any sleep time when the game is suspended (look for m_bSuspended I believe). It needs to be an if/else with something like Sleep(250) when it's not active. Originally, minimizing my app would slow the system down. I thought this had been added a while back - but it didn't make it into the last release.


This will be fixed. Minimized apps shouldn't use any CPU.

fast_rx wrote:edit: one more thing...
When using a SendMessage(... WA_INACTIVE), the program DOES show up in the running programs tab of the system/memory. So, SW_HIDE really hides well.


Indeed. It is not the proper way of minimizing an app. Aside from setting the desktop on top, I am not sure what can be done.
Thierry,

Using the 'GetDesktopWindow()' way of minimizing works except that the GameSuspend() function is not called...

I tried briefly to send a WM_ACTIVATE/WA_INACTIVE message to the application as well, but I never could get it to work. I tried both SendMessage and PostMessage...

Is there another way to get the GameSuspend to automatically fire when it's supposed to?
It works perfectly here with PHAL. Which version of PocketFrog are you using?
I'm using PF0.8 with some modifications... Nothing that should keep the messages from working though. I did add that 'if(m_suspended) Sleep(250) else GameLoop' thing in order to not use a lot of processor time when suspended.

Are you sure it's working? My project is using hekkus, so I can easily tell that the suspend was not called since the music is still playing...
I am sure it's working with PHAL 0.8. I will have to test this again with PF 0.8. Hopefully tonight.
I took the latest PF release as-is (with PHAL 0.7.3) and added the "ButtonDown()" callback to class BlitSample:

Code:

void BlitSample::ButtonDown( int button )
{
HWND hwnd = GetDesktopWindow();
SetForegroundWindow( hwnd );
}


I then updated the message pump so that it would be like yours:

Code:


// Main loop
for(;;)
{
MSG msg;

if (::PeekMessage( &msg, 0, 0, 0, PM_REMOVE ))
{
if (msg.message == WM_QUIT)
break;

::TranslateMessage( &msg );
::DispatchMessage( &msg );
}
else
{
if (!m_bSuspended)
GameLoop();
else
Sleep(250);
}
}


I then put two breakpoints in Game::GameSuspend() and Game::GameResume().

I then run the blit sample under the debugger and as soon as I hit a button on my PDA, I hit the breakpoint in GameSuspend(). I press <F5> to continue running the app.

I then go to "start menu->settings->memory" and select the "Blit Sample" and click "Activate". Right away I get a hit in the debugger (GameResume()).

So yes, this is working perfectly here. Would you consider sending me your source code so that I can try running it under the debugger here? Email is "thierry-at-droneship-dot-com".
I am doing pretty much the same thing, except using the Hekkus sample.

I put a breakpoint in the game.cpp file on line 442 in the
LRESULT Game::OnActivate( UINT msg, WPARAM wparam, LPARAM lparam, BOOL& bHandled )
function...

It is called when I expect it, but Game::GameSuspend(); calls the GameSuspend in game.cpp, not the one defined as HekkusSample::GameSuspend()


Looks like the problem is the call to the GameSuspend and GameResume in the OnActivate. Removing the 'Game::' from them allows the user declared functions to run instead of the default ones (is overridden the correct term to use?).
fast_rx wrote:Looks like the problem is the call to the GameSuspend and GameResume in the OnActivate. Removing the 'Game::' from them allows the user declared functions to run instead of the default ones (is overridden the correct term to use?).


Are you telling me that Game::OnSuspend() is being explicitely called from OnActivate()?

If this is so, it is totally wrong and it escaped me. OnActivate() should of course call OnSuspend() without the "Game::" prefix. Same thing for OnResume().
Yes, that is what I was trying to say...

It seems to have been this way since it was changed from PocketPC::Suspend() back in version 0.61.
No wonder I couldnt reproduce it, I was always putting my breakpoints in Game::OnSuspend().

Oh well. So now you have your fix =)
Sorry to dig this thread up again...

But I noticed that the code in Thierry's first post has this:

HWND hOther = ::FindWindow( uniqueName, 0 );

Which is looking for a class name, not a window name. Looking at the PFrog source, it appears to be setting the window name with the Create() method. I'm using the same thing - but with the parameters swapped.

The reason I was looking at this so closely is that it appears to be related to my 'Loading Delay' thread.

Programs I've written with the code to allow 1 instance will not load after the problem starts - whereas other programs (anything without the 1 instance code) will load fine.
You don't want to do a FindWindow() with a window name, because this can indeed hang your app. This is exactly what you are getting.

I don't remember the details, but I think FindWindow() has to ask the existing window for its name by sending a WM_GETTEXT or something like that. This request can hang or stall for a long time.
That makes sense that another app may not be responding to the WM_GETTEXT request.

But, I don't see where PF is setting a class name, so what should you do to make it work?

And lastly, I was not using the mutex to determine when I should even be looking for the existing window. I suppose that is a safer way to do things, so that is added now. That will probably eliminate 99/100th of the problems.
ATL is setting the window class for you.

Lookup "CWndClassInfo::m_szAutoName" in help. It seems you simply have to declare a class name in the .h "DECLARE_WND_CLASS".

So I would expect something like this to work:

Code:

class BlitSample : public Game
{
DECLARE_WND_CLASS( TEXT("MyClassName") )
...
Wow, that was simple enough...

The minimize works, restore works, even the window name in the remote process viewer is correct (as opposed to FAKEIMEUI).

It will take a while to see if the loading delay is fixed or not since it didn't happen too often.


Thanks Thierry.