vc++ 中当对话框的边界属性(Border)设为none后,窗口无法移动。如果我想移动窗口,该怎么做?

解决方案 »

  1.   

    加入WM_NCHITTEST的消息响应,然后返回HTCAPTION(就是返回点击了标题栏的意思),就可以移动窗口了
      

  2.   

    自己用SetWindowPos
    或者MoveWindow
      

  3.   

    响应WM_LBUTTONDOWN消息,在对话的函数
    CDialog::OnLButtonDown(nFlags, point); 
    中添加:
    PostMessage(WM_NCLBUTTONDOWN,HTCAPTION,MAKELPARAM(point.x, point.y)); 就可以在任意位置按住鼠标左键来移动
      

  4.   

    其实也很简单,给你一段代码:
    void shader::OnLButtonDown(UINT nFlags, CPoint point) 
    {
             CPoint point1;//计算鼠标相对于对话框的位置
          CRect rect;
         GetCursorPos(&point1);
         GetWindowRect(&rect);
         awidth=point1.x-rect.left;//该量为类成员(在public中定义 int)
         aheight=point1.y-rect.top;//该量为类成员(在public中定义 int)
             m_con=true;//该量为类成员(在public中定义 bool m_con=false)   
                        //如果该量为true,表示可以拖动
             CDialog::OnLButtonDown(nFlags, point); 
    }
    void shader::OnLButtonUp(UINT nFlags, CPoint point) 
    {
              m_con=false;//不可拖动
             CDialog::OnLButtonUp(nFlags, point); 
    }void shader::OnTimer(UINT nIDEvent) 
    {
    CPoint point;
    CRect rect;  
    GetCursorPos(&point);
    this->GetWindowRect(&rect);   
    rect.right=rect.Width()+point.x-awidth;//注意顺序:先计算right和
                                                    //bottom
      rect.bottom=rect.Height()+point.y-aheight;
              rect.left=point.x-awidth;
      rect.top=point.y-aheight;
          this->MoveWindow(rect); CDialog::OnTimer(nIDEvent);}其实也是是计算了一下鼠标的位置,然后让对话框移动该位置,同时考虑鼠标与对话框的相对距离.别忘了SetTimer(1,10,0);
      

  5.   

    UINT CMainWindow::OnNcHitTest (CPoint point)
    {
        UINT nHitTest = CFrameWnd::OnNcHitTest (point);
        if ((nHitTest == HTCLIENT) && (::GetAsyncKeyState (MK_LBUTTON) < 0))
            nHitTest = HTCAPTION;
        return nHitTest;
    }
      

  6.   

    同意 zhucde(【风间苍月】)  的。