How can I receive a user windows message in .NET

  • Thread starter Thread starter Hans
  • Start date Start date
H

Hans

Hi all,

I am about to replace an existing program by a C#
version. The old program is startet by a main program.

If the program is startet a second time, it sends a user
defined windows message to the first instance and
terminates.

In win32 this is not problem, but how can I add a message
handler for a user defined windows message to a .NET
form???

Anybody out there who can tell???
Hans.
 
* "Hans said:
I am about to replace an existing program by a C#
version. The old program is startet by a main program.

If the program is startet a second time, it sends a user
defined windows message to the first instance and
terminates.

In win32 this is not problem, but how can I add a message
handler for a user defined windows message to a .NET
form???

Add this to your form:

\\\
Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)
If m.Msg = ... Then
...
End If
End Sub
///
 
Herfried said:
Add this to your form:

\\\
Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)
If m.Msg = ... Then
...
End If
End Sub
///

Hm, I doubt his C# compiler will like this code ...

Gerhard Menzl
 
And as a result you will end up controling every event in your form and will
be forced to reimplement almost every behaviuor.

You should pass all unporcessed messages to base.WndProc(ref m) for further
processing at the end of function call.

Jacek
 
* "Jacek said:
And as a result you will end up controling every event in your form and will
be forced to reimplement almost every behaviuor.

You should pass all unporcessed messages to base.WndProc(ref m) for further
processing at the end of function call.

ACK. Sorry, I forgot to write this line...
 
I handled WM_NCPAINT and painted an additional button in the title bar. I
called the base.WndProc at the end of the function and it doesn't work, my
button just flickers for a moment and the title bar becomes blank again. I
moved the call to the base class implementation as first line of the
function and it all seems to work fine.

Should the call to base class be at the beginning or end of the function?

--Saurabh

Jacek said:
And as a result you will end up controling every event in your form and will
be forced to reimplement almost every behaviuor.

You should pass all unporcessed messages to base.WndProc(ref m) for further
processing at the end of function call.

Jacek
 
It depends. If you process the message yourself you (probably)
don't want to call the base class

In your case the base class will paint over the stuff that you
just painted.

For WM_NCPAINT you should also set m.Result = IntPtr.Zero

/claes

Saurabh said:
I handled WM_NCPAINT and painted an additional button in the title bar. I
called the base.WndProc at the end of the function and it doesn't work, my
button just flickers for a moment and the title bar becomes blank again. I
moved the call to the base class implementation as first line of the
function and it all seems to work fine.

Should the call to base class be at the beginning or end of the function?

--Saurabh
 
Back
Top