把一个  dialog 的  Title Bar 设置为false(没有标题栏,没有最大化最小化,关闭按钮)我如何去实现窗口的拖曳功能了

解决方案 »

  1.   

    UINT CXXXDialog::OnNcHitTest(CPoint pt)
    {
      CRect rc;
      GetClientRect(&rc);
      ClientToScreen(&rc);
      return rc.PtInRect(pt) ? HTCAPTION : CDialog::OnNcHitTest(pt);
    }  
      

  2.   


    方法一:添加WM_NCHITTEST消息响应
    UINT CXXXDialog::OnNcHitTest(CPoint point)
    {
      CRect rc;
      GetClientRect(&rc);
      CRect rcTitle(0,0,rc.Width(),TITLE_HEIGHT);//rcTitle为虚拟标题栏,即能通过鼠标拖动窗口 
                                                       //的区域,高度为TITLE_HEIGHT
      ClientToScreen(&rcTitle);
      return rcTitle.PtInRect(point) ? HTCAPTION : CDialog::OnNcHitTest(point);

    //方法二:添加WM_LBUTTONDOWN、WM_LBUTTONUP、WM_MOUSEMOVE消息响应移动窗口,大致如下
    void CBTFDialog::OnMouseMove(CPoint point)
    {
    if (!m_bDragTitle)
    {
    return;
    } int offleft = point.x - m_pointDown.x;
    int offtop = point.y - m_pointDown.y; CRect wrc;
    GetWindowRect(&wrc); wrc.OffsetRect(offleft, offtop);
    MoveWindow(&wrc, TRUE );
    }void CBTFDialog::OnLButtonDown(CPoint point)
    {
    if (point.y < 0 || point.y > TITLE_HEIGHT)
    {
    return;
    }
            m_bDragTitle = TRUE;
    m_pointDown = point;
    SetCapture();
    }void CBTFDialog::OnLButtonUp(CPoint point)
    {
    if (!m_bDragTitle)
    {
    return;
    }

    m_bDragTitle = FALSE;
    ReleaseCapture();
    }
      

  3.   

    最简单的方法就是
    void CXXXDlg::OnLButtonDown(UINT nFlags, CPoint point)
    {
    PostMessage(WM_NCLBUTTONDOWN, HTCAPTION, MAKELPARAM(point.x, point.y));
    CDialog::OnLButtonDown(nFlags, point);
    }
      

  4.   

    添加WM_NCHITTEST消息楼上的回答的很清楚了,利用这个消息将客户区作为窗口框架使用。
      

  5.   

    原理为把客户区当做标题栏来处理,
    加上一个OnNcHitTest()消息处理函数:
    UINT CMainWnd::OnNcHitTest(CPoint point)
    {
    UINT nHitTest = CWnd::OnNcHitTest(point);
    if(nHitTest == HTCLIENT)
    nHitTest = HTCAPTION;
    return nHitTest;
    }