enum
AfxSig
{
AfxSig_end = 0 , // [marks end of message map]
AfxSig_vv,
} ;
#define ON_COMMAND(id, memberFxn) \
{ WM_COMMAND, 0 , (WORD)id, (WORD)id, AfxSig_vv, (AFX_PMSG)memberFxn } ,
{
AfxSig_end = 0 , // [marks end of message map]
AfxSig_vv,
} ;
#define ON_COMMAND(id, memberFxn) \
{ WM_COMMAND, 0 , (WORD)id, (WORD)id, AfxSig_vv, (AFX_PMSG)memberFxn } ,
1
#define
TRUE 1
2 #define FALSE 0
3
4 typedef char * LPSTR;
5 typedef const char * LPCSTR;
6
7 typedef unsigned long DWORD;
8 typedef int BOOL;
9 typedef unsigned char BYTE;
10 typedef unsigned short WORD;
11 typedef int INT;
12 typedef unsigned int UINT;
13 typedef long LONG;
14
15 typedef UINT WPARAM;
16 typedef LONG LPARAM;
17 typedef LONG LRESULT;
18 typedef int HWND;
19
20 #define WM_COMMAND 0x0111 // following windows.h
21 #define WM_CREATE 0x0001
22 #define WM_PAINT 0x000F
23 #define WM_NOTIFY 0x004E
24
25 #define CObjectid 0xffff
26 #define CCmdTargetid 1
27 #define CWinThreadid 11
28 #define CWinAppid 111
29 #define CMyWinAppid 1111
30 #define CWndid 12
31 #define CFrameWndid 121
32 #define CMyFrameWndid 1211
33 #define CViewid 122
34 #define CMyViewid 1221
35 #define CDocumentid 13
36 #define CMyDocid 131
37
38 #include < iostream.h >
39
40 /**/ ////////////////////////////////////////////////////////////////// //
41 // Window message map handling
42
43 struct AFX_MSGMAP_ENTRY;
44
45 struct AFX_MSGMAP
46 {
47 AFX_MSGMAP * pBaseMessageMap;
48 AFX_MSGMAP_ENTRY * lpEntries;
49 } ;
50
51 #define DECLARE_MESSAGE_MAP() \
52 static AFX_MSGMAP_ENTRY _messageEntries[]; \
53 static AFX_MSGMAP messageMap; \
54 virtual AFX_MSGMAP * GetMessageMap() const ;
55
56 #define BEGIN_MESSAGE_MAP(theClass, baseClass) \
57 AFX_MSGMAP * theClass::GetMessageMap() const \
58 { return & theClass::messageMap; } \
59 AFX_MSGMAP theClass::messageMap = \
60 { & (baseClass::messageMap), \
61 (AFX_MSGMAP_ENTRY * ) & (theClass::_messageEntries) } ; \
62 AFX_MSGMAP_ENTRY theClass::_messageEntries[] = \
63 {
64
65 #define END_MESSAGE_MAP() \
66 { 0 , 0 , 0 , 0 , AfxSig_end, (AFX_PMSG) 0 } \
67 } ;
68
69 // Message map signature values and macros in separate header
70 #include " afxmsg_.h "
71
72 class CObject
73 {
74 public :
75 CObject::CObject() {
76 }
77 CObject:: ~ CObject() {
78 }
79 } ;
80
81 class CCmdTarget : public CObject
82 {
83 public :
84 CCmdTarget::CCmdTarget() {
85 }
86 CCmdTarget:: ~ CCmdTarget() {
87 }
88
89 virtual BOOL OnCmdMsg(UINT nID, int nCode);
90
91 DECLARE_MESSAGE_MAP() // base class - no {{ }} macros
92 } ;
93
94 typedef void (CCmdTarget:: * AFX_PMSG)( void );
95
96 struct AFX_MSGMAP_ENTRY // MFC 4.0 format
97 {
98 UINT nMessage; // windows message
99 UINT nCode; // control code or WM_NOTIFY code
100 UINT nID; // control ID (or 0 for windows messages)
101 UINT nLastID; // used for entries specifying a range of control id's
102 UINT nSig; // signature type (action) or pointer to message #
103 AFX_PMSG pfn; // routine to call (or special value)
104 } ;
105
106 class CWinThread : public CCmdTarget
107 {
108 public :
109 CWinThread::CWinThread() {
110 }
111 CWinThread:: ~ CWinThread() {
112 }
113
114 virtual BOOL InitInstance() {
115 cout << " CWinThread::InitInstance \n " ;
116 return TRUE;
117 }
118 virtual int Run() {
119 cout << " CWinThread::Run \n " ;
120 // AfxWndProc();
121 return 1 ;
122 }
123 } ;
124
125 class CWnd;
126
127 class CWinApp : public CWinThread
128 {
129 public :
130 CWinApp * m_pCurrentWinApp;
131 CWnd * m_pMainWnd;
132
133 public :
134 CWinApp::CWinApp() {
135 m_pCurrentWinApp = this ;
136 }
137 CWinApp:: ~ CWinApp() {
138 }
139
140 virtual BOOL InitApplication() {
141 cout << " CWinApp::InitApplication \n " ;
142 return TRUE;
143 }
144 virtual BOOL InitInstance() {
145 cout << " CWinApp::InitInstance \n " ;
146 return TRUE;
147 }
148 virtual int Run() {
149 cout << " CWinApp::Run \n " ;
150 return CWinThread::Run();
151 }
152
153 DECLARE_MESSAGE_MAP()
154 } ;
155
156 typedef void (CWnd:: * AFX_PMSGW)( void );
157 // like 'AFX_PMSG' but for CWnd derived classes only
158
159 class CDocument : public CCmdTarget
160 {
161 public :
162 CDocument::CDocument() {
163 }
164 CDocument:: ~ CDocument() {
165 }
166
167 virtual BOOL OnCmdMsg(UINT nID, int nCode);
168
169 DECLARE_MESSAGE_MAP()
170 } ;
171
172 class CWnd : public CCmdTarget
173 {
174 public :
175 CWnd::CWnd() {
176 }
177 CWnd:: ~ CWnd() {
178 }
179
180 virtual BOOL Create();
181 BOOL CreateEx();
182 virtual BOOL PreCreateWindow();
183 virtual LRESULT WindowProc(UINT nMsg, WPARAM wParam, LPARAM lParam);
184 virtual LRESULT DefWindowProc(UINT message, WPARAM wParam, LPARAM lParam);
185 virtual BOOL OnCommand(WPARAM wParam, LPARAM lParam);
186
187 DECLARE_MESSAGE_MAP()
188 } ;
189
190 class CView;
191
192 class CFrameWnd : public CWnd
193 {
194 public :
195 CView * m_pViewActive; // current active view
196
197 public :
198 CFrameWnd::CFrameWnd() {
199 }
200 CFrameWnd:: ~ CFrameWnd() {
201 }
202 BOOL Create();
203 virtual BOOL PreCreateWindow();
204 CView * GetActiveView() const ;
205 virtual BOOL OnCommand(WPARAM wParam, LPARAM lParam);
206 virtual BOOL OnCmdMsg(UINT nID, int nCode);
207
208 DECLARE_MESSAGE_MAP()
209
210 friend CView;
211 } ;
212
213 class CView : public CWnd
214 {
215 public :
216 CDocument * m_pDocument;
217
218 public :
219 CView::CView() {
220 }
221 CView:: ~ CView() {
222 }
223
224 virtual BOOL OnCmdMsg(UINT nID, int nCode);
225
226 DECLARE_MESSAGE_MAP()
227
228 friend CFrameWnd;
229 } ;
230
231 // global function
232 CWinApp * AfxGetApp();
233 LRESULT AfxWndProc(HWND hWnd, UINT nMsg, WPARAM wParam, LPARAM lParam,
234 CWnd * pWnd); // last param. pWnd is added by JJHOU.
235 LRESULT AfxCallWndProc(CWnd * pWnd, HWND hWnd, UINT nMsg, WPARAM wParam,
236 LPARAM lParam);
237
2 #define FALSE 0
3
4 typedef char * LPSTR;
5 typedef const char * LPCSTR;
6
7 typedef unsigned long DWORD;
8 typedef int BOOL;
9 typedef unsigned char BYTE;
10 typedef unsigned short WORD;
11 typedef int INT;
12 typedef unsigned int UINT;
13 typedef long LONG;
14
15 typedef UINT WPARAM;
16 typedef LONG LPARAM;
17 typedef LONG LRESULT;
18 typedef int HWND;
19
20 #define WM_COMMAND 0x0111 // following windows.h
21 #define WM_CREATE 0x0001
22 #define WM_PAINT 0x000F
23 #define WM_NOTIFY 0x004E
24
25 #define CObjectid 0xffff
26 #define CCmdTargetid 1
27 #define CWinThreadid 11
28 #define CWinAppid 111
29 #define CMyWinAppid 1111
30 #define CWndid 12
31 #define CFrameWndid 121
32 #define CMyFrameWndid 1211
33 #define CViewid 122
34 #define CMyViewid 1221
35 #define CDocumentid 13
36 #define CMyDocid 131
37
38 #include < iostream.h >
39
40 /**/ ////////////////////////////////////////////////////////////////// //
41 // Window message map handling
42
43 struct AFX_MSGMAP_ENTRY;
44
45 struct AFX_MSGMAP
46 {
47 AFX_MSGMAP * pBaseMessageMap;
48 AFX_MSGMAP_ENTRY * lpEntries;
49 } ;
50
51 #define DECLARE_MESSAGE_MAP() \
52 static AFX_MSGMAP_ENTRY _messageEntries[]; \
53 static AFX_MSGMAP messageMap; \
54 virtual AFX_MSGMAP * GetMessageMap() const ;
55
56 #define BEGIN_MESSAGE_MAP(theClass, baseClass) \
57 AFX_MSGMAP * theClass::GetMessageMap() const \
58 { return & theClass::messageMap; } \
59 AFX_MSGMAP theClass::messageMap = \
60 { & (baseClass::messageMap), \
61 (AFX_MSGMAP_ENTRY * ) & (theClass::_messageEntries) } ; \
62 AFX_MSGMAP_ENTRY theClass::_messageEntries[] = \
63 {
64
65 #define END_MESSAGE_MAP() \
66 { 0 , 0 , 0 , 0 , AfxSig_end, (AFX_PMSG) 0 } \
67 } ;
68
69 // Message map signature values and macros in separate header
70 #include " afxmsg_.h "
71
72 class CObject
73 {
74 public :
75 CObject::CObject() {
76 }
77 CObject:: ~ CObject() {
78 }
79 } ;
80
81 class CCmdTarget : public CObject
82 {
83 public :
84 CCmdTarget::CCmdTarget() {
85 }
86 CCmdTarget:: ~ CCmdTarget() {
87 }
88
89 virtual BOOL OnCmdMsg(UINT nID, int nCode);
90
91 DECLARE_MESSAGE_MAP() // base class - no {{ }} macros
92 } ;
93
94 typedef void (CCmdTarget:: * AFX_PMSG)( void );
95
96 struct AFX_MSGMAP_ENTRY // MFC 4.0 format
97 {
98 UINT nMessage; // windows message
99 UINT nCode; // control code or WM_NOTIFY code
100 UINT nID; // control ID (or 0 for windows messages)
101 UINT nLastID; // used for entries specifying a range of control id's
102 UINT nSig; // signature type (action) or pointer to message #
103 AFX_PMSG pfn; // routine to call (or special value)
104 } ;
105
106 class CWinThread : public CCmdTarget
107 {
108 public :
109 CWinThread::CWinThread() {
110 }
111 CWinThread:: ~ CWinThread() {
112 }
113
114 virtual BOOL InitInstance() {
115 cout << " CWinThread::InitInstance \n " ;
116 return TRUE;
117 }
118 virtual int Run() {
119 cout << " CWinThread::Run \n " ;
120 // AfxWndProc();
121 return 1 ;
122 }
123 } ;
124
125 class CWnd;
126
127 class CWinApp : public CWinThread
128 {
129 public :
130 CWinApp * m_pCurrentWinApp;
131 CWnd * m_pMainWnd;
132
133 public :
134 CWinApp::CWinApp() {
135 m_pCurrentWinApp = this ;
136 }
137 CWinApp:: ~ CWinApp() {
138 }
139
140 virtual BOOL InitApplication() {
141 cout << " CWinApp::InitApplication \n " ;
142 return TRUE;
143 }
144 virtual BOOL InitInstance() {
145 cout << " CWinApp::InitInstance \n " ;
146 return TRUE;
147 }
148 virtual int Run() {
149 cout << " CWinApp::Run \n " ;
150 return CWinThread::Run();
151 }
152
153 DECLARE_MESSAGE_MAP()
154 } ;
155
156 typedef void (CWnd:: * AFX_PMSGW)( void );
157 // like 'AFX_PMSG' but for CWnd derived classes only
158
159 class CDocument : public CCmdTarget
160 {
161 public :
162 CDocument::CDocument() {
163 }
164 CDocument:: ~ CDocument() {
165 }
166
167 virtual BOOL OnCmdMsg(UINT nID, int nCode);
168
169 DECLARE_MESSAGE_MAP()
170 } ;
171
172 class CWnd : public CCmdTarget
173 {
174 public :
175 CWnd::CWnd() {
176 }
177 CWnd:: ~ CWnd() {
178 }
179
180 virtual BOOL Create();
181 BOOL CreateEx();
182 virtual BOOL PreCreateWindow();
183 virtual LRESULT WindowProc(UINT nMsg, WPARAM wParam, LPARAM lParam);
184 virtual LRESULT DefWindowProc(UINT message, WPARAM wParam, LPARAM lParam);
185 virtual BOOL OnCommand(WPARAM wParam, LPARAM lParam);
186
187 DECLARE_MESSAGE_MAP()
188 } ;
189
190 class CView;
191
192 class CFrameWnd : public CWnd
193 {
194 public :
195 CView * m_pViewActive; // current active view
196
197 public :
198 CFrameWnd::CFrameWnd() {
199 }
200 CFrameWnd:: ~ CFrameWnd() {
201 }
202 BOOL Create();
203 virtual BOOL PreCreateWindow();
204 CView * GetActiveView() const ;
205 virtual BOOL OnCommand(WPARAM wParam, LPARAM lParam);
206 virtual BOOL OnCmdMsg(UINT nID, int nCode);
207
208 DECLARE_MESSAGE_MAP()
209
210 friend CView;
211 } ;
212
213 class CView : public CWnd
214 {
215 public :
216 CDocument * m_pDocument;
217
218 public :
219 CView::CView() {
220 }
221 CView:: ~ CView() {
222 }
223
224 virtual BOOL OnCmdMsg(UINT nID, int nCode);
225
226 DECLARE_MESSAGE_MAP()
227
228 friend CFrameWnd;
229 } ;
230
231 // global function
232 CWinApp * AfxGetApp();
233 LRESULT AfxWndProc(HWND hWnd, UINT nMsg, WPARAM wParam, LPARAM lParam,
234 CWnd * pWnd); // last param. pWnd is added by JJHOU.
235 LRESULT AfxCallWndProc(CWnd * pWnd, HWND hWnd, UINT nMsg, WPARAM wParam,
236 LPARAM lParam);
237
1
#include
<
iostream.h
>
2 #include " mfc.h "
3
4 class CMyWinApp : public CWinApp
5 {
6 public :
7 CMyWinApp::CMyWinApp() {
8 }
9 CMyWinApp:: ~ CMyWinApp() {
10 }
11 virtual BOOL InitInstance();
12 DECLARE_MESSAGE_MAP()
13 } ;
14
15 class CMyFrameWnd : public CFrameWnd
16 {
17 public :
18 CMyFrameWnd();
19 ~ CMyFrameWnd() {
20 }
21 DECLARE_MESSAGE_MAP()
22 } ;
23
24 class CMyDoc : public CDocument
25 {
26 public :
27 CMyDoc::CMyDoc() {
28 }
29 CMyDoc:: ~ CMyDoc() {
30 }
31 DECLARE_MESSAGE_MAP()
32 } ;
33
34 class CMyView : public CView
35 {
36 public :
37 CMyView::CMyView() {
38 }
39 CMyView:: ~ CMyView() {
40 }
41 DECLARE_MESSAGE_MAP()
42 } ;
43
2 #include " mfc.h "
3
4 class CMyWinApp : public CWinApp
5 {
6 public :
7 CMyWinApp::CMyWinApp() {
8 }
9 CMyWinApp:: ~ CMyWinApp() {
10 }
11 virtual BOOL InitInstance();
12 DECLARE_MESSAGE_MAP()
13 } ;
14
15 class CMyFrameWnd : public CFrameWnd
16 {
17 public :
18 CMyFrameWnd();
19 ~ CMyFrameWnd() {
20 }
21 DECLARE_MESSAGE_MAP()
22 } ;
23
24 class CMyDoc : public CDocument
25 {
26 public :
27 CMyDoc::CMyDoc() {
28 }
29 CMyDoc:: ~ CMyDoc() {
30 }
31 DECLARE_MESSAGE_MAP()
32 } ;
33
34 class CMyView : public CView
35 {
36 public :
37 CMyView::CMyView() {
38 }
39 CMyView:: ~ CMyView() {
40 }
41 DECLARE_MESSAGE_MAP()
42 } ;
43
1
#include
"
my.h
"
//
赣 mfc.h 碞 extern CMyWinApp ┮
2
3 extern CMyWinApp theApp;
4 extern void printlpEntries(AFX_MSGMAP_ENTRY * lpEntry);
5
6 BOOL CCmdTarget::OnCmdMsg(UINT nID, int nCode)
7 {
8 cout << " CCmdTarget::OnCmdMsg() " << endl;
9 // Now look through message map to see if it applies to us
10 AFX_MSGMAP * pMessageMap;
11 AFX_MSGMAP_ENTRY * lpEntry;
12 for (pMessageMap = GetMessageMap(); pMessageMap != NULL;
13 pMessageMap = pMessageMap -> pBaseMessageMap)
14 {
15 lpEntry = pMessageMap -> lpEntries;
16 printlpEntries(lpEntry);
17 }
18
19 return FALSE; // not handled
20 }
21
22 BOOL CWnd::Create()
23 {
24 cout << " CWnd::Create \n " ;
25 return TRUE;
26 }
27
28 BOOL CWnd::CreateEx()
29 {
30 cout << " CWnd::CreateEx \n " ;
31 PreCreateWindow();
32 return TRUE;
33 }
34
35 BOOL CWnd::PreCreateWindow()
36 {
37 cout << " CWnd::PreCreateWindow \n " ;
38 return TRUE;
39 }
40
41 LRESULT CWnd::WindowProc(UINT nMsg, WPARAM wParam, LPARAM lParam)
42 {
43 AFX_MSGMAP * pMessageMap;
44 AFX_MSGMAP_ENTRY * lpEntry;
45
46 cout << " CWnd::WindowProc() " << endl;
47 if (nMsg == WM_COMMAND) // special case for commands
48 {
49 if (OnCommand(wParam, lParam))
50 return 1L ; // command handled
51 else
52 return (LRESULT)DefWindowProc(nMsg, wParam, lParam);
53 }
54
55 pMessageMap = GetMessageMap();
56
57 for (; pMessageMap != NULL;
58 pMessageMap = pMessageMap -> pBaseMessageMap)
59 {
60 lpEntry = pMessageMap -> lpEntries;
61 printlpEntries(lpEntry);
62 }
63 return 0 ; // J.J.Hou: if find, should call lpEntry->pfn,
64 // otherwise should call DefWindowProc.
65 // for simplization we just return 0.
66 }
67
68 LRESULT CWnd::DefWindowProc(UINT message, WPARAM wParam, LPARAM lParam)
69 {
70 cout << " CWnd::DefWindowProc() " << endl;
71 return TRUE;
72 }
73
74 BOOL CWnd::OnCommand(WPARAM wParam, LPARAM lParam)
75 {
76 cout << " CWnd::OnCommand() " << endl;
77 //
78 return OnCmdMsg( 0 , 0 );
79 }
80
81 BOOL CFrameWnd::OnCommand(WPARAM wParam, LPARAM lParam)
82 {
83 cout << " CFrameWnd::OnCommand() " << endl;
84 //
85 // route as normal command
86 return CWnd::OnCommand(wParam, lParam);
87 }
88
89 BOOL CFrameWnd::Create()
90 {
91 cout << " CFrameWnd::Create \n " ;
92 CreateEx();
93 return TRUE;
94 }
95
96 BOOL CFrameWnd::PreCreateWindow()
97 {
98 cout << " CFrameWnd::PreCreateWindow \n " ;
99 return TRUE;
100 }
101
102 CView * CFrameWnd::GetActiveView() const
103 {
104 cout << " CFrameWnd::GetActiveView() " << endl;
105 return m_pViewActive;
106 }
107
108 BOOL CFrameWnd::OnCmdMsg(UINT nID, int nCode)
109 {
110 cout << " CFrameWnd::OnCmdMsg() " << endl;
111 // pump through current view FIRST
112 CView * pView = GetActiveView();
113 if (pView -> OnCmdMsg(nID, nCode))
114 return TRUE;
115
116 // then pump through frame
117 if (CWnd::OnCmdMsg(nID, nCode))
118 return TRUE;
119
120 // last but not least, pump through app
121 CWinApp * pApp = AfxGetApp();
122 if (pApp -> OnCmdMsg(nID, nCode))
123 return TRUE;
124
125 return FALSE;
126 }
127
128 BOOL CDocument::OnCmdMsg(UINT nID, int nCode)
129 {
130 cout << " CDocument::OnCmdMsg() " << endl;
131 if (CCmdTarget::OnCmdMsg(nID, nCode))
132 return TRUE;
133
134 return FALSE;
135 }
136
137 BOOL CView::OnCmdMsg(UINT nID, int nCode)
138 {
139 cout << " CView::OnCmdMsg() " << endl;
140 if (CWnd::OnCmdMsg(nID, nCode))
141 return TRUE;
142
143 BOOL bHandled = FALSE;
144 bHandled = m_pDocument -> OnCmdMsg(nID, nCode);
145 return bHandled;
146 }
147
148 AFX_MSGMAP * CCmdTarget::GetMessageMap() const // JJHou: in MFC 40 cmdtarg.cpp
149 {
150 return & CCmdTarget::messageMap;
151 }
152
153 AFX_MSGMAP CCmdTarget::messageMap = // JJHou: in in MFC 40 cmdtarg.cpp
154 {
155 NULL,
156 & CCmdTarget::_messageEntries[ 0 ]
157 } ;
158
159 AFX_MSGMAP_ENTRY CCmdTarget::_messageEntries[] = // JJHou: in in MFC 40 cmdtarg.cpp
160 {
161 { 0 , 0 , CCmdTargetid, 0 , AfxSig_end, 0 } // nothing here
162 } ;
163
164 BEGIN_MESSAGE_MAP(CWnd, CCmdTarget)
165 ON_COMMAND(CWndid, 0 )
166 END_MESSAGE_MAP()
167
168 BEGIN_MESSAGE_MAP(CFrameWnd, CWnd)
169 ON_COMMAND(CFrameWndid, 0 )
170 END_MESSAGE_MAP()
171
172 BEGIN_MESSAGE_MAP(CDocument, CCmdTarget)
173 ON_COMMAND(CDocumentid, 0 )
174 END_MESSAGE_MAP()
175
176 BEGIN_MESSAGE_MAP(CView, CWnd)
177 ON_COMMAND(CViewid, 0 )
178 END_MESSAGE_MAP()
179
180 BEGIN_MESSAGE_MAP(CWinApp, CCmdTarget)
181 ON_COMMAND(CWinAppid, 0 )
182 END_MESSAGE_MAP()
183
184 CWinApp * AfxGetApp()
185 {
186 return theApp.m_pCurrentWinApp;
187 }
188
189 LRESULT AfxWndProc(HWND hWnd, UINT nMsg, WPARAM wParam, LPARAM lParam,
190 CWnd * pWnd) // last param. pWnd is added by JJHou.
191 {
192 cout << " AfxWndProc() " << endl;
193 return AfxCallWndProc(pWnd, hWnd, nMsg, wParam, lParam);
194 }
195
196 LRESULT AfxCallWndProc(CWnd * pWnd, HWND hWnd, UINT nMsg,
197 WPARAM wParam, LPARAM lParam)
198 {
199 cout << " AfxCallWndProc() " << endl;
200 LRESULT lResult = pWnd -> WindowProc(nMsg, wParam, lParam);
201 return lResult;
202 }
203
2
3 extern CMyWinApp theApp;
4 extern void printlpEntries(AFX_MSGMAP_ENTRY * lpEntry);
5
6 BOOL CCmdTarget::OnCmdMsg(UINT nID, int nCode)
7 {
8 cout << " CCmdTarget::OnCmdMsg() " << endl;
9 // Now look through message map to see if it applies to us
10 AFX_MSGMAP * pMessageMap;
11 AFX_MSGMAP_ENTRY * lpEntry;
12 for (pMessageMap = GetMessageMap(); pMessageMap != NULL;
13 pMessageMap = pMessageMap -> pBaseMessageMap)
14 {
15 lpEntry = pMessageMap -> lpEntries;
16 printlpEntries(lpEntry);
17 }
18
19 return FALSE; // not handled
20 }
21
22 BOOL CWnd::Create()
23 {
24 cout << " CWnd::Create \n " ;
25 return TRUE;
26 }
27
28 BOOL CWnd::CreateEx()
29 {
30 cout << " CWnd::CreateEx \n " ;
31 PreCreateWindow();
32 return TRUE;
33 }
34
35 BOOL CWnd::PreCreateWindow()
36 {
37 cout << " CWnd::PreCreateWindow \n " ;
38 return TRUE;
39 }
40
41 LRESULT CWnd::WindowProc(UINT nMsg, WPARAM wParam, LPARAM lParam)
42 {
43 AFX_MSGMAP * pMessageMap;
44 AFX_MSGMAP_ENTRY * lpEntry;
45
46 cout << " CWnd::WindowProc() " << endl;
47 if (nMsg == WM_COMMAND) // special case for commands
48 {
49 if (OnCommand(wParam, lParam))
50 return 1L ; // command handled
51 else
52 return (LRESULT)DefWindowProc(nMsg, wParam, lParam);
53 }
54
55 pMessageMap = GetMessageMap();
56
57 for (; pMessageMap != NULL;
58 pMessageMap = pMessageMap -> pBaseMessageMap)
59 {
60 lpEntry = pMessageMap -> lpEntries;
61 printlpEntries(lpEntry);
62 }
63 return 0 ; // J.J.Hou: if find, should call lpEntry->pfn,
64 // otherwise should call DefWindowProc.
65 // for simplization we just return 0.
66 }
67
68 LRESULT CWnd::DefWindowProc(UINT message, WPARAM wParam, LPARAM lParam)
69 {
70 cout << " CWnd::DefWindowProc() " << endl;
71 return TRUE;
72 }
73
74 BOOL CWnd::OnCommand(WPARAM wParam, LPARAM lParam)
75 {
76 cout << " CWnd::OnCommand() " << endl;
77 //
78 return OnCmdMsg( 0 , 0 );
79 }
80
81 BOOL CFrameWnd::OnCommand(WPARAM wParam, LPARAM lParam)
82 {
83 cout << " CFrameWnd::OnCommand() " << endl;
84 //
85 // route as normal command
86 return CWnd::OnCommand(wParam, lParam);
87 }
88
89 BOOL CFrameWnd::Create()
90 {
91 cout << " CFrameWnd::Create \n " ;
92 CreateEx();
93 return TRUE;
94 }
95
96 BOOL CFrameWnd::PreCreateWindow()
97 {
98 cout << " CFrameWnd::PreCreateWindow \n " ;
99 return TRUE;
100 }
101
102 CView * CFrameWnd::GetActiveView() const
103 {
104 cout << " CFrameWnd::GetActiveView() " << endl;
105 return m_pViewActive;
106 }
107
108 BOOL CFrameWnd::OnCmdMsg(UINT nID, int nCode)
109 {
110 cout << " CFrameWnd::OnCmdMsg() " << endl;
111 // pump through current view FIRST
112 CView * pView = GetActiveView();
113 if (pView -> OnCmdMsg(nID, nCode))
114 return TRUE;
115
116 // then pump through frame
117 if (CWnd::OnCmdMsg(nID, nCode))
118 return TRUE;
119
120 // last but not least, pump through app
121 CWinApp * pApp = AfxGetApp();
122 if (pApp -> OnCmdMsg(nID, nCode))
123 return TRUE;
124
125 return FALSE;
126 }
127
128 BOOL CDocument::OnCmdMsg(UINT nID, int nCode)
129 {
130 cout << " CDocument::OnCmdMsg() " << endl;
131 if (CCmdTarget::OnCmdMsg(nID, nCode))
132 return TRUE;
133
134 return FALSE;
135 }
136
137 BOOL CView::OnCmdMsg(UINT nID, int nCode)
138 {
139 cout << " CView::OnCmdMsg() " << endl;
140 if (CWnd::OnCmdMsg(nID, nCode))
141 return TRUE;
142
143 BOOL bHandled = FALSE;
144 bHandled = m_pDocument -> OnCmdMsg(nID, nCode);
145 return bHandled;
146 }
147
148 AFX_MSGMAP * CCmdTarget::GetMessageMap() const // JJHou: in MFC 40 cmdtarg.cpp
149 {
150 return & CCmdTarget::messageMap;
151 }
152
153 AFX_MSGMAP CCmdTarget::messageMap = // JJHou: in in MFC 40 cmdtarg.cpp
154 {
155 NULL,
156 & CCmdTarget::_messageEntries[ 0 ]
157 } ;
158
159 AFX_MSGMAP_ENTRY CCmdTarget::_messageEntries[] = // JJHou: in in MFC 40 cmdtarg.cpp
160 {
161 { 0 , 0 , CCmdTargetid, 0 , AfxSig_end, 0 } // nothing here
162 } ;
163
164 BEGIN_MESSAGE_MAP(CWnd, CCmdTarget)
165 ON_COMMAND(CWndid, 0 )
166 END_MESSAGE_MAP()
167
168 BEGIN_MESSAGE_MAP(CFrameWnd, CWnd)
169 ON_COMMAND(CFrameWndid, 0 )
170 END_MESSAGE_MAP()
171
172 BEGIN_MESSAGE_MAP(CDocument, CCmdTarget)
173 ON_COMMAND(CDocumentid, 0 )
174 END_MESSAGE_MAP()
175
176 BEGIN_MESSAGE_MAP(CView, CWnd)
177 ON_COMMAND(CViewid, 0 )
178 END_MESSAGE_MAP()
179
180 BEGIN_MESSAGE_MAP(CWinApp, CCmdTarget)
181 ON_COMMAND(CWinAppid, 0 )
182 END_MESSAGE_MAP()
183
184 CWinApp * AfxGetApp()
185 {
186 return theApp.m_pCurrentWinApp;
187 }
188
189 LRESULT AfxWndProc(HWND hWnd, UINT nMsg, WPARAM wParam, LPARAM lParam,
190 CWnd * pWnd) // last param. pWnd is added by JJHou.
191 {
192 cout << " AfxWndProc() " << endl;
193 return AfxCallWndProc(pWnd, hWnd, nMsg, wParam, lParam);
194 }
195
196 LRESULT AfxCallWndProc(CWnd * pWnd, HWND hWnd, UINT nMsg,
197 WPARAM wParam, LPARAM lParam)
198 {
199 cout << " AfxCallWndProc() " << endl;
200 LRESULT lResult = pWnd -> WindowProc(nMsg, wParam, lParam);
201 return lResult;
202 }
203
1
#include
"
my.h
"
2
3 CMyWinApp theApp; // global object
4
5 BOOL CMyWinApp::InitInstance()
6 {
7 cout << " CMyWinApp::InitInstance \n " ;
8 m_pMainWnd = new CMyFrameWnd;
9 return TRUE;
10 }
11
12 CMyFrameWnd::CMyFrameWnd()
13 {
14 Create();
15 }
16
17 BEGIN_MESSAGE_MAP(CMyWinApp, CWinApp)
18 ON_COMMAND(CMyWinAppid, 0 )
19 END_MESSAGE_MAP()
20
21 BEGIN_MESSAGE_MAP(CMyFrameWnd, CFrameWnd)
22 ON_COMMAND(CMyFrameWndid, 0 )
23 END_MESSAGE_MAP()
24
25 BEGIN_MESSAGE_MAP(CMyDoc, CDocument)
26 ON_COMMAND(CMyDocid, 0 )
27 END_MESSAGE_MAP()
28
29 BEGIN_MESSAGE_MAP(CMyView, CView)
30 ON_COMMAND(CMyViewid, 0 )
31 END_MESSAGE_MAP()
32
33 void printlpEntries(AFX_MSGMAP_ENTRY * lpEntry)
34 {
35 struct {
36 int classid;
37 char * classname;
38 } classinfo[] = {
39 CCmdTargetid , " CCmdTarget " ,
40 CWinThreadid , " CWinThread " ,
41 CWinAppid , " CWinApp " ,
42 CMyWinAppid , " CMyWinApp " ,
43 CWndid , " CWnd " ,
44 CFrameWndid , " CFrameWnd " ,
45 CMyFrameWndid, " CMyFrameWnd " ,
46 CViewid , " CView " ,
47 CMyViewid , " CMyView " ,
48 CDocumentid , " CDocument " ,
49 CMyDocid , " CMyDoc " ,
50 0 , " "
51 } ;
52
53 for ( int i = 0 ; classinfo[i].classid != 0 ; i ++ )
54 {
55 if (classinfo[i].classid == lpEntry -> nID)
56 {
57 cout << lpEntry -> nID << " " ;
58 cout << classinfo[i].classname << endl;
59 break ;
60 }
61 }
62 }
63 // ------------------------------------------------------------------
64 // main
65 // ------------------------------------------------------------------
66 void main()
67 {
68 CWinApp * pApp = AfxGetApp();
69
70 pApp -> InitApplication();
71 pApp -> InitInstance();
72 pApp -> Run();
73
74 CMyDoc * pMyDoc = new CMyDoc;
75 CMyView * pMyView = new CMyView;
76 CFrameWnd * pMyFrame = (CFrameWnd * )pApp -> m_pMainWnd;
77 pMyFrame -> m_pViewActive = pMyView;
78 pMyView -> m_pDocument = pMyDoc;
79
80 // test Message Routing
81 cout << endl << " pMyFrame receive WM_CREATE, " ;
82 cout << " routing path and call stack: " << endl;
83 AfxWndProc( 0 , WM_CREATE, 0 , 0 , pMyFrame);
84
85 cout << endl << " pMyView receive WM_PAINT, " ;
86 cout << " routing path and call stack: " << endl;
87 AfxWndProc( 0 , WM_PAINT, 0 , 0 , pMyView);
88
89 cout << endl << " pMyView receive WM_COMMAND, " ;
90 cout << " routing path and call stack: " << endl;
91 AfxWndProc( 0 , WM_COMMAND, 0 , 0 , pMyView);
92
93 cout << endl << " pMyFrame receive WM_COMMAND, " ;
94 cout << " routing path and call stack: " << endl;
95 AfxWndProc( 0 , WM_COMMAND, 0 , 0 , pMyFrame);
96 }
97
2
3 CMyWinApp theApp; // global object
4
5 BOOL CMyWinApp::InitInstance()
6 {
7 cout << " CMyWinApp::InitInstance \n " ;
8 m_pMainWnd = new CMyFrameWnd;
9 return TRUE;
10 }
11
12 CMyFrameWnd::CMyFrameWnd()
13 {
14 Create();
15 }
16
17 BEGIN_MESSAGE_MAP(CMyWinApp, CWinApp)
18 ON_COMMAND(CMyWinAppid, 0 )
19 END_MESSAGE_MAP()
20
21 BEGIN_MESSAGE_MAP(CMyFrameWnd, CFrameWnd)
22 ON_COMMAND(CMyFrameWndid, 0 )
23 END_MESSAGE_MAP()
24
25 BEGIN_MESSAGE_MAP(CMyDoc, CDocument)
26 ON_COMMAND(CMyDocid, 0 )
27 END_MESSAGE_MAP()
28
29 BEGIN_MESSAGE_MAP(CMyView, CView)
30 ON_COMMAND(CMyViewid, 0 )
31 END_MESSAGE_MAP()
32
33 void printlpEntries(AFX_MSGMAP_ENTRY * lpEntry)
34 {
35 struct {
36 int classid;
37 char * classname;
38 } classinfo[] = {
39 CCmdTargetid , " CCmdTarget " ,
40 CWinThreadid , " CWinThread " ,
41 CWinAppid , " CWinApp " ,
42 CMyWinAppid , " CMyWinApp " ,
43 CWndid , " CWnd " ,
44 CFrameWndid , " CFrameWnd " ,
45 CMyFrameWndid, " CMyFrameWnd " ,
46 CViewid , " CView " ,
47 CMyViewid , " CMyView " ,
48 CDocumentid , " CDocument " ,
49 CMyDocid , " CMyDoc " ,
50 0 , " "
51 } ;
52
53 for ( int i = 0 ; classinfo[i].classid != 0 ; i ++ )
54 {
55 if (classinfo[i].classid == lpEntry -> nID)
56 {
57 cout << lpEntry -> nID << " " ;
58 cout << classinfo[i].classname << endl;
59 break ;
60 }
61 }
62 }
63 // ------------------------------------------------------------------
64 // main
65 // ------------------------------------------------------------------
66 void main()
67 {
68 CWinApp * pApp = AfxGetApp();
69
70 pApp -> InitApplication();
71 pApp -> InitInstance();
72 pApp -> Run();
73
74 CMyDoc * pMyDoc = new CMyDoc;
75 CMyView * pMyView = new CMyView;
76 CFrameWnd * pMyFrame = (CFrameWnd * )pApp -> m_pMainWnd;
77 pMyFrame -> m_pViewActive = pMyView;
78 pMyView -> m_pDocument = pMyDoc;
79
80 // test Message Routing
81 cout << endl << " pMyFrame receive WM_CREATE, " ;
82 cout << " routing path and call stack: " << endl;
83 AfxWndProc( 0 , WM_CREATE, 0 , 0 , pMyFrame);
84
85 cout << endl << " pMyView receive WM_PAINT, " ;
86 cout << " routing path and call stack: " << endl;
87 AfxWndProc( 0 , WM_PAINT, 0 , 0 , pMyView);
88
89 cout << endl << " pMyView receive WM_COMMAND, " ;
90 cout << " routing path and call stack: " << endl;
91 AfxWndProc( 0 , WM_COMMAND, 0 , 0 , pMyView);
92
93 cout << endl << " pMyFrame receive WM_COMMAND, " ;
94 cout << " routing path and call stack: " << endl;
95 AfxWndProc( 0 , WM_COMMAND, 0 , 0 , pMyFrame);
96 }
97