Once we understand the previous architecture, it makes sense to use it in a variety of ways: avoiding predefined behaviors for controls or windows, adding specific elements to existing windows components, and many others.
Let's try a basic example. Suppose that we want to change the way a window responds to the left button. Only that. So, we have a simple Windows Forms application, and we need to think of the elements we need in order to code that behavior.
First, we need to capture the specific messages addressed to the left button. Then, we have the override to WndProc
associated with our window, determine what to do if the message is the one required, and finally, always return the control to the operating system correctly.
This figure shows the process:
Fortunately, in C#, that's something pretty simple. Just look at this code, which we add to the main
, default window code created by the IDE:
protected override void WndProc(ref Message m) { // Captures messages...