画虚拟矩形框(适合静态的)

CPoint flag=FALSE;
CPoint startPoint=0;
CPoint endPoint=0;                          

 

BEGIN_MESSAGE_MAP(CVIDEO, CFormView)
  ON_WM_LBUTTONDOWN()
 ON_WM_LBUTTONUP()
 ON_WM_MOUSEMOVE()
END_MESSAGE_MAP()

 

void CVIDEO::OnLButtonDown(UINT nFlags, CPoint point)
{
 // TODO: 在此添加消息处理程序代码和/或调用默认值
 CMainFrame* pMainFrm = (CMainFrame *)AfxGetApp()->GetMainWnd();
 if (pMainFrm->IsAviFile||pMainFrm->IsCamera)
 {
  startPoint=point;
  endPoint=point;
  if (!flag)
  {
   CClientDC dc(this);
   
   dc.SetROP2(R2_NOT);
   dc.SelectStockObject(NULL_BRUSH);
   dc.Rectangle(CRect(startPoint,endPoint));
  }
  flag=TRUE;
 }

 CFormView::OnLButtonDown(nFlags, point);
}

void CVIDEO::OnMouseMove(UINT nFlags, CPoint point)
{
 // TODO: 在此添加消息处理程序代码和/或调用默认值
 
 CClientDC dc(this);
 
 dc.SetROP2(R2_NOT);
 dc.SelectStockObject(NULL_BRUSH);
 if(flag)
 {
  dc.Rectangle(CRect(startPoint,endPoint));
  dc.Rectangle(CRect(startPoint,point));
  endPoint=point;

 }
 
 CFormView::OnMouseMove(nFlags, point);
}

void CVIDEO::OnLButtonUp(UINT nFlags, CPoint point)
{
 // TODO: 在此添加消息处理程序代码和/或调用默认值
 flag=FALSE;
 
 CClientDC dc(this);
 dc.SetROP2(R2_NOT);
 dc.SelectStockObject(NULL_BRUSH);
 dc.Rectangle(CRect(startPoint,endPoint));
 
   /*if(MessageBox("所选矩形框是否为需要对象","询问",MB_ICONQUESTION|MB_OKCANCEL)==IDOK)
  {
   CPen   pen(PS_SOLID,1,RGB(100,0,100));
   dc.SelectObject(&pen);
   dc.MoveTo(startPoint);
   dc.LineTo(startPoint.x,endPoint.y);
   dc.MoveTo(startPoint.x,endPoint.y);
   dc.LineTo(endPoint);
   dc.MoveTo(endPoint);
   dc.LineTo(endPoint.x,startPoint.y);
   dc.MoveTo(endPoint.x,startPoint.y);
   dc.LineTo(startPoint);
   SetRect(ObjectRect,startPoint.x,startPoint.y,endPoint.x,endPoint.y);
  }*/

 CFormView::OnLButtonUp(nFlags, point);
}

 

你可能感兴趣的:(画虚拟矩形框(适合静态的))