CounterView.
cpp
BEGIN_MESSAGE_MAP(CCounterView, CView)
     //{{AFX_MSG_MAP(CCounterView)
     ON_WM_LBUTTONDOWN()
     ON_WM_RBUTTONDOWN()
     //}}AFX_MSG_MAP
     // Standard printing commands
     ON_COMMAND(ID_FILE_PRINT, CView::OnFilePrint)
     ON_COMMAND(ID_FILE_PRINT_DIRECT, CView::OnFilePrint)
     ON_COMMAND(ID_FILE_PRINT_PREVIEW,CView::OnFilePrintPreview)
END_MESSAGE_MAP()
void CCounterView::OnDraw(CDC* pDC)
{
      CCounterDoc* pDoc = GetDocument();
      ASSERT_VALID(pDoc);
      // TODO: add draw code for native data here
      CRect r;
      GetClientRect(&r);
       CString str;
       str.Format("%d",pDoc->count);
       pDC->DrawText(str,-1,&r,DT_CENTER|DT_VCENTER);
}
CCounterView message handlers
void CCounterView::OnLButtonDown(UINT nFlags, CPoint point)
{
      // TODO: Add your message handler code here and/or call default
      CCounterDoc *pdoc=GetDocument();
      pdoc->count++;
      Invalidate();
       CView::OnLButtonDown(nFlags, point);
}
void CCounterView::OnRButtonDown(UINT nFlags, CPoint point)
{
      // TODO: Add your message handler code here and/or call default
      CCounterDoc *pdoc=GetDocument();
      pdoc->count--;
      Invalidate();
      CView::OnRButtonDown(nFlags, point);
}
CounterDoc.h
class CCounterDoc : public CDocument
{
protected: // create from serialization only
        CCounterDoc();
        DECLARE_DYNCREATE(CCounterDoc)
// Attributes
public:
// Operations
        int count;
public:
// Overrides
        // ClassWizard generated virtual function overrides
        //{{AFX_VIRTUAL(CCounterDoc)
        public:
        virtual BOOL OnNewDocument();
        virtual void Serialize(CArchive& ar);
        //}}AFX_VIRTUAL
// Implementation
public:
        virtual ~CCounterDoc();
#ifdef _DEBUG
        virtual void AssertValid() const;
        virtual void Dump(CDumpContext& dc) const;
#endif
protected:
// Generated message map functions
protected:
        //{{AFX_MSG(CCounterDoc)
              // NOTE - the ClassWizard will add and remove member functions here.
              // DO NOT EDIT what you see in these blocks of generated code !
        //}}AFX_MSG
        DECLARE_MESSAGE_MAP()
};
CounterView.h
class CCounterView : public CView
{
protected: // create from serialization only
        CCounterView();
        DECLARE_DYNCREATE(CCounterView)
// Attributes
public:
         CCounterDoc* GetDocument();
// Operations
public:
// Overrides
        // ClassWizard generated virtual function overrides
        //{{AFX_VIRTUAL(CCounterView)
        public:
        virtual void OnDraw(CDC* pDC); // overridden to draw this view
        virtual BOOL PreCreateWindow(CREATESTRUCT& cs);
        protected:
        virtual BOOL OnPreparePrinting(CPrintInfo* pInfo);
        virtual void OnBeginPrinting(CDC* pDC, CPrintInfo* pInfo);
        virtual void OnEndPrinting(CDC* pDC, CPrintInfo* pInfo);
        //}}AFX_VIRTUAL
// Implementation
public:
        virtual ~CCounterView();
#ifdef _DEBUG
        virtual void AssertValid() const;
        virtual void Dump(CDumpContext& dc) const;
#endif
protected:
// Generated message map functions
protected:
       //{{AFX_MSG(CCounterView)
       afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
       afx_msg void OnRButtonDown(UINT nFlags, CPoint point);
       //}}AFX_MSG
       DECLARE_MESSAGE_MAP()
};