怎么才能实现鼠标按住对话框的边框,拖动对话框大小,在鼠标按下拖动的时候不改变对话框大小,但是显示对话框未来的大小的虚线框,在鼠标松开的时候才改变对话框大小!!

解决方案 »

  1.   

    重载一下 WM_SIZING消息,然后在该消息函数中直接返回就ok了.
    解说一下,在拖动窗口的时候,一般都响应WM_SIZING消息,函数一般为OnSizing(UINT fwSide, LPRECT pRect)此时窗口会动态的改变窗体的大小,当鼠标停下,此时对话框响应WM_SIZE消息。这个消息就是经常看到的onsize了。
      

  2.   

    谁给俺写一个Demo,发到俺的信箱,如果能解决,每人200!
      

  3.   

    刚给别人做的一个demo,修改一下给你了,问题太简单了,要200分太高了
      

  4.   

    http://www.codeguru.com/Cpp/W-D/dislog/resizabledialogs/article.php/c1917/
      

  5.   

    发了程序的在这个帖子中说一下,超过5人就没有分了,呵呵。
    我的帖子:
    http://community.csdn.net/Expert/topic/3627/3627191.xml?temp=.629574
    http://community.csdn.net/Expert/topic/3623/3623634.xml?temp=.5107996
      

  6.   

    DentistryDoctor(雅克医生<改行做程序员了>) 给的例子不行!不是我所要求的!
      

  7.   

    aoosang(智慧的鱼) 发了Demo了吗?
    你写的不对,看清我的要求!!
      

  8.   

    to all:
    问题搞定了,多谢dandycheung(珠穆朗玛),一会散分!
      

  9.   

    楼主是在什么地方SetCapture()的?
      

  10.   

    我也解决了,想要的留下email!
      

  11.   

    答案见此帖 http://community.csdn.net/Expert/topic/3623/3623634.xml?temp=.8533289
    原来楼主海发了好几个帖呢!我接分来了。;) 窃喜中...
      

  12.   

    解决方法:
    因为找不到onsizing,所以只能在onsize里面跳出,
    mouse_event(MOUSEEVENTF_LEFTUP,0,0,0,0);//get out of system sizing再模拟鼠标左键按下
    SetCursorPos(m_rctWindow.left,m_rctWindow.top);
    mouse_event(MOUSEEVENTF_LEFTDOWN,0,0,0,0);//down the left mouse
    SetCursorPos(oldPoint.x,oldPoint.y);//位置要是原来光标的位置然后在onsizing后的第一次OnLButtonDown里面得到点在框架的位置(8个位置)!接下来的就是在onmousemove和onlbuttonup里面处理了!
    绘画的方法是dandycheung(珠穆朗玛) 所说的方法!希望大家多交流,怎么得到点在框架的位置(8个位置)?????????
    ///////////////
    .h文件
    ///////////////
    对话框头文件中加入
    int         m_flagSize;//标志位,控制是否在改变大小!1的时候在改变大小
    CRect       m_rctWindow;//窗口矩形
    CRect       m_rctDraw;//虚线矩形
    int         m_moveDirect; //拖动的位置,1~8代表上右下左,右上,右下,左下,左上afx_msg void OnMouseMove(UINT nFlags, CPoint point);
    afx_msg void OnLButtonUp(UINT nFlags, CPoint point);
    afx_msg void OnSize(UINT nType, int cx, int cy);
    afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
    ///////////////////////////////////////////////////////////////////////////////
    ///////////////
    .cpp文件
    ///////////////
    void CResizingDlg::OnLButtonUp(UINT nFlags, CPoint point) 
    {
    // TODO: Add your message handler code here and/or call default

    if(m_flagSize == 1){
    m_flagSize = -1;
    //erase the pre rectangle start
    {
    HDC hdc = ::GetDC(NULL);
    CDC* pDC = CDC::FromHandle(hdc);
    CRectTracker rectTracker;
    m_rctDraw.NormalizeRect();
    rectTracker.DrawTrackerRect(&m_rctDraw, NULL, pDC, NULL);
    ::ReleaseDC(NULL,hdc);
    }
    //erase the pre rectangle end

    //sizing the window
    m_rctWindow.NormalizeRect();
    ::SetWindowPos(this->GetSafeHwnd(),HWND_TOP,m_rctWindow.left,m_rctWindow.top,m_rctWindow.Width(),m_rctWindow.Height(),SWP_SHOWWINDOW);

    ReleaseCapture();
    }
    CDialog::OnLButtonUp(nFlags, point);
    }void CResizingDlg::OnSize(UINT nType, int cx, int cy) 
    {
    CDialog::OnSize(nType, cx, cy) ;
    // TODO: Add your message handler code here if(m_flagSize != 0){
    m_flagSize =0;
    }else if(m_flagSize == 0){
    GetClientRect(&m_rctWindow);
    ClientToScreen(&m_rctWindow);
    CPoint oldPoint;
    GetCursorPos(&oldPoint); //get the pos of cursor

    mouse_event(MOUSEEVENTF_LEFTUP,0,0,0,0);//get out of system sizing
    SetCursorPos(m_rctWindow.left,m_rctWindow.top);//for left mouse button down in the client area
    mouse_event(MOUSEEVENTF_LEFTDOWN,0,0,0,0);//down the left mouse
    SetCursorPos(oldPoint.x,oldPoint.y);//
    m_flagSize = 1;
    }
    }void CResizingDlg::OnMouseMove(UINT nFlags, CPoint point) 
    {
    // TODO: Add your message handler code here and/or call default

    if(m_flagSize == 1){//sizing the window
    CPoint oldPoint = point;
    this->ClientToScreen(&oldPoint);

    //erase the pre rectangle start
    {
    HDC hdc = ::GetDC(NULL);
    CDC* pDC = CDC::FromHandle(hdc);
    CRectTracker rectTracker;
    m_rctDraw.NormalizeRect();
    rectTracker.DrawTrackerRect(&m_rctDraw, NULL, pDC, NULL);
    ::ReleaseDC(NULL,hdc);
    }
    //erase the pre rectangle end

    //changed the data of rectangle start
    GetWindowRect(&m_rctWindow);
    switch(m_moveDirect) {
    case 1://top
    m_rctWindow.top = oldPoint.y;
    break;
    case 2://right
    m_rctWindow.right = oldPoint.x;
    break;
    case 3://bottom
    m_rctWindow.bottom = oldPoint.y;
    break;
    case 4://left
    m_rctWindow.left = oldPoint.x;
    break;
    case 5://topright
    m_rctWindow.top = oldPoint.y;
    m_rctWindow.right = oldPoint.x;
    break;
    case 6://bottomright
    m_rctWindow.bottom= oldPoint.y;
    m_rctWindow.right = oldPoint.x;
    break;
    case 7://bottomleft
    m_rctWindow.left = oldPoint.x;
    m_rctWindow.bottom = oldPoint.y;
    break;
    case 8://topleft
    m_rctWindow.left = oldPoint.x;
    m_rctWindow.top = oldPoint.y;
    break;
    default:
    break;
    }
    m_rctDraw = m_rctWindow;
    //changed the data of rectangle end


    //Draw the rectangle start
    {
    HDC hdc = ::GetDC(NULL);
    CDC* pDC = CDC::FromHandle(hdc);
    CRectTracker rectTracker;
    m_rctDraw.NormalizeRect();
    rectTracker.DrawTrackerRect(&m_rctDraw, NULL, pDC, NULL);
    ::ReleaseDC(NULL,hdc);
    }
    //Draw the rectangle end

    }else{

    }


    CDialog::OnMouseMove(nFlags, point);
    }void CResizingDlg::OnLButtonDown(UINT nFlags, CPoint point) 
    {
    // TODO: Add your message handler code here and/or call default
    GetWindowRect(&m_rctWindow);
    CPoint oldPoint;
    GetCursorPos(&oldPoint); //get the pos of cursor if(m_flagSize == 1)
    {
    //check the pos of cursor start
    //15---can be changed
    if(fabs(oldPoint.y - m_rctWindow.top)<15){
    if(fabs(oldPoint.x - m_rctWindow.right)<15){//topright
    m_moveDirect = 5;
    m_rctDraw.left = m_rctWindow.left;
    m_rctDraw.right = m_rctWindow.left;
    m_rctDraw.top = m_rctWindow.bottom;
    m_rctDraw.bottom= m_rctWindow.bottom;
    }else if(fabs(oldPoint.x - m_rctWindow.left)<15){//topleft
    m_moveDirect = 8;
    m_rctDraw.left = m_rctWindow.right;
    m_rctDraw.right = m_rctWindow.right;
    m_rctDraw.top = m_rctWindow.bottom;
    m_rctDraw.bottom= m_rctWindow.bottom;
    }else{//上
    m_moveDirect = 1;
    m_rctDraw.left = m_rctWindow.left;
    m_rctDraw.right = m_rctWindow.right;
    m_rctDraw.top = m_rctWindow.bottom;
    m_rctDraw.bottom= m_rctWindow.bottom;
    }
    }else if(fabs(oldPoint.y - m_rctWindow.bottom)<15){
    if(fabs(oldPoint.x - m_rctWindow.right)<15){//bottomright
    m_moveDirect = 6;
    m_rctDraw.left = m_rctWindow.left;
    m_rctDraw.right = m_rctWindow.left;
    m_rctDraw.top = m_rctWindow.top;
    m_rctDraw.bottom= m_rctWindow.top;
    }else if(fabs(oldPoint.x - m_rctWindow.left)<15){//bottomleft
    m_moveDirect = 7;
    m_rctDraw.left = m_rctWindow.right;
    m_rctDraw.right = m_rctWindow.right;
    m_rctDraw.top = m_rctWindow.top;
    m_rctDraw.bottom= m_rctWindow.top;
    }else{//下
    m_moveDirect = 3;
    m_rctDraw.left = m_rctWindow.left;
    m_rctDraw.right = m_rctWindow.right;
    m_rctDraw.top = m_rctWindow.top;
    m_rctDraw.bottom= m_rctWindow.top;
    }
    }else if(fabs(oldPoint.x - m_rctWindow.right)<15){//right
    m_moveDirect = 2;
    m_rctDraw.left = m_rctWindow.left;
    m_rctDraw.right = m_rctWindow.left;
    m_rctDraw.top = m_rctWindow.top;
    m_rctDraw.bottom= m_rctWindow.bottom;
    }else if(fabs(oldPoint.x - m_rctWindow.left)<15){//left
    m_moveDirect = 4;
    m_rctDraw.left = m_rctWindow.right;
    m_rctDraw.right = m_rctWindow.right;
    m_rctDraw.top = m_rctWindow.top;
    m_rctDraw.bottom= m_rctWindow.bottom;
    }else{
    m_flagSize = 0;
    }
    //check the pos of cursor end

    if (m_flagSize == 1) {
    SetCapture();
    }
    }
    CDialog::OnLButtonDown(nFlags, point);
    }