在vc++技术内幕IV中第4章讲到:
在View.h中声明:
//{{AFX_MSG(CCex03View)
afx_msg void OnLButtonDown(UINT nFlags,CPoint point);
//}}AFX_MSG
private:
int m_nColor;
CRect m_rectEllipse;
在.cpp文件中这样写:
CCex04View::CCex04View():m_rectEllipse(0,0,200,200)
{
// TODO: add construction code here
m_nColor=GRAY_BRUSH;
}
void CCex03View::OnDraw(CDC* pDC)
{
pDC->SelectStockObject(m_nColor);
pDC->Ellipse(m_rectEllipse);
}
void CCex03View::OnLButtonDown(UINT nFlags,CPoint point)
{
if(m_rectEllipse.PtInRect(point)) 
{
if (m_nColor=GRAY_BRUSH)
{
m_nColor=WHITE_BRUSH;
}
else
{
m_nColor=GRAY_BRUSH;
}
InvalidateRect(m_rectEllipse);
}
}
为什么我左键按下的时候,没有变色

解决方案 »

  1.   

    你给分真小气你在mouseup函数里面updateallviews看看可以不可以
      

  2.   

    你点左上角
    必须在
    (0,0,200,200)
    之内或者把
    if(m_rectEllipse.PtInRect(point)) 
    注释掉
      

  3.   

    我知道了
    在cpp文件中要加
    //{{AFX_MSG_MAP(CCex03View)
    ON_WM_LBUTTONDOWN()
    //}}AFX_MSG_MAP
      

  4.   

    在实现文件(.CPP)中的
    BEGIN_MESSAGE_MAP(...)
    END_MESSAGE_MAP()
    之间是否有ON_WM_LBUTTONDOWN()?若没有则加上
      

  5.   

    to kxgy(科学怪人)谢谢了~不过估计是CSDN的数据库执行效率太差了~呵呵~没看到你的帖子~~已经结贴了