I have some questions regarding overriding the WndProc method of a Windows Form / NativeWindow.
What exactly is the difference between WndProc and DefWndProc (edit: I thought it is called "DefaultWndProc" before)? I can only override WndProc, but what is DefWndProc for, which I can call anytime?
And where to call base.WndProc in my overridden method? Or should I call DefWndProc instead? The following positions came into my mind:
protected override void WndProc(ref Message m)
{
// 1st: I call the base handler at the start, in front of my handling.
// Are there disadvantages here?
base.WndProc(ref m);
switch (m.Msg)
{
case (int)WindowsMessage.Paint:
// 2nd: Do whatever you want to do now. I could also place
// base.WndProc for each message manually here, at a point I
// can control myself. It makes the method a little messy
// since I have several base calls for each message I handle.
base.WndProc(ref m);
break;
default:
// 3rd: If I put it here, it never gets called for messages I
// have handled. I think it is disastrous for specific
// messages which need additional handling of the system.
base.WndProc(ref m);
}
}
// 4th: Or put it here. It gets called even after messages I have
// already handled. If I made some drawings in WM_PAINT, doesn't
// calling the system's default method draw "over" my paintings?
// And is this really needed?
base.WndProc(ref m);
}
What do you recommend? Is there a best-case-scenario or does it heavily depend on which messages I handle?