screen coordinate problem in EasyCE
i have a little difficulty here, hope you can give me some idea to overcome it.
i created a fullscreen game, when playing, if there are some background application trying to pop up a message (eg: the low battery status, or some poutlook reminder), the fullscreen game will start flickering (seems like it is drawing those popup windows at background). and the worst part came in, the clickypos() will be shifted by around 60 pixels down. that means, if i point at (0,60) it will be returning as (0,120).
was wondering if anyone facing the similiar problem, and if you could provide some hints to overcome this

Capture WM_ACTIVATE messages, and check LOWORD(wParam) to see if you are gaining or losing focus.
If losing focus:
Release the screen buffer if you have it, and don't draw to the display until you regain activation.
Go into a "pause" type state, making sure you Sleep to give plenty of processing time to the app that is now active. Process Windows messages while in that paused loop, so you can handle the WM_ACTIVATE you get when you regain activation. Stay in the loop until your "paused" flag is not set.
If gaining focus:
Call SHFullScreen to hide the taskbar, then resize your main window to the dimensions of the display. Clear the paused flag.
Dan East
After posting I noticed that in the subject you state you are using EasyCE. The problem could lie within Jacco's library. I don't know if it is supposed to handle those type of messages or not. My guess is that after regaining activation you are not sizing your window to take over the whole display, which would throw off your mouse coordinates because your window would no longer cover the taskbar at the top and app bar at the bottom.
dan East
here's what happened in EasyCE when trapping the messages:
case WM_ENABLE:
case WM_ACTIVATE:
case WM_CREATE:
case WM_SETTINGCHANGE:
taskbar( false );
break;
with your explanation, i guess we can tweak it as
case WM_ENABLE:
case WM_ACTIVATE:
if (lParam) {
// set pause flag;
break;
}
case WM_CREATE:
case WM_SETTINGCHANGE:
taskbar( false );
break;
what do you think of this?
The problem with that first example is that WM_ACTIVATE is used for both activation / deactivation. Unlike WM_SETFOCUS and WM_KILLFOCUS, where the two events are broken into two different messages, MS lumped activation into one. So something like this would be a step in the right direction:
[fixed]
case WM_ACTIVATE:
if ( LOWORD( wParam ) !=WM_INACTIVE ) {
// clear pause flag
bPaused=false;
// hide taskbar
taskbar( false );
} else {
// set pause flag
bPaused=true;
// show taskbar
taskbar ( true );
}
break;
case WM_ENABLE:
case WM_CREATE:
case WM_SETTINGCHANGE:
taskbar( false );
break;
[/fixed]
Now I don't know what all is done in taskbar(), but it needs to call SHFullScreen, and size the main window to the display size.
In your main game loop you would check each cycle for bPaused. While bPaused, you do a message pump and sleep.
Dan East
here's what happened in EasyCE when trapping the messages:
case WM_ENABLE:
case WM_ACTIVATE:
case WM_CREATE:
case WM_SETTINGCHANGE:
taskbar( false );
break;
with your explanation, i guess we can tweak it as
case WM_ENABLE:
case WM_ACTIVATE:
if (LOWORD(wParam) == INACTIVE ) {
// set pause flag;
break;
}
if (LOWORD(wParam) == ACTIVE )
// clear pause flag;
case WM_CREATE:
case WM_SETTINGCHANGE:
taskbar( false );
break;
is this going to work?

sorry i made some mistake in the previous reply and i reposted this.
Close. See my example. Your WM_ENABLE case is falling through to WM_ACTIVATE, so the same code is being executed for both. Then don't forget to break before WM_CREATE, because taskbar( false ) is being executed for all cases as well.
BTW, you ought to register to these boards. You can then edit and delete your posts, and the board notifies you when threads and forums have new posts that you haven't read yet.
Dan East
i've just got myself registered.

now that i've added in the code, the screen no longer flashes in and out while something popup in the background. but a new problem appear :p i can't get back control to the game...
i added a pause flag as suggested, and in my update() code i just check if it is paused then perform a sleep(100) and return without drawing the game screen.
what else could be the problem??
You have to pump Windows messages somewhere along the way. I don't know where EasyCE does this, but you may be bypassing it. You can just do a loop as follows in your update code:
[fixed]
while ( paused ) {
MSG msg;
while ( PeekMessage ( &msg, NULL, 0, 0, PM_REMOVE ) ) {
TranslateMessage ( &msg );
DispatchMessage ( &msg );
}
Sleep( 100 );
}
[/fixed]
Dan East
Last modification: Dan East - 12/12/01 at 21:53:18
i see, so the PeekMessage will be able to capture messages sent to the program and invoke WndProc ?
I've added the modifications that Dan suggested to EasyCE. I hope to release 1.6 soon, it will have the faster line code (fixed point, works like a charm), the 3800 code, faster rotation code for the iPaq framebuffer, and of course this message stuff (I REALLY suck at windows coding).
sillycat, PeekMessage checks to see if there are any messages pending. TranslateMessage converts keyboard accelerator codes to their true commands (which is seldom useful for CE, probably never for games). The DispatchMessage does the real work, and eventually calls your WndProc. I use PeekMessage is used instead of GetMessage so we only stay in that inner loop as long as messages are pending. Windows messages usually come in bursts, so you're better off processing all that are available at once, then sleep or do whatever else (your game processing, for example). GetMessage is like PeekMessage, but it will block and wait until a message arrives.
Jacco, Windows programming is a pain, because you have to do things the way MS wants you to.
Dan East
great, it works now. windows return control to my game. but again, new problem arise :p again, pls help me...

now that the mouse coordinate is correct, and windows do return control to my game, but i found that if there's a popup window at the background when i click on the game screen it will be clicking the popup! that's terrible :p it freezes the lower half of my game screen. when i tap on that part of the screen the background popup will flicker, then upon game screen update it is covered.
seems like me sucks even more at windows programming :p
The problem you are talking about I have see when
I was developing the palettize code for EasyCE.
If the PPC was turned off with EasyCE running then on the logical palettize becomes off of context and EasyCE would display the image using the default palette. I got round this by calling
RealizePalette() each time the display is updated.
LLcooL, I don't think you guys are talking about the same thing.

What you ought to do is just call RealizePalette when you app gets activation, instead of every frame.
sillycat, if you (or EasyCE) captures the mouse (SetCapture), then you need to release / recapture appropriately in the WM_ACTIVATE handler.
Dan East
Dan is corrrect. LLcool you've mistaken my question

thanks to both of you. i'll try that out later.
Hm, I should have captured the mouse?

Why?
Well, since your app is fullscreen its not really necessary. I have to capture the mouse in DEXplor when the user drag / drops, because they can drag outside of my window.
It sounds like sillycat is not MoveWindow'ing his window to cover the whole screen when he gets WM_ACTIVATE. I also don't think he should be getting an activation message in the first place if a popup window he doesn't own is still covering his window.
DanEast
the taskbar() function is moving the windows to cover fullscreen.
and for the popup, it is not covering my window, my window covers it but yet my window seems not able to capture mouse events at that particular area where the popup is....
I just took a look at the 1.5 source. In the "taskbar" function Jacco finds the system taskbar, gets its dimensions, gets the dimensions of your main window, then resizes the window's rect based on the taskbar size. I use a much simpler approach that should work for all cases. I simply explicitly size my main window to the size of the display. I also have not needed to manually hide the taskbar window. This is all I do when I gain activation:
[fixed]
SHFullScreen(hWnd, SHFS_HIDETASKBAR);
MoveWindow(hWnd, 0, 0, GetSystemMetrics(SM_CXSCREEN),
GetSystemMetrics(SM_CYSCREEN), TRUE);[/fixed]
hWnd is of course the handle to your main window.
Dan East
[sub][color=blue]Last modification: Dan East - 12/18/01 at 20:27:51
Dan,
If I use your code to hide my taskbar, I get problems: When I click the first couple of lines, I get windows stuff flickering through my app... When I change back to my original lines, the problem is gone.
- Jacco.
Hmm. I use that in PQ, PWolf, and other software that takes over the display, and it works fine. I noticed in your WM_ACTIVATE handler you are not handling all cases of activation. There is one inactivate code (WA_INACTIVE), but multiple activation. So if LOWORD(wParam)!=WM_INACTIVE then your window is being activated.
Dan East
Dan,
Right now, my message handling looks like this:
- Code:
// Dan's suggestions
case WM_ENABLE:
break;
case WM_ACTIVATE:
if (LOWORD(wParam) == WA_INACTIVE )
{
taskbar( true );
GXCloseInput();
GXCloseDisplay();
paused = true;
break;
}
if (LOWORD(wParam) == WA_ACTIVE )
{
taskbar( false );
GXOpenDisplay( NULL, GX_FULLSCREEN );
GXOpenInput();
paused = false;
}
break;
case WM_CREATE:
case WM_SETTINGCHANGE:
taskbar( false );
break;
I'm testing this stuff now (added it last night) to see if it handles low batteries properly (it should pause the game automatically). This works properly with my own taskbar function, but when I replace it by your taskbar stuff, I get problems even when there are no other windows take over control (such as the battery meter).
So basically, if this message stuff works with my own taskbar stuff, there's no problem, but your taskbar code looks better (smaller).

I just noticed that in the above code, the pause = true line is never executed. So aparently my app never receives a WM_ACTIVATE event with a WA_ACTIVATE parameter... Could this have something to do with the way I open the window? It's opened by this line:
- Code:
hWnd = CreateWindowEx(WS_EX_TOPMOST, wincls, szTitle, WS_VISIBLE, 0, 0, 240, 320, NULL, NULL, hi, NULL );
And one more question: Once my app goes to sleep (for instance, when an agenda item pops up), how do I get it back in action?

Would closing the appointment popup be enough?
- Jacco.
The TOPMOST style could definitely be causing problems. I don't use that in any of my fullscreen apps either.

Well, technically using the Pocket PC paradigm, the way to get it active again is to "run" the app again from the start menu, etc. When your app first runs it should check for previous running instances, and switch to one of those and exit. You can also click on your window if any part of it is visible. You should then receive WM_ACTIVATE with a WA_CLICKACTIVE code. Of course there are also task-switchers like WisBar.
Dan East
OK, so if I shouldn't use the TOPMOST approach, how would you modify that line?
If you're not specifying an extended style, then you don'tneed to use CreateWindowEx in the first place. Just call CreateWindow instead, and omit the first parameter completely.
Dan East
Phantom, a little request

could you make the next release of EasyCE include the function for detecting the same apps that is already running and activate it ?
thanks guys.
check out the new thread i posted, i am releasing the game for free

Sillycat: Certainly, I'll add that.
Dan: If I use CreateWindow without the TOPMOST parameter as you suggested, I can press the SIP button even if it's not visible... Making the bottom 20 or so pixels useless. Is there a solution for this? Right now I'm under the impression that there is no safe way to have a full-screen app that responds correctly to other apps...
great! i've learned a lot through this thread, esp. from you both, Dan and Phantom.
