Subclass to read Windows messages in C#
Every form has a function called WndProc that processes Windows messages. This function handles messages telling the form to move, resize, redraw, close, display system menus, and all sorts of other things. Without it, the form can't do anything.
To see what messages the form is receiving, you can override WndProc as shown in the following code.
// Override WndProc to watch for messages.This function receives a Message object as a parameter and uses its ToString method to display the message's name. The code then calls the base class's WndProc method to process the message normally. This is very important! If you don't process the message normally, the form will not be able to resize itself, draw its interior, and perform other standard Windows functions.
protected override void WndProc(ref Message m)
{
Console.WriteLine(m.ToString());
base.WndProc(ref m);
}


Comments