switch( Msg )
{
case WM_PAINT:
{
PAINTSTRUCT ps;
HDC hdc = BeginPaint(&ps);
this->OnPaint( hdc );
EndPaint(&ps);
}
return 0; // We've already handled it and we don't want to pass it to DefWindowProc().
case WM_SIZE:
// Here lies code which we want to execute whenever the window is resized,
// but we still want DefWindowProc() to handle the message, so we break.
this->OnSize();
break;
}
return DefWindowProc();
Of course, you could still replace your "break;" statements with a "return DefWindowProc(...);" statement, but that seems counter-intuitive to me.
There is an somewhat old article which discusses coupling a C++ object with a native window handle (HWND) here. It's one of the better ways to do it. The finished code is in what he calls the AngelCode Tool Box, and the files most relevant to this discussion are acWindow.h and acWindow.cpp which you can find here.
Notice that WM_NCDESTROY is guaranteed to be the last message that a window will receive from the system, WM_NCCREATE is not the first message it will receive. I think the first message received by a window's message processor is WM_NCCALCSIZE, but I don't think it says so in the docs, so it can change, so good code will not depend on that piece of information. The article I linked above talks about how to do it by setting a hook procedure that gets called whenever a window is created, creating the window (and consequently the hook procedure that will do the coupling), then removing the hook procedure.
Good luck.