我在窗体中加了一个data grid控件,我想在改变主窗口大小时也改变控件的大小,该怎么作,谢谢!

解决方案 »

  1.   

    楼上说得对,MoveWindow可以修改对象位置和大小,也可以使用SetWindowPos,不过SetWindowPos调用比MoveWindow稍微麻烦一点,但有更多的功能。
      

  2.   

    CRect rect;
    GetDlgItem(IDC_DATAGRID)->GetWindowRect(&rect);
    ScreenToClient(&rect);
    GetDlgItem(IDC_DATAGRID)->MoveWindow(rect.left,rect.top,rect.right,rect.bottom);
      

  3.   

    m_ctrlPicture.SetImage("c:\\windows\\Clouds.bmp");
         const int nAddConst=40;
         //图象尺寸不会正合适,需要加点增量。
         long lPictureWidth=m_ctrlPicture.GetImageWidth();
         long lPictureHeight=m_ctrlPicture.GetImageHeight();
         MoveWindow(0,0,lPictureWidth,lPictureHeight,true);
         //改变对话框大小     //改变控件的大小
    m_ctrlPicture.MoveWindow(0,0,lPictureWidth,
    lPictureHeight+nAddConst,true);
    m_ctrlPicture.Display();移动窗口 
    调用CWnd : : SetWindowPos并指定SWP_NOSIZE标志。目的位置与父窗口有关
    (顶层窗口与屏幕有关)。调用CWnd : : MoveWindow时必须要指定窗口的大小。
    //Move window to positoin 100 , 100 of its parent window .
    SetWindowPos (NULL, 100 , 100 , 0 , 0 , SWP_NOSIZE |SWP_NOACTIVATE);
      

  4.   

    ::SetWindowPos()给你一个示例
    // Arrange controls
    void CLakerDlg::Arrange(void)
    {
    RECT rc_start;
    // this is frame and edit
    GetClientRect( &rc_start );
    rc_start.left = 10;
    rc_start.top = 10;
    rc_start.right -= 20;
    rc_start.bottom -= 100;
    ::SetWindowPos( m_frame.m_hWnd, 0, rc_start.left, rc_start.top, rc_start.right, rc_start.bottom, 0 ); Invalidate();//这个是最重要的
    }最后在OnInitDialog和OnSize中都调用这个Arrange()
      

  5.   

    void CADO1View::OnSize(UINT nType, int cx, int cy)
    {  int iHeight, iWidth; 
      CRect rect;
      COleDBRecordView::OnSize(nType, cx, cy);
      m_adoDC1.GetClientRect(rect);
      iHeight=rect.Height();
      iWidth=rect.Width();
      m_adoDC1.MoveWindow(cx,cy,iWidth,iHeight,TRUE);
      m_dataGrid1.MoveWindow(0,0,cx,cy-iHeight,TRUE);
    }
    m_adoDC1是 ms ado control
    m_dataGrid1是ms datagrid control
    可是程序一运行就出错。