我要实现鼠标点击圆形区域,在区域外画一个红色的矩形
我画了两个圆,且要求红矩形能在两个圆间切换,就是说点击第一个圆,红矩形显示,而第二个圆外没有;点击第二个圆,红矩形显示,而第一个圆外没有;
  BOOL CLabel2View::OnLButtonDown(UINT nFlags, CPoint point) 
{
 // TODO: Add your message handler code here and/or call default
  CDC *pDC;
   CDC dcMem;
   pDC=GetDC();     
      CClientDC dc(this);
      OnPrepareDC(&dc);
       CRect rc;
       GetClientRect(&rc);      int x1=rc.right/2-200; 
      int y1=300-200;
      int x2=rc.right/2+200;
      int y2=300+200;
     int y5=750-200;
      int y6=750+200;
    CRect rgn(x1,y1,x2,y2);
     CRect rect(x1,y5,x2,y6);
     if(rgn.PtInRect(point))
    { SetCapture();
     m_bCaptured=TRUE;
      m_bCaptured1=FALSE;
      ::SetCursor(::LoadCursor(NULL,IDC_CROSS));
   
   
  }
 else if(rect.PtInRect(point))
 {
  SetCapture();
   m_bCaptured1=TRUE;
   m_bCaptured=FALSE;
     
   ::SetCursor(::LoadCursor(NULL,IDC_CROSS));
    
   }
   ReleaseDC(pDC);        return m_bCaptured;
 CScrollView::OnLButtonDown(nFlags, point);
 
}
我在onLbuttonDown 设标志,在ondraw 里画,可是响应非常慢,大家帮我看看怎么回事void CLabel2View::OnDraw(CDC* pDC)
{//// 圆已经画过/////////
 CPoint point ;
 GetCursorPos(&point);
m_bCaptured=OnLButtonDown(MK_LBUTTON,point); 
  
if(m_bCaptured==TRUE)
{
     pDC->Rectangle(x1-20,y1-20,x2+20,y2+20);
      pDC->SelectObject(&ppenOld);
 m_bCaptured=OnLButtonDown(MK_LBUTTON,point); 
}
if(m_bCaptured1==TRUE)
{  
 pDC->Rectangle(x1-20,y5-20,x2+20,y6+20);
 pDC->SelectObject(&ppenOld);
  m_bCaptured=OnLButtonDown(MK_LBUTTON,point); 
}
void CLabel2View::OnLButtonUp(UINT nFlags, CPoint point) 
{
 // TODO: Add your message handler code here and/or call default
   if(m_bCaptured){
  ::ReleaseCapture();
  m_bCaptured=FALSE;
  m_bCaptured1=FALSE;
 }}
大家帮我看看或提个办法,妹妹在这里谢谢了!

解决方案 »

  1.   

    用 Invalidate在最后更新客户区  还有在OnLButtonDown中的pDC是干嘛用的 在OnDraw又调用OnLButtonDown ????? 感觉代码非常混乱  建议在OnLButtonDown中检测 最后用Invalidate刷新客户区 在OnDraw中根据OnLButtonDown的信息绘图 不用调用OnLButtonDown  还有 在这段代码中 你没有使用WM_MOUSEMOVE因此
    完全 没有 必要用mouse capture 
      

  2.   

    以前用pDC->Ellipse (..);画图的
    在ondraw()里我试过用invalidate();不停的闪烁,可能不能用Invalidate()刷新,
    不过还是谢谢你!