PocketMatrix forums

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

PPC2002 (X) on applications

What is the windows message that is sent when the little (X) in the upper corner of an app is pressed?

It is not a WM_COMMAND like in a dialog.

Hrm...is it the WM_CLOSE?
It is indeed WM_CLOSE.
uh..nope. tried it. meh...

thanks though.

anyone else?
Where / what are you sending it to?

Dan East
not related but that button sucks it doesnt even close the app it just sends it to the background!
WM_TERMINATE is the command that actually closes the app, I believe.
WM_MINIMIZE would be the one that brings it to the background.
Let me be more clear. I want my app to close, not go to the background when it is tapped. So, I want to capture that command.

I suppose I could use Spy++ or something to find out.

My app creates a ~[filename].xml temp file, and I want it gone when it closes.
Is there a spy++ for the ppc?
Yeah, do you have eVC++? It's tools->remote spy++, or you can find it in C:\Windows CE Tools\BIN if you installed to the default directory.
Cool thanks, i just learned something new. You should make the X close your program i guess microsoft missed that X means close not hide when they built ppc2002.
Ok, it's one of the following.

WM_NCACTIVATE
WM_CANCELMODE

I can't find NCACTIVATE in the help files, so I have no clue what that is. My guess it is the CANCELMODE.
Okay, now I see what you are trying to do. Here's the docs for WM_NCACTIVATE:

WM_NCACTIVATE
The WM_NCACTIVATE message is sent to a window when its nonclient area needs to be changed to indicate an active or inactive state.

A window receives this message through its WindowProc function.

LRESULT CALLBACK WindowProc(
HWND hwnd, // handle to window
UINT uMsg, // WM_NCACTIVATE
WPARAM wParam, // new state (BOOL)
LPARAM lParam // not used
);
Parameters
wParam
Specifies when a title bar or icon needs to be changed to indicate an active or inactive state. If an active title bar or icon is to be drawn, the wParam parameter is TRUE. It is FALSE for an inactive title bar or icon.
lParam
This parameter is not used.
Return Values
When the wParam parameter is FALSE, an application should return TRUE to indicate that the system should proceed with the default processing, or it should return FALSE to prevent the title bar or icon from being deactivated. When wParam is TRUE, the return value is ignored.

Remarks
The DefWindowProc function draws the title bar or icon title in its active colors when the wParam parameter is TRUE and in its inactive colors when wParam is FALSE.


So, if you receive WM_NCACTIVATE with wParam==FALSE, then PostMessage a WM_CLOSE to your main hwnd.

Dan East
Thank Dan...
WM_NCACTIVATE is undefined, so I have to use the hex, but other than that it is all cool.
Code:

switch (message)
{
case 0x86:
if (wParam == 0)
{
DeleteFile (szFileName);
PostMessage (hWnd, WM_QUIT, (WPARAM)NULL, (LPARAM)NULL);
}
break;
}


Don't know if anyone else is trying to do this, so here is what I did.

Also, the NCACTIVATE message comes in on activation with a wParam of 1, and on deactivation with a wParam of 0.

Though, I can tell you if you launch any other app, this app will terminate.
Don't know if anyone is reading this thread besides me, but just in case...

I used the code above and it was a no-go.

Problem is, if you launch a dialog or anything, the message is recieved and expected bad stuff happens. I was gonna put in a flag to handle this, but I don't want to hack it like that.

I am going to investigat WM_CANCELMODE a bit further, but until then, this is where I am.
You could get it to work as follows:
When you receive WM_NCACTIVATE, create a timer say for 5 seconds. If you receive a WM_ACTIVATE message look at what HWND is gaining activation, and decide if you want your app to close or not. That would also solve the problem of allowing the user to switch to other apps without closing your app (you reported that a WM_ACTIVATE is not received when the "close" button is clicked). Set a flag based on that info. In your timer handler, which will be triggered 5 seconds after WM_NCACTIVATE, only close your app based on the setting of your flag.

Dan East
It's called <A HREF="http://www.microsoft.com/mobile/developer/technicalarticles/whatsnew2002.asp">Smart Minimize</A>.

Of course, they don't tell you HOW to take advantage of it...so I will have to figure that out on my own.
Microsoft Docs wrote:
With Pocket PC 2002 something that looks like the Close button is back on the screen. The application gets a notification when the new smart minimize is clicked. The application can then either close or just ignore the click. If it ignores the click, the application will be minimized by the operating system instead of closing. For the user the effect is the same. The application is gone from the Pocket PC screen … for now.


Are you sure WM_NCACTIVATE and WM_CANCELMODE are the only messages received when the user hits the "close" button? It sounds like there should be a message sent prior to those indicating the event.

Dan East
These are all the messages that my window proc receives when I click on the 'x' on an iPaq 3870:

WM_WINDOWPOSCHANGED, wParam = 00000000, lParam = 2A0721A8
WM_SIZE, wParam = 00000001, lParam = 014000F0
WM_CANCELMODE, wParam = 00000000, lParam = 00000000
WM_NCACTIVATE, wParam = 00000000, lParam = 00000000
WM_ACTIVATE, wParam = 00000000, lParam = 00000000
WM_KILLFOCUS, wParam = 00000000, lParam = 00000000
WM_IME_SETCONTEXT, wParam = 00000000, lParam = C000000F
WM_IME_NOTIFY, wParam = 00000001, lParam = 00000000
And on my Casio E200

WM_KILLFOCUS
WM_ACTIVATE
WM_NCACTIVATE
WM_CANCELMODE
WM_SIZE
WM_WINDOWPOSCHANGED
I've run several tests on this, and the only two messages that seem to be directly related to the (x) button are the WM_NCACTIVATE and WM_CANCELMODE.

Thing is, if you capture either of these messages, they will get sent on a menu command, a new dialog, etc.

I am not seeing anything that is a message stating that this particular button is clicked. Yet, in the MSDN it say, specifically that you can choose to close the app when it is clicked.
You're being sent a Minimize command via WM_SIZE. A wParam of 1 is equivalant to SIZE_MINIMIZED. You need to see if any other events cause your app to receive a WM_SIZE with wParam==SIZE_MINIMIZED (like when switching to another app - I think your main window is just hidden in that case, as opposed to minimized). So you may be able to close your app when you receive that type of WM_SIZE message.

MS is throwing all convention out the Window. They are really screwing things up and making it hard to support all these various versions of the OS. What if "real" support is added for truly minimized windows?

Dan East
Amen, its hard work progamming Win CE.
This thread is very informative. I've just started programming for Win CE. The documentation is very poor (which doesn't surprise me); I'm glad to have this forum for some REAL/APPLICABLE information.
I caught onto the WM_SIZE thing myself. It happens whenever you switch to another app. So, there it is. The (X) is just a minimize button.

BTW, I just re-installed VS6.0 whilst I was poking around the forum. It gets done and asks if you want to reboot, usually I say yes, but I said no so I could type this. Then it says that installation was not successful becuase I did not click yes. THEN a new dialog pops up and says 'The system must be restarted for the Installation Wizard to proceed. The system will now restart.' No 'cancel', just 'ok'. I find that humorous.
Just in case anyone still cares, it is WM_SIZE, with a SIZE_MINIMIZED wParam.

I actually stumbled across it in the documentation, but not through the index or a search. It is in the contents somewhere.

I am using it now, as I have a dialog box that is not a dialog box...or something. :)