BEGIN_MESSAGE_MAP
Posted on 2010-08-06 09:02 幻海藍(lán)夢(mèng) 閱讀(1449) 評(píng)論(0) 編輯 收藏 所屬分類(lèi): C++原文:http://www.cppblog.com/momoxiao/archive/2009/10/22/99206.html
BEGIN_MESSAGE_MAP()

2

3

這些都是宏定義,不是函數(shù)。
在BEGIN_MESSAGE_MAP()和END_MESSAGE_MAP()之間添加你的消息響應(yīng)函數(shù),為每個(gè)消息處理函數(shù)加入一個(gè)入口
BEGIN_MESSAGE_MAP( theClass, baseClass )
參數(shù):
theClass | 指定消息映射所屬的類(lèi)的名字。 |
baseClass | 指定theClass的基類(lèi)的名字。 |
說(shuō)明:
使用BEGIN_MESSAGE_MAP宏開(kāi)始你的消息映射的定義。
在你的類(lèi)的成員函數(shù)的實(shí)現(xiàn)文件(.CPP)中,使用BEGIN_MESSAGE_MAP宏開(kāi)始消息映射,然后為每個(gè)消息處理函數(shù)加入一個(gè)入口,最后用END_MESSAGE_MAP宏結(jié)束消息映射。
每個(gè)消息映射入口的格式如下:
ON_Notification(id, memberFxn)
其中id指定了發(fā)送通知的控件的子窗口的ID,而memberFxn指定了處理該通知的父對(duì)象中的成員函數(shù)名。
父對(duì)象的函數(shù)原型格式如下:
afx_msg void memberFxn( );
可能的消息映射入口如下:
映射入口 | 何時(shí)向父對(duì)象發(fā)送消息 |
ON_BN_CLICKED | 用戶(hù)單擊按鈕時(shí) |
ON_BN_DOUBLECLICKED | 用戶(hù)雙擊按鈕時(shí) |
例如:

2

3

4

5

6

7

8

void CTestDlg::OnSysCommand(UINT nID, LPARAM lParam)
這個(gè)函數(shù)響應(yīng)系統(tǒng)控制菜單的命令.(即左上角圖標(biāo)處)。
OnSysCommand:The framework calls this member function when the user selects a command from the Control menu, or when the user selects the Maximize or the Minimize button.
另外:
DoDataExchange:當(dāng)UpdateData時(shí)候
OnInitDialog:對(duì)話(huà)框類(lèi)已經(jīng)構(gòu)造,但是對(duì)話(huà)框還沒(méi)有顯示出來(lái)的時(shí)候
OnQueryDragIcon:The framework calls this member function by a minimized (iconic) window that does not have an icon defined for its class. The system makes this call to obtain the cursor to display while the user drags the minimized window.