MFC应用:在视图窗口中间显示计数,功能:点击左键加1右键减1

在左右键上添加代码实现点击加减1的控制:

void CMy1View::OnLButtonDown(UINT nFlags, CPoint point) 
{
 // TODO: Add your message handler code here and/or call default
    CMy1Doc* pDoc = GetDocument();
    ASSERT_VALID(pDoc); 
    CClientDC dc(this);
    dc.TextOut(10,10,pDoc->str);
    CMy1Doc* pDoc = GetDocument();
    ASSERT_VALID(pDoc);


//计数左击键盘加1右击键盘减1
 CRect rect;
 this->GetWindowRect(&rect);
 ++pDoc->num;
 pDoc->SetModifiedFlag();
 this->Invalidate(); 
 CView::OnLButtonDown(nFlags, point);
}


void CMy1View::OnRButtonDown(UINT nFlags, CPoint point) 
{
 // TODO: Add your message handler code here and/or call default
  CMy1Doc* pDoc = GetDocument();
 ASSERT_VALID(pDoc);

 CRect rect;
 this->GetWindowRect(&rect);
 --pDoc->num;
 pDoc->SetModifiedFlag();
 this->Invalidate();
 CView::OnRButtonDown(nFlags, point);
}

void CMy1View::OnMenuitem32773() 
{
 // TODO: Add your command handler code here
 CDialog my;
 my.DoModal();
}

 

//在视图菜单view.cpp文件中进行的操作:

void CMy1View::OnDraw(CDC* pDC)
{
 CMy1Doc* pDoc = GetDocument();
 ASSERT_VALID(pDoc);

CRect rect;
 this->GetWindowRect(&rect);
 int x = rect.Width() / 2;
 int y = rect.Height() / 2;

    str.Format("计数%d",pDoc->num);
 pDC->TextOut(x,y,str); 


 


 

你可能感兴趣的:(MFC应用:在视图窗口中间显示计数,功能:点击左键加1右键减1)