Windows フォーム/NativeWindow の WndProc メソッドのオーバーライドに関していくつか質問があります。
WndProc と DefWndProc の違いは何ですか (編集: 以前は「DefaultWndProc」と呼ばれていたと思いました)? オーバーライドできるのは WndProc だけですが、いつでも呼び出すことができる DefWndProc は何のためにあるのでしょうか。
そして、オーバーライドされたメソッドで base.WndProc を呼び出す場所は? または、代わりに DefWndProc を呼び出す必要がありますか? 以下のポジションが頭に浮かびました。
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);
}
おすすめは何ですか?最善のシナリオはありますか、それとも処理するメッセージに大きく依存しますか?