Handling WM_USER messages

B

Bob Kirkwood

Does anyone know how a C#/Forms application might handle a
user defined windows message. I need to do it for
migratin reasons.
 
C

Chris Dunaway

Does anyone know how a C#/Forms application might handle a
user defined windows message. I need to do it for
migratin reasons.

The Form has WndProc that you can overload to catch those messages in a
form.

I think the Application class has a SetMessageFilter method thay may help
you.

Chris
 
Y

Ying-Shen Yu[MSFT]

Hi Bob,
Chris has given some idea on this issue, and I'd like to expand the
solution.
In Win32, we often handle the messages in wndproc , Now in WinForm the
WndProc still exists, every class derived from Control class have a
protected method named WndProc, you can override this method to handle your
own message of that control. Here is some snippet to show how to do this.
<code>
protected override void WndProc(ref Message m)
{
const int WM_USER = 0x0400;
If(m.Msg == WM_USER)
{
//call your handler here.
}
base.WndProc(ref m);
}
</code>
Also if you need to handle the message before it is dispatched, you may
implement the IMessageFilter interface to do this job, You can add a
MessageFilter to the MessageLoop by the Application.AddMessageFilter
method, to get more information on and sample code on this topic you may
take a look at the this link:
<Application.AddMessageFilter Method>
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/
frlrfsystemwindowsformsapplicationclassaddmessagefiltertopic.asp

Does this answer your problem?
Please be free to reply to this group, if you have anything unclear on it.
Thanks!


Best regards,

Ying-Shen Yu [MSFT]
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security

This posting is provided "AS IS" with no warranties and confers no rights.
You should not reply this mail directly, "Online" should be removed before
sending, Thanks!
 
B

Bob Kirkwood

WndProc was not sufficient, many messages arrived there,
but not my WM_USER message (actually WM_USER + 1).

Calling Application.AddMessageFilter (mymsgfilter) did
work. Thanks for the help.
 
N

news.microsoft.com

Why doesnt WndProc allow processing of ALL mesages? Sounds stupid.

I would expect all messages to be available there and its up to me to
process what I need.
 
Y

Ying-Shen Yu[MSFT]

Hi,
Every class derived by control has an WndProc, probably in this case, the
overridden WndProc was not in the control which the WM_USER message posted
to. Anyway, IMessageFilter will work, because it will get all messages from
the message queue.

Best regards,

Ying-Shen Yu [MSFT]
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security

This posting is provided "AS IS" with no warranties and confers no rights.
You should not reply this mail directly, "Online" should be removed before
sending, Thanks!
 

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