ON_NOTIFY用法

来源:互联网 发布:淘宝怎么看自己退款率 编辑:程序博客网 时间:2024/06/10 08:54

摘自:http://msdn.microsoft.com/zh-cn/library/749htf6k(v=VS.100).aspx

 

ON_NOTIFY: Handling WM_NOTIFY Messages in MFC Applications


The function CWnd::OnNotify handles notification messages. Its default implementation checks the message map for notification handlers to call. In general, you do not override OnNotify. Instead, you provide a handler function and add a message-map entry for that handler to the message map of your owner window's class.

ClassWizard, via the ClassWizard property sheet, can create the ON_NOTIFY message-map entry and provide you with a skeleton handler function. For more information on using ClassWizard to make this easier, see Mapping Messages to Functions.

The ON_NOTIFY message-map macro has the following syntax:


where the italicized parameters are replaced with:

wNotifyCode

The code for the notification message to be handled, such as LVN_KEYDOWN.

id

The child identifier of the control for which the notification is sent.

memberFxn

The member function to be called when this notification is sent.

Your member function must be declared with the following prototype:

 
 
备注

where the italicized parameters are:

pNotifyStruct

A pointer to the notification structure, as described in the section above.

result

A pointer to the result code you'll set before you return.

示例

To specify that you want the member function OnKeydownList1 to handle LVN_KEYDOWN messages from the CListCtrl whose ID is IDC_LIST1, you would use ClassWizard to add the following to your message map:

复制
 

In the example above, the function provided by ClassWizard is:

 

Note that ClassWizard provides a pointer of the proper type automatically. You can access the notification structure through either pNMHDR or pLVKeyDow.

原创粉丝点击