MFC
MFC -Message Map Functions When the user presses the left mouse button in a view window, Windows sends a message—specifically WM_LBUTTONDOWN—to that window.If your program needs to take action in response to WM_LBUTTONDOWN, your view class must have a member function that looks like this:
void CMyView::OnLButtonDown(UINT nFlags, CPoint point) {
// event processing code here
}
Your class header file must also have the corresponding prototype:
afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
The afx_msg notation is a "no-op" that alerts you that this is a prototype for a message map function.
Next, your code file needs a message map macro that connects your OnLButtonDown function to the application framework:
BEGIN_MESSAGE_MAP(CMyView, CView) ON_WM_LBUTTONDOWN()
// entry specifically for OnLButtonDown
// other message map entries END_MESSAGE_MAP()
Finally, your class header file needs the statement DECLARE_MESSAGE_MAP()
How do you know which function goes with which Windows message?(the MFC library online documentation) includes a table that lists all standard Windows messages and corresponding member function prototypes. You can manually code the message-handling functions—indeed, that is still necessary for certain messages.
Fortunately, Visual C++ provides a tool, ClassWizard, that automates the coding of most message map functions.
页:
[1]