Programming Tips - MFC: How does my application receive a user's mouse click?

Date: 2010jan19 OS: Windows Level: beginner Language: C/C++ Framework: MFC Q. MFC: How does my application receive a user's mouse click? A. If its a button you get WM_COMMAND otherwise WM_LBUTTONDOWN windows messages. In MFC you can use the GUI to set this up or do: For a button... In your .h file:
afx_msg LRESULT OnMyButton(WPARAM, LPARAM);
By the way, MFC used to be called AFX. That's why many things have that in the name. In your .cpp file:
BEGIN_MESSAGE_MAP(CMyDialog, CDialog) ON_COMMAND(ID_MY_BUTTON, OnMyButton) END_MESSAGE_MAP() // ... LRESULT CMyDialog::OnMyButton(WPARAM, LPARAM); { }
For a click on a window... In your .h file:
afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
In your .cpp file:
BEGIN_MESSAGE_MAP(CMyWindow, CWnd) ON_WM_LBUTTONDOWN() END_MESSAGE_MAP() // ... void CMyWindow::OnLButtonDown(UINT nFlags, CPoint point) { // ... }