void CTyuiDlg::OnMouseMove(UINT nFlags, CPoint point) 
{
 // TODO: Add your message handler code here and/or call default
 if ((nFlags&MK_LBUTTON)==MK_LBUTTON)
 {
  CClientDC dc(this);
  CPen pen(PS_SOLID,1,RGB(256,256,256));
  dc.SelectObject(&pen);
  dc.Ellipse(m_x,m_y,point.x,point.y);
 // dc.Rectangle(10,10,point.x,point.y);
   
   
 }
 
 CDialog::OnMouseMove(nFlags, point);
}
 void CTyuiDlg::OnLButtonDown(UINT nFlags, CPoint point) 
{
 // TODO: Add your message handler code here and/or call default
 m_x=point.x;
 m_y=point.y;
 CDialog::OnLButtonDown(nFlags, point);
}
 
void CTyuiDlg::OnLButtonUp(UINT nFlags, CPoint point) 
{
 // TODO: Add your message handler code here and/or call default
 CClientDC dc(this);
 dc.Ellipse(m_x,m_y,point.x,point.y) ;
// dc.Rectangle(m_x,m_y,point.x,point.y);
 CDialog::OnLButtonUp(nFlags, point);
}
按下鼠标左键,光标位置被m_x,m_y记录,然后随鼠标画圆或椭圆,我只想模拟“画图程序”中的做法,但是,随着鼠标画了一大堆圆,我只想要最后一个。我想用RGB(256,256,256)画透明的圆,在OnLButtonUp画一个黑色的圆,没成功。
问问“怎么擦除不想要的圆”

解决方案 »

  1.   

    void CTyuiDlg::OnMouseMove(UINT nFlags, CPoint point)
    {
    // TODO: Add your message handler code here and/or call default
    if ((nFlags&MK_LBUTTON)==MK_LBUTTON)
    {
    dc.Ellipse(m_x,m_y,point.x,point.y);
    // dc.Rectangle(10,10,point.x,point.y);
    }CDialog::OnMouseMove(nFlags, point);
    }
    void CTyuiDlg::OnLButtonDown(UINT nFlags, CPoint point)
    {
    // TODO: Add your message handler code here and/or call default
    m_x=point.x;
    m_y=point.y;
    CDialog::OnLButtonDown(nFlags, point);
    }void CTyuiDlg::OnLButtonUp(UINT nFlags, CPoint point)
    {
    // TODO: Add your message handler code here and/or call default
    m_x2 = point.x;
    m_y2 = point.y
    Invalidate();
    CDialog::OnLButtonUp(nFlags, point);
    }void CTyuiDlg::OnPaint()
    {
    CClientDC dc(this);
    CPen pen(PS_SOLID,1,RGB(256,256,256));
    dc.SelectObject(&pen);
    dc.Ellipse(m_x,m_y,m_x2,m_y2) ;
    }
      

  2.   

    OnPaint函数要修改一下:   
    void CTyuiDlg::OnPaint()
    {
    CClientDC dc(this);
    CPen pen(PS_SOLID,1,RGB(256,256,256));
    dc.SelectObject(&pen);
    int Radius = int(sqr((m_x2-m_x)*(m_x2-m_x)+(m_y2-m_y)*(m_y2-m_y)));
    dc.Ellipse(m_x-Radius,m_y-Radius,m_x+Radius,m_y+Radius) ;  
    }
      

  3.   

    (1)绘图模式修改为XOR模式;
    (2)每次在新的位置画时,先在原来的位置画一下。(XOR模式下画了以后,再画一次就擦除了)。没人回答是因为很多人不用VC++/MFC了,我就是其中一个
      

  4.   

    RGB(256,256,256)还真是太有意思,去看看RGB的宏定义先……最好把所有的绘图语句集中到OnPaint(),要更新某个部分,用InvalidateRect(),不然,即便是用XOR也可以做到差不多的效果,但是画面被覆盖,画的圆就没了。
      

  5.   

    w_anthony() :画面被覆盖是什么意思?是不是刷新的意思。
    LZ的问题是鼠标拖动中绘制,就是那种橡皮筋矩形,如果放到OnPaint中,鼠标一动就要Invalidate,会造成屏幕闪烁。
    最好画完了存到内存对象以后,再Invalidate(),从OnPaint中画。
      

  6.   

    Invalidate()的确会闪,InvalidateRect()却不会闪,不信你试试……
      

  7.   

    使用NOTXORPEN模式,在原来的地方再画一次就擦除了
      

  8.   

    tracing() 说的对,我的绘图模式那里写错了
      

  9.   

    quote:Invalidate()的确会闪,InvalidateRect()却不会闪    Invalidate()和InvalidateRect()原理是一样的,只不过 Invalidate()刷新整个客户区,而InvalidateRect()刷新指定的矩形区域。
      

  10.   

    我试过了,用NOTXORPEN模式用了N年了,这是最好的解决方案