Visual C++ and MFC Programming 2nd Edition

(Martin Jones) #1

Visual C++ and MFC Fundamentals Chapter 5: The Document/View Architecture


void CMainFrame::OnLButtonDown(UINT nFlags, CPoint point)
{
char *MsgCoord = new char[20];

sprintf(MsgCoord, "Left Button at P(%d, %d)", point.x, point.y);

MessageBox(MsgCoord);
}

void CMainFrame::OnRButtonUp(UINT nFlags, CPoint point)
{
MessageBox("Right Mouse Button Up");
}

BOOL CExerciseApp::InitInstance()
{
m_pMainWnd = new CMainFrame ;
m_pMainWnd->ShowWindow(SW_SHOW);
m_pMainWnd->UpdateWindow();

return TRUE;
}

CExerciseApp theApp;


  1. Execute the program. To test it, click in the middle of the window and hold the
    mouse down

  2. Then release the mouse. Notice that the title bar displays the new message only when
    the mouse is up.

  3. Return to MSVC


4.5.4 The Double-Click Message................................................................


Instead of pressing and simply releasing a mouse button, a classic action the user can
perform with the mouse is to double-click an object. When this is done, a double-click
message is sent. The message to consider actually depends on the button that was double-
pressed.

If the double-click was performed using the left mouse button, the
WM_LBUTTONDBLCLK message is sent and its syntax is:

afx_msg void OnLButtonDblClk(UINT nFlags, CPoint point);

If the action was performed using the right mouse button, the WM_RBUTTONDBLCLK
message would be sent. Its syntax is:

afx_msg void OnRButtonDblClk(UINT nFlags, CPoint point);

In both cases the nFlags argument specifies the button that was double-clicked. This
argument can have one of the following values:

Value Description
MK_CONTROL A Ctrl key was held down when the user double-clicked
MK_LBUTTON The left mouse button is down
Free download pdf