HELP! AddMessageFilter

  • Thread starter Thread starter Mark Everett
  • Start date Start date
M

Mark Everett

Hi all,

I want to send a window message from a normal win32 application to my
windows forms app.

In my Windows forms app I do:
Application.AddMessageFilter( new IncomingMessageFilter() );

My implementation of IMessageFilter uses PreFilterMessage to test the
messages .Msg property value. Thing is the message never arrives. I
send the message using the following:

SendMessage( wnd, TEST_MESSAGE, NULL, NULL );

The window handle is obtained using FindWindow which is returning the
HWND successfully. But m.Msg is never equal to TEST_MESSAGE which I
set to WM_APP + 0x666. Any ideas? Is this the best way to do this as
as far as I understand the messagefilter will pick up *ALL* messages
not just those to my window. This doesn't seem to be very optimum. Is
this correct?

Finally a quickie. I have noticed in lots of sample code references to
Win32.Msgs.WM_XXX but I cannot work out what reference I have to use
to include Win32. Is this just for managed code or something?

Thanks in advance
Mark
 
See inline

Mark Everett said:
Hi all,

I want to send a window message from a normal win32 application to my
windows forms app.

In my Windows forms app I do:
Application.AddMessageFilter( new IncomingMessageFilter() );

My implementation of IMessageFilter uses PreFilterMessage to test the
messages .Msg property value. Thing is the message never arrives. I
send the message using the following:

SendMessage( wnd, TEST_MESSAGE, NULL, NULL );

The window handle is obtained using FindWindow which is returning the
HWND successfully. But m.Msg is never equal to TEST_MESSAGE which I
set to WM_APP + 0x666. Any ideas? Is this the best way to do this as
as far as I understand the messagefilter will pick up *ALL* messages
not just those to my window. This doesn't seem to be very optimum. Is
this correct?

IMessageFilter.PreFilterMessage picks up all messages in the message queue
before they are dispatched to the window proc. Your problem is that
SendMessage doesn't place the message in the queue, it calls the window proc
directly. Try PostMessage instead.
Finally a quickie. I have noticed in lots of sample code references to
Win32.Msgs.WM_XXX but I cannot work out what reference I have to use
to include Win32. Is this just for managed code or something?

This is an old namespace/class that existed in the beta versions for the
first VS.NET. It doesn't exist any more (AFAIK).


/claes
 
Back
Top