窗体中生成了一个TOOLBAR和一个TREEVIEW改变大小位置代码如下:case WM_SIZE:
    HDWP hdwp;
    RECT rect;
    RECT toolbar;
    RECT tree;    hdwp = BeginDeferWindowPos(2);

    GetClientRect(hwnd, &rect);
    GetClientRect(hToolBar, &toolbar);
    GetClientRect(hTree, &tree);

    DeferWindowPos(hdwp, hToolBar, NULL, 0, 0, 
rect.right, toolbar.bottom, SWP_NOZORDER);
    DeferWindowPos(hdwp, hTree, NULL, 0, toolbar.bottom,
toolbar.bottom, rect.bottom, SWP_NOZORDER);    EndDeferWindowPos(hdwp);
    break;
但是在窗体Size改变时TOOLBAR和TREEVIEW并没有变化,跟踪了下,
toolbar和rect都有正确值。大家帮忙看下是什么原因?
谢谢!

解决方案 »

  1.   

    DeferWindowPos没用过,调用MoveWindow或SetWindowPos试试
      

  2.   

    晕,WM_SIZE里面GetClientRect获取到的是未改变尺寸前的尺寸,lParam参数才包含改变后的尺寸。
      

  3.   


    我查了下,跟踪到Size改变时,GetClientRect获取的是当前尺寸啊。
      

  4.   

    计算好位置后,MoveWindow 即可。
      

  5.   

    hToolBar->getparent()->getclientrect(&rect1)//主窗体getclientrect
    hToolBar ->getwindowrect((&rect2)//目标控件 getwindowrect 
    onsize(int cx,int cy)
    {
    ..........                      
       screentoclent(&rect2)
       movewindow(....);
    ..............
    }