How to override message loop in winforms application

  • Thread starter Thread starter Felix Collins
  • Start date Start date
F

Felix Collins

Hi All,
I have a situation where I need to do some custom message filtering.
Unfortunately I need more functionality than provided by the
IMessageFilter system or by overriding a Form's wndproc() method.
What I need is to be able to run code before and after a message is
processed and optionally drop selected messages.

As I understand it:

The IMessageFilter system only allows filtering out selected messages
(can't run code after they have been processed)

A Form's wndproc method only sees messages destined for that form. (I
need to handle all messages for the entire application)

In an unmanaged application say in visual c++ it would be a simple
matter of implementing ones own getmessage/dispatchmessage loop. In
the dotnet framework the actual message loop is implemented in native
code and is inaccessible to the programmer.

Does anyone know a solution for this?

Regards,
Felix
 
Hello Felix,
Hi All,
I have a situation where I need to do some custom message filtering.
Unfortunately I need more functionality than provided by the
IMessageFilter system or by overriding a Form's wndproc() method.
What I need is to be able to run code before and after a message is
processed and optionally drop selected messages.
As I understand it:

The IMessageFilter system only allows filtering out selected messages
(can't run code after they have been processed)

A Form's wndproc method only sees messages destined for that form. (I
need to handle all messages for the entire application)

In an unmanaged application say in visual c++ it would be a simple
matter of implementing ones own getmessage/dispatchmessage loop. In
the dotnet framework the actual message loop is implemented in native
code and is inaccessible to the programmer.

Does anyone know a solution for this?

You could host the managed application in a C++ application... That would
allow you access to the Messages for the whole application. It isn't too
hard to host a standard windows forms application inside an unmanaged C++
app.

This should get you started:
http://www.codeproject.com/KB/COM/simpleclrhost.aspx
 
Hello Felix,
Hi All,
I have a situation where I need to do some custom message filtering.
Unfortunately I need more functionality than provided by the
IMessageFilter system or by overriding a Form's wndproc() method.
What I need is to be able to run code before and after a message is
processed and optionally drop selected messages.
As I understand it:

The IMessageFilter system only allows filtering out selected messages
(can't run code after they have been processed)

A Form's wndproc method only sees messages destined for that form. (I
need to handle all messages for the entire application)

In an unmanaged application say in visual c++ it would be a simple
matter of implementing ones own getmessage/dispatchmessage loop. In
the dotnet framework the actual message loop is implemented in native
code and is inaccessible to the programmer.

Does anyone know a solution for this?

You could host the managed application in a C++ application... That would
allow you access to the Messages for the whole application. It isn't too
hard to host a standard windows forms application inside an unmanaged C++
app.

This should get you started:
http://www.codeproject.com/KB/COM/simpleclrhost.aspx
 
Back
Top