画出红色矩形框(还需修改)

void CVIDEO::OnLButtonDown(UINT nFlags, CPoint point)
{
 // TODO: 在此添加消息处理程序代码和/或调用默认值
 CMainFrame* pMainFrm = (CMainFrame *)AfxGetApp()->GetMainWnd();

 ClientToScreen(&point);
 CRect rect;
 GetDlgItem(IDC_STATIC1)->GetClientRect(rect);
 GetDlgItem(IDC_STATIC1)->ClientToScreen(rect);

 if ((pMainFrm->IsAviFile||pMainFrm->IsCamera)&&rect.PtInRect(point))
 {
  startPoint=point;
  endPoint=point;
  selection=cvRect(point.x,point.y,0,0);
  drawingflag=TRUE;
  if (playflag) KillTimer(1); 
 }
 CFormView::OnLButtonDown(nFlags, point);
}

void CVIDEO::OnMouseMove(UINT nFlags, CPoint point)
{
 // TODO: 在此添加消息处理程序代码和/或调用默认值
 if (!drawingflag)  
  return;   
 CClientDC   dc(this);  
 dc.DPtoLP(&point); //映射每个点的坐标,或大小的尺寸,到GDI的逻辑坐标系统的设备坐标系统。
 dc.SelectStockObject(NULL_BRUSH);   

 CPen pen, *oldPen;
 pen.CreatePen(PS_SOLID,1,RGB(255,0,0)); 
 oldPen =dc.SelectObject(&pen); 

 dc.SetROP2(R2_NOT);


 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);

 endPoint=point;
 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);

 dc.SelectObject(oldPen);
 
 CFormView::OnMouseMove(nFlags, point);
}

void CVIDEO::OnLButtonUp(UINT nFlags, CPoint point)
{
 // TODO: 在此添加消息处理程序代码和/或调用默认值
 if (drawingflag)  
 {
  drawingflag=false;   

  CClientDC   dc(this);   
  dc.DPtoLP(&point);   
  dc.SelectStockObject(NULL_BRUSH);   

  CPen pen, *oldPen; 
  pen.CreatePen(PS_SOLID,1,RGB(255,0,0)); 
  oldPen =dc.SelectObject(&pen); 

  dc.SetROP2( R2_COPYPEN );  
  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);

  dc.SelectObject(oldPen);

  selection.width=abs(point.x-selection.x);
  selection.height=abs(point.y-selection.y);
  selectionflag=-1;
  if(playflag) SetTimer(1,m_fps,NULL);
 }
 
 CFormView::OnLButtonUp(nFlags, point);
}

你可能感兴趣的:(null)