I'm currently writing my own mini visual framework to wrap pure WinAPI in classes.
Currently the process of analyzing messages looks as follows:
static
Application::Run
has a message loop; it gets new message and dispatches it to apropriate WndProc.All windows I create are created from the same class (in terms of WinAPI), so the same
WndProc
is being called. Actually, it's a staticFormAPI::WndProc
method. This one checks, which window the message refers to and calls itsWndProc
.Form::WndProc
method is called, which analyzes message. Suppose, that it's aWM_MOUSEMOVE
. It callsProcessMouseMove
and thenDefWindowProc
. Remember this point as [1].private
Form::ProcessMouseMove
gets the actual data from the message (eg. x, y, shift state), converts it into usable data and calls protectedForm::OnMouseMove
.Finally, protected
OnMouseMove
checks, whether event handler is set (that is,std::function<void(Form *, int, int, ShiftState)>
) and if so, it calls the handler. Otherwise it does nothing.
My concern is about calling DefWindowProc
. It may seem, that its simply "do the default behavior for me", but sometimes it actually does some critical stuff. For instance, disabling WM_LBTNDOWN
by not calling DefWindowProc
will result in inability to close window by clicking the [X] button.
On the other hand, sometimes I don't want to call DefWindowProc
. For instance, if WM_CLOSE
comes, I may decide not to close application. DefWindowProc
in this case calls DestroyWindow
.
My question is: should I call the DefWindowProc
or not? If so, always or only sometimes?