life ideas

January 7, 2007

wm_command vs wm_notify.

Filed under: Uncategorized — manoftoday @ 8:40 am

http://msdn2.microsoft.com/en-us/library/749htf6k(VS.80).aspx

http://www.yesky.com/217/1715717.shtml

This technical note provides background information on the new WM_NOTIFY message and
describes the recommended (and most common) way of handling WM_NOTIFY messages in
your MFC application.

Notification Messages in Windows 3.x

0) WM_COMMAND
lParam= NULL,  LOWORD(wParam)  is control ID.  for  instance menu

for toolbar
We just need to assign each button an ID (ID_FILE_NEW etc…) which is identical
to the IDs of the equivalent menu items. These buttons will generate WM_COMMAND
messages identical to the menu, so no extra processing is required! If we were
adding a button for a command that didn’t already have a menu item, we would
simply pick a new ID for it and add a handler to WM_COMMAND.

1)notified WM_COMMAND
lParam= hWnd, LOWORD(wParam)  is control ID.  HIWORD(wParam)  is message id (for
example, BN_CLICKED)

In Windows 3.x, controls notify their parents of events such as mouse clicks,
changes in content and selection, and control background painting by sending a
message to the parent. Simple notifications are sent as special WM_COMMAND messages,
with the notification code (such as BN_CLICKED) and control ID packed into wParam and
the control’s handle in lParam. Note that since wParam and lParam are full, there is
no way to pass any additional data — these messages can be only simple notification.
For instance, in the BN_CLICKED notification, there’s no way to send information about
the location of the mouse cursor when the button was clicked.

2)list of limited messages
When controls in Windows 3.x need to send a notification message that includes
additional data, they use a variety of special-purpose messages, including:
A) tell parent it is created/destroyed or clicked by mouse :WM_PARENTNOTIFY;
B) notify parent how to draw  itself:
WM_CTLCOLOR,WM_DRAWITEM, WM_MEASUREITEM,WM_DELETEITEM,WM_CHARTOITEM,WM_VKTOITEM,
WM_COMPAREITEM;
C) about scroll status: WM_VSCROLL, WM_HSCROLL.

3)WM_NOTIFY

However, Win32 also adds a number of sophisticated, complex controls to those supported in Windows 3.x. Frequently,
these controls need to send additional data with their notification messages.
Rather than adding a new WM_* message for each new notification that needs additional
data, the designers of the Win32 API chose to add just one message, WM_NOTIFY, which
can pass any amount of additional data in a standardized fashion.

WM_NOTIFY messages contain the ID of the control sending the message in wParam and a
pointer to a structure in lParam. This structure is either an NMHDR structure or some
larger structure that has an NMHDR structure as its first member. Note that since the
NMHDR member is first, a pointer to this structure can be used as either a pointer to
an NMHDR or as a pointer to the larger structure depending on how you cast it.

In most cases, the pointer will point to a larger structure and you’ll need to cast it
when you use it. In only a few notifications, such as the common notifications (whose
names start with NM_. list: NM_CLICK,NM_DBLCLK,NM_RCLICK,NM_RDBLCLK,NM_RETURN,NM_SETFOCUS,
NM_KILLFOCUS, NM_OUTOFMEMORY) and the tool tip control’s TTN_SHOW and TTN_POP notifications,
is an NMHDR structure actually used.

typedef struct tagNMHDR {
HWND hwndFrom;
UINT idFrom;
UINT code;
} NMHDR;

or

typedef struct tagLV_KEYDOWN {
NMHDR hdr;
WORD wVKey;
UINT flags;
} LV_KEYDOWN;
since the NMHDR member is first in this structure, the pointer you’re
passed in the notification message can be cast to either a pointer to an
NMHDR or a pointer to an LV_KEYDOWN.

Reflected Messages – MFC 4.0+   this is specific for MFC applications.(Note that
since message reflection is implemented by MFC, not by Windows, the parent
window class must be derived from CWnd for message reflection to work.)

What Is Message Reflection?

Windows controls frequently send notification messages to their parent windows.
For instance, many controls send a control color notification message (WM_CTLCOLOR
or one of its variants) to their parent to allow the parent to supply a brush for
painting the background of the control.

In Windows and in MFC before version 4.0, the parent window, often a dialog box,
is responsible for handling these messages. This means that the code for handling
the message needs to be in the parent window’s class and that it has to be duplicated
in every class that needs to handle that message. In the case above, every dialog box
that wanted controls with custom backgrounds would have to handle the control color
notification message. It would be much easier to reuse code if a control class could
be written that would handle its own background color.

When a WM_NOTIFY message is sent, the control is offered the first chance to handle
it. If any other reflected message is sent, the parent window has the first chance
to handle it and the control will receive the reflected message. To do so, it will
need a handler function and an appropriate entry in the control’s class message map.

The message-map macro for reflected messages is slightly different than for regular
notifications: it has _REFLECT appended to its usual name. For instance, to handle
a WM_NOTIFY message in the parent, you use the macro ON_NOTIFY in the parent’s message
map. To handle the reflected message in the child control, use the ON_NOTIFY_REFLECT
macro in the child control’s message map.

* normally, To convert from the message name to the reflected macro name, prepend
ON_ and append _REFLECT.For example, WM_CTLCOLOR becomes ON_WM_CTLCOLOR_REFLECT.
for the list:
ON_WM_CTLCOLOR_REFLECT( )
ON_WM_DRAWITEM_REFLECT( )
ON_WM_MEASUREITEM_REFLECT( )
ON_WM_DELETEITEM_REFLECT( )
ON_WM_COMPAREITEM_REFLECT( )
ON_WM_CHARTOITEM_REFLECT( )
ON_WM_VKEYTOITEM_REFLECT( )
ON_WM_HSCROLL_REFLECT( )
ON_WM_VSCROLL_REFLECT( )
ON_WM_PARENTNOTIFY_REFLECT( )

The three exceptions to the rule above are as follows:

* The macro for WM_COMMAND notifications is ON_CONTROL_REFLECT.
* The macro for WM_NOTIFY reflections is ON_NOTIFY_REFLECT.
* The macro for ON_UPDATE_COMMAND_UI reflections is ON_UPDATE_COMMAND_UI_REFLECT.

http://msdn2.microsoft.com/en-us/library/eeah46xd(VS.80).aspx

Advertisements

3 Comments »

  1. Is it possible to reflect the mouse messages like LBUTTONDOWN ?

    If yes then please tell me.

    If there is an example following it will be highly appreciated.

    Thanks.

    Comment by kishor bagul — January 4, 2008 @ 11:40 am

  2. похудение с помощью лунного календарякак правильно использовать пояс для похудения талииправильное питание в 16 летпохудение лида акция 3 4как можно похудеть с 54 размера на 48диетпитание меню раскладка программадиетическое питание для котадиетическое питание профессора в ф богоявленскогорецепты диет 1а б где посмотретьможно ли кушать фасоль находясь на диетедиетические продукты статистикаэфирное масло мяты длля похудениядиета не едим после 18.00ален карр. легкий способ похудетькак я худела на диете протасоваклиники для снижения веса в городе воронежеуменьшение концентрации липидов в крови с помощью диетыкак похудеть с помошью медаантицеллюлитный крем при беременностифотографии до и после диеты

    Comment by avensuts — July 31, 2011 @ 9:53 am

  3. Hey very cool site!! Guy .. Beautiful .. Wonderful .. I’ll bookmark your blog and take the feeds also?I’m satisfied to find a lot of useful information right here within the publish, we need work out extra techniques on this regard, thank you for sharing. . . . . .

    Comment by эффективные рецепты диеты — January 29, 2012 @ 6:00 pm


RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Blog at WordPress.com.

%d bloggers like this: