左键按下加1,右键按下则减1
class CMYView : public CView //在View类中定义num为整形变量
{
protected: // create from serialization only
CMYView();
DECLARE_DYNCREATE(CMYView)
// Attributes
public:
CMYDoc* GetDocument();
int num;
// Operations
CMYView::CMYView()
{
// TODO: add construction code here
num=0; //赋初值
}
void CMYView::OnDraw(CDC* pDC)
{
CMYDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
CString str; //定义中间变量
str.Format("%d",num); //将格式转换为整形
pDC->TextOut(400,400,str); //在屏幕上输出
// TODO: add draw code for native data here
}
void CMYView::OnLButtonDown(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
num+=1; //左键按下加1
this->Invalidate(); //刷新
CView::OnLButtonDown(nFlags, point);
}
void CMYView::OnRButtonDown(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
num-=1; //减1
this->Invalidate();
CView::OnRButtonDown(nFlags, point);
}