基于对话框的绘图程序(vc)

来源:互联网 发布:软件编程程序培训机构 编辑:程序博客网 时间:2024/06/06 06:54

最近没事写几行代码,拿来分享一下,很简单的利用鼠标画图:IsDraging是鼠标拖拽的标志,IsRect是菜单标记(判断是否单击菜单)

初始化:

IsDraging=false;
 IsRect=false;
 m_hCross=AfxGetApp()->LoadStandardCursor(IDC_CROSS);

其它程序:

if(IsDraging)
 {
  CClientDC dc1(this);
  //GetClientRect(&rectangle);
  CPen lpen(PS_SOLID,2,RGB(255,0,0));
  dc1.SelectObject(&lpen);
  dc1.Rectangle(rectangle.left,rectangle.top,rectangle.right,rectangle.bottom);
  
 }

 

void CToolTipDlg::OnLButtonDown(UINT nFlags, CPoint point)
{
 // TODO: Add your message handler code here and/or call default
 if(IsRect)
 {
  SetCapture();
  ::SetCursor(m_hCross);
  rectangle.left=point.x;
  rectangle.top=point.y;
 
  IsDraging=true;
 }
 
 CDialog::OnLButtonDown(nFlags, point);
}

void CToolTipDlg::OnMouseMove(UINT nFlags, CPoint point)
{
 // TODO: Add your message handler code here and/or call default
 if(IsDraging&&IsRect)
 {
  rectangle.right=point.x;
  rectangle.bottom=point.y;
  Invalidate();
 }

 
 CDialog::OnMouseMove(nFlags, point);
}

void CToolTipDlg::OnLButtonUp(UINT nFlags, CPoint point)
{
 // TODO: Add your message handler code here and/or call default
 if(IsDraging&&IsRect)
 {
  rectangle.right=point.x;
  rectangle.bottom=point.y;
  ReleaseCapture();
  IsDraging=false;
  
  //IsRect=false;

 }
 
 CDialog::OnLButtonUp(nFlags, point);
}

原创粉丝点击