无边框的对话框的大小拖动实现

网上收集的:

void   CMyDlg::OnMouseMove(UINT   nFlags,   CPoint   point)    
  {  
  //   TODO:   Add   your   message   handler   code   here   and/or   call   default  
  if(m_nMyHitTest   ==   20)//当鼠标没有选择拖动类型的时候改变鼠标状态  
  {  
  CRect   rect;  
  CRect   staticRect;  
  this->GetWindowRect(&rect);  
  ScreenToClient(&rect);  
  HCURSOR   hCursor;  
  if(point.x   >   rect.left   &&   point.x   <   rect.right   &&    
  point.y   >   rect.top-FRAME_SPACE   &&   point.y   <   rect.top+FRAME_SPACE)//上边框区域  
  {    
  hCursor   =   AfxGetApp()->LoadStandardCursor(IDC_SIZENS);  
  SetCursor(hCursor);  
  }  
  else   if(point.x   >   rect.left   &&   point.x   <   rect.right   &&    
  point.y   >   rect.bottom-FRAME_SPACE   &&   point.y   <   rect.bottom+FRAME_SPACE)  
  {  
  hCursor   =   AfxGetApp()->LoadStandardCursor(IDC_SIZENS);  
  SetCursor(hCursor);  
  }  
  else   if(point.y   >   rect.top   &&   point.y   <   rect.bottom   &&    
  point.x   >   rect.left-FRAME_SPACE   &&   point.x   <   rect.left+FRAME_SPACE)  
  {  
  hCursor   =   AfxGetApp()->LoadStandardCursor(IDC_SIZEWE);  
  SetCursor(hCursor);  
  }  
  else   if(   point.y   >   rect.top   &&   point.y   <   rect.bottom   &&    
  point.x   >   rect.right-FRAME_SPACE   &&   point.x   <   rect.right+FRAME_SPACE)  
  {  
  hCursor   =   AfxGetApp()->LoadStandardCursor(IDC_SIZEWE);  
  SetCursor(hCursor);  
  }  
  GetDlgItem(IDC_STATIC_SIZE)->GetWindowRect(&staticRect);  
  ScreenToClient(staticRect);  
  if(staticRect.PtInRect(point))  
  {  
  hCursor   =   AfxGetApp()->LoadStandardCursor(IDC_SIZENWSE);  
  SetCursor(hCursor);  
  }  
  }  
  CDialog::OnMouseMove(nFlags,   point);  
  }

void   CMyDlg::OnLButtonDown(UINT   nFlags,   CPoint   point)    
  {  
  //   TODO:   Add   your   message   handler   code   here   and/or   call   default  
  CRect   rect;  
  CRect   staticRect;  
  this->GetWindowRect(&rect);  
  ScreenToClient(&rect);  
  HCURSOR   hCursor;  
  if(point.x   >   rect.left   &&   point.x   <   rect.right   &&    
  point.y   >   rect.top-FRAME_SPACE   &&   point.y   <   rect.top+FRAME_SPACE)//上边框区域  
  {    
  hCursor   =   AfxGetApp()->LoadStandardCursor(IDC_SIZENS);  
  SetCursor(hCursor);  
  SetCapture();  
  m_bChangeSize   =   TRUE;  
  m_nMyHitTest   =   HTTOP;  
  }  
  else   if(point.x   >   rect.left   &&   point.x   <   rect.right   &&    
  point.y   >   rect.bottom-FRAME_SPACE   &&   point.y   <   rect.bottom+FRAME_SPACE)  
  {  
  hCursor   =   AfxGetApp()->LoadStandardCursor(IDC_SIZENS);  
  SetCursor(hCursor);  
  SetCapture();  
  m_bChangeSize   =   TRUE;  
  m_nMyHitTest   =   HTBOTTOM;  
  }  
  else   if(point.y   >   rect.top   &&   point.y   <   rect.bottom   &&    
  point.x   >   rect.left-FRAME_SPACE   &&   point.x   <   rect.left+FRAME_SPACE)  
  {  
  hCursor   =   AfxGetApp()->LoadStandardCursor(IDC_SIZEWE);  
  SetCursor(hCursor);  
  SetCapture();  
  m_bChangeSize   =   TRUE;  
  m_nMyHitTest   =   HTLEFT;  
  }  
  else   if(   point.y   >   rect.top   &&   point.y   <   rect.bottom   &&    
  point.x   >   rect.right-FRAME_SPACE   &&   point.x   <   rect.right+FRAME_SPACE)  
  {  
  hCursor   =   AfxGetApp()->LoadStandardCursor(IDC_SIZEWE);  
  SetCursor(hCursor);  
  SetCapture();  
  m_bChangeSize   =   TRUE;  
  m_nMyHitTest   =   HTRIGHT;  
  }  
  GetDlgItem(IDC_STATIC_SIZE)->GetWindowRect(&staticRect);  
  ScreenToClient(staticRect);  
  if(staticRect.PtInRect(point))  
  {  
  hCursor   =   AfxGetApp()->LoadStandardCursor(IDC_SIZENWSE);  
  SetCursor(hCursor);  
  SetCapture();  
  m_bChangeSize   =   TRUE;  
  m_nMyHitTest   =   HTBOTTOMRIGHT;  
  }  
  CDialog::OnLButtonDown(nFlags,   point);  
  }  
   
  void   CMyDlg::OnLButtonUp(UINT   nFlags,   CPoint   point)    
  {  
  //   TODO:   Add   your   message   handler   code   here   and/or   call   default  
  BOOL   bChangeStatic   =   TRUE;  
  //   TODO:   Add   your   message   handler   code   here   and/or   call   default  
  if(m_bChangeSize)  
  {  
  m_bChangeSize   =   FALSE;  
  TRACE("OnLButtonUp\n");  
  ::ReleaseCapture();  
  CPoint   CurPoint;  
  CRect     DlgRect;  
  GetCursorPos(&CurPoint);  
  GetWindowRect(DlgRect);  
  CRect   rectTemp,rectTemp1;  
  GetDlgItem(IDC_STATIC_SIZE)->GetWindowRect(&rectTemp);    
  GetDlgItem(IDC_STATIC_SIZE)->GetWindowRect(&rectTemp1);    
  ScreenToClient(rectTemp1);  
  bChangeStatic   =   rectTemp1.PtInRect(point);  
  int   RightWidth   =   DlgRect.right   -   rectTemp.right;  
  int   BottomWidth   =   DlgRect.bottom   -   rectTemp.bottom;  
  int   Width   =   rectTemp.right   -rectTemp.left;  
  int   Hight   =   rectTemp.bottom   -   rectTemp.top;  
   
  if(m_nMyHitTest   ==   HTLEFT)  
  {  
  if(abs(DlgRect.left   -   CurPoint.x)   >   FRAME_SPACE)  
  DlgRect.left   =   CurPoint.x;  
  }  
  else   if(m_nMyHitTest   ==   HTRIGHT)  
  {  
  if(abs(DlgRect.right   -   CurPoint.x)   >   FRAME_SPACE)  
  DlgRect.right   =   CurPoint.x;  
  }  
  else   if(m_nMyHitTest   ==   HTTOP)  
  {  
  if(abs(DlgRect.top   -   CurPoint.y)   >   FRAME_SPACE)  
  DlgRect.top   =   CurPoint.y;  
  }  
  else   if(m_nMyHitTest   ==   HTTOPLEFT)  
  {  
  DlgRect.top   =   CurPoint.y;  
  DlgRect.left   =   CurPoint.x;  
  }  
  else   if(m_nMyHitTest   ==   HTTOPRIGHT)  
  {  
  DlgRect.top   =   CurPoint.y;  
  DlgRect.right   =   CurPoint.x;  
  }  
  else   if(m_nMyHitTest   ==   HTBOTTOM)  
  {  
  if(abs(DlgRect.bottom   -   CurPoint.y)   >   FRAME_SPACE)    
  DlgRect.bottom   =   CurPoint.y;  
  }  
  else   if(m_nMyHitTest   ==   HTBOTTOMLEFT)  
  {  
  DlgRect.bottom   =   CurPoint.y;  
  DlgRect.left   =   CurPoint.x;  
  }  
  else   if(m_nMyHitTest   ==   HTBOTTOMRIGHT)  
  {  
  if(!bChangeStatic)  
  {  
  DlgRect.bottom   =   CurPoint.y;  
  DlgRect.right   =   CurPoint.x;  
  }  
  }  
  MoveWindow(DlgRect);  
  SetRedrawArea(DlgRect);  
  if(!bChangeStatic)  
  {  
  rectTemp.right   =   DlgRect.right   -   RightWidth;  
  rectTemp.left   =   rectTemp.right   -   Width;  
  rectTemp.bottom   =   DlgRect.bottom   -   BottomWidth;  
  rectTemp.top   =   rectTemp.bottom   -   Hight;  
  ScreenToClient(rectTemp);  
  GetDlgItem(IDC_STATIC_SIZE)->MoveWindow(rectTemp);  
  }  
  m_nMyHitTest   =   20; //恢复鼠标为未选择拖动状态  
  }  
  CDialog::OnLButtonUp(nFlags,   point);  
  }

转载于:https://www.cnblogs.com/aion111/archive/2009/01/13/1374904.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值