MFC无边窗体的移动

    CRect rcDialog;//创建对象
    GetClientRect(&rcDialog);//创建区域并赋予对话框
    CRgn rgn;
    
    
    //rgn.CreateEllipticRgn (0,0,rcDialog.Width(),rcDialog.Height());//创建圆形或椭圆形“region”。
    rgn.CreateRoundRectRgn(0 , 0 , rcDialog.Width( ) , rcDialog.Height( ),rcDialog.Width()-50,rcDialog.Height()-50);//创建圆角矩形“region”
    //rgn.CreateRectRgn( 0, 0, rcDialog.Width(), rcDialog.Height()); //创建矩形的“region”。
     //rgn.CreatePolygonRgn(pt, //LPPOINT lpPoints
                     // rcDialog.Width(), //int nCount
                     //rcDialog.Height()); //创建多边形“region”。int nMode 



    //设置区域
    SetWindowRgn( (HRGN) rgn ,TRUE );

 

 

方法一:直接在OnNcHitTest中虚拟发送HTCAPTION消息

    UINT CMainFrame::OnNcHitTest(CPoint point)   
    {  
     RECT rectWindows, rectClient;  
     this->GetWindowRect(&rectWindows);  
     this->GetClientRect(&rectClient);  
       
     if (point.y > rectWindows.top && point.y < rectWindows.top + 25)  
     {  
      return HTCAPTION;//标题栏形式  
     }  
     else  
     {  
      return CFrameWnd::OnNcHitTest(point);  
     }  
    }   
View Code

方法二:直接在OnLButtonDown中虚拟发送WM_NCLBUTTONDOWN,HTCAPTION消息

    void CMyDlg::OnLButtonDown(UINT nFlags, CPoint point)   
    {  
        if (point.y < 26)  
            PostMessage(WM_NCLBUTTONDOWN,HTCAPTION,MAKELPARAM(point.x,point.y));  
          
        CDialog::OnLButtonDown(nFlags, point);  
    }   
View Code

方法三:通过在OnMouseMove中手动进行处理

    void CMyDlg::OnMouseMove(UINT nFlags, CPoint point)  
    {  
     // TODO: Add your message handler code here and/or call default  
           static CPoint PrePoint = CPoint(0, 0);  
           if(MK_LBUTTON == nFlags)  
           {  
                 if(point != PrePoint)  
                 {  
                        CPoint ptTemp = point - PrePoint;  
                        CRect rcWindow;  
                        GetWindowRect(&rcWindow);  
                        rcWindow.OffsetRect(ptTemp.x, ptTemp.y);  
                        MoveWindow(&rcWindow);  
                        return ;  
                  }  
      
           }  
      
           PrePoint = point;  
           CDialog::OnMouseMove(nFlags, point);  
    }  
View Code

控件拖动:

控件拖动只能采用上述的第三种方法

posted @ 2014-09-10 11:10  鱼时代  阅读(190)  评论(0编辑  收藏  举报