Book Image

Microsoft Visual C++ Windows Applications by Example

By : Stefan Bjornander, Stefan Björnander
Book Image

Microsoft Visual C++ Windows Applications by Example

By: Stefan Bjornander, Stefan Björnander

Overview of this book

Table of Contents (15 chapters)
Microsoft Visual C++ Windows Applications by Example
Credits
About the Author
About the Reviewer
Preface
Index

Catching the Mouse


When the us er clicks the left mouse button, a message is sent from Windows to the application. We can catch the message by opening the file RingView.cpp, choosing View and Properties Window , and the Message button. Then we connect the function OnLeftButtonDown to the message WM_LBUTTONDOWN.

Then we have a function prototype in the RingView.h file and a skeleton function definition in the RingView.cpp file.

RingView.cpp

void CRingView::OnLButtonDown(UINT nFlags, CPoint point)
{
  // TODO: Add your message handler code here and/or call
  // default.
  CScrollView::OnLButtonDown(nFlags, point);
}

We modify the function by sending the message from the view to the document.

RingView.cpp

void CRingView::OnLButtonDown(UINT nFlags, CPoint point)
{
  CRingDoc* pDoc = GetDocument();
  ASSERT_VALID(pDoc);
  pDoc->MouseDown(point);
  CScrollView::OnLButtonDown(nFlags, point);
}

After that, we have to add the function MouseDown to the document class. We do also add two functions...