views:

411

answers:

1

Below is my message filter:

bool MyFilter::PreFilterMessage(Message %m){
    switch(m.Msg){
    case WM_CLOSE:
    case WM_DESTROY:
    case WM_NCDESTROY:
    case WM_QUIT:
     Debug::WriteLine(L"Gone!");
     break;
    case WM_MOUSEMOVE:
     Debug::WriteLine(L"A mouse! Catch! Catch!!! CATCH!!");
     break;
    }
    return false;
}

I verified that I am filtering most messages without a problem. However, I am not receiving any messages dispatched after the window's close button is clicked (WM_CLOSE, WM_DESTROY, WM_NCDESTROY and WM_QUIT). Why is this?

+4  A: 

IMessageFilter.PreFilterMessage() is only called for messages in the message queue. Messages like WM_CLOSE are sent directly to WndProc() with SendMessage(), they bypass the queue. You also won't get messages like WM_ACTIVATE, WM_GETTEXT, etc. Input events, that's about it.

Hans Passant
What about WM_LBUTTONDOWN? And where can I find out which messages are sent directly to the WndProc and which ones are posted to the message queue?
Vulcan Eager
WM_LBUTTONDOWN is usually posted, not sent. It depends on the code generating the message.
Hans Passant