Reputation: 1198
This is an theory question released to control messages in win32 api.
What is the difference between WM_COMMAND
and WM_NOTIFY
?
When do we need to handle these messages and when do we choose to ignore them?.
This doubt arises because both these messages are sent when the user interacts with an control and both send the same information to the window procedure that is event type,control I'd and control handle either as an structure
(LPNMHDR in case of WM_NOTIFY
) or directly (LPARAM handle to control and LOWORD (WPARAM) in case of WM_COMMAND
)
With all these similarities why do we still use both together and not just depracate one ?
Upvotes: 3
Views: 2266
Reputation: 15162
We use both due to reasons of backwards compatibility. New controls tend to use WM_NOTIFY (it is far more capable), but there are existing controls that send WM_COMMAND and MS is not going to change that.
I say that WM_NOTIFY is more capable because of its lParam being an NMHDR *, which if the NMHDR is the first member of a POD type (or standard layout in modern C++ terms) then you can cast the lParam to the actual type the control sent. All WM_COMMAND can provide is a command code and window handle.
As for when to handle them that is strictly a matter of need, if you need to deal with a particular action on part of a particular control then you handle the message, if not then you don't.
Upvotes: 10