How to ignore WM_CLOSE (again...)

L

luser

Hi all!

I've been trying for a couple of days now to understand how i can
ignore VW_CLOSE.
I'm using ApplicationEx and IMessageFilter from opennetcf, and are able
to catch the
VW_CLOSE message. But from there it's just no go...

When i have caught the WM_CLOSE event, i have tried to look at the
message queue, and ignore the message if it's the VW_CLOSE. But, when
using PeekMessage, there's no message at the queue.

Firstly i need help with understanding the IMessageFilter. When i
have caught a message, is that; a) before it's in the message queue,
b) while it's in the message queue, or c) after it has been on the
message queue?

I've been using the ApplicationEx sample code, and have added

case WinMsg.WM_CLOSE:
System.Windows.Forms.MessageBox.Show("WM_CLOSE caught!");
MsgProcessing.SuppressCloseEvent();
break;

to the public bool PrefilterMessage(ref Message m) method in the
Filters class.


MsgProcessing.SuppressCloseEvent() looks like this:

public static bool SuppressCloseEvent()
{
//Microsoft.WindowsCE.Forms.Message lpMsg;
MSG lpMsg;
// check for messages
while(PeekMessage(out lpMsg, IntPtr.Zero, 0, 0, PM_NOREMOVE))
{
// there is, so get the top one
if(GetMessage(out lpMsg, IntPtr.Zero, 0, 0))
{
if (lpMsg.Msg == (int)WinMsg.WM_CLOSE)
{
}
else
{
TranslateMessage(out lpMsg);
DispatchMessage(ref lpMsg);
}
}
}
return true;
}

I can step through the code, and see that the while-loop never is
true, i.e no messages exists in the message queue?

I have read a lot of post where the author says that have managed
to catch the WM_CLOSE message, and then just ignore the message.
But how the h-ll do you ingore the WM_CLOSE message?

Any help would be really appriciated, since this is slowly driving
me mad (and I have already reached the 100 mph mark...).

//Kind regards, Torbjörn.

PS. This is posted in both
microsoft.public.dotnet.framework.compactframework
and the opennetcf.org forum. DS
 
G

Guest

If you're using ApplicationEx.Run, then it has a message pump that takes
messages out of the queue and dispatches them. Before dispatching them, it
runs them through any filters. A Filter can prevent it from being
dispatched be simply returning true. It works just like the desktop
documentation says.

http://msdn2.microsoft.com/en-US/li...s.imessagefilter.prefiltermessage(VS.80).aspx

-Chris




Hi all!

I've been trying for a couple of days now to understand how i can
ignore VW_CLOSE.
I'm using ApplicationEx and IMessageFilter from opennetcf, and are able
to catch the
VW_CLOSE message. But from there it's just no go...

When i have caught the WM_CLOSE event, i have tried to look at the
message queue, and ignore the message if it's the VW_CLOSE. But, when
using PeekMessage, there's no message at the queue.

Firstly i need help with understanding the IMessageFilter. When i
have caught a message, is that; a) before it's in the message queue,
b) while it's in the message queue, or c) after it has been on the
message queue?

I've been using the ApplicationEx sample code, and have added

case WinMsg.WM_CLOSE:
System.Windows.Forms.MessageBox.Show("WM_CLOSE caught!");
MsgProcessing.SuppressCloseEvent();
break;

to the public bool PrefilterMessage(ref Message m) method in the
Filters class.


MsgProcessing.SuppressCloseEvent() looks like this:

public static bool SuppressCloseEvent()
{
//Microsoft.WindowsCE.Forms.Message lpMsg;
MSG lpMsg;
// check for messages
while(PeekMessage(out lpMsg, IntPtr.Zero, 0, 0, PM_NOREMOVE))
{
// there is, so get the top one
if(GetMessage(out lpMsg, IntPtr.Zero, 0, 0))
{
if (lpMsg.Msg == (int)WinMsg.WM_CLOSE)
{
}
else
{
TranslateMessage(out lpMsg);
DispatchMessage(ref lpMsg);
}
}
}
return true;
}

I can step through the code, and see that the while-loop never is
true, i.e no messages exists in the message queue?

I have read a lot of post where the author says that have managed
to catch the WM_CLOSE message, and then just ignore the message.
But how the h-ll do you ingore the WM_CLOSE message?

Any help would be really appriciated, since this is slowly driving
me mad (and I have already reached the 100 mph mark...).

//Kind regards, Torbjörn.

PS. This is posted in both
microsoft.public.dotnet.framework.compactframework
and the opennetcf.org forum. DS
 
T

Torbjorn Stavas

Thnx a lot!

I thought i have tried to return true, but i screwed up in some way... =/

Again, thnx for the swift reply.

//torbjörn
 
L

luser

Another question about catching closing messages:

I suppose you can't stop your program from being shut down if the user
goes to System->Memory->Running Programs and clicks on "End task" after
he/she gets information that the program aren't responding, etc?

//Regard, Torbjörn
 
G

Guest

Probably not. I think it's sends a WM_COLSE, which you can catch and
prevent, but I think it then looks to see if it took effect and calls
TerminateProcess if it didn't, assuming it's hung. There's no way to
intercept that.

-Chris
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top