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 可是程序一运行就出错。
GetDlgItem(IDC_DATAGRID)->GetWindowRect(&rect);
ScreenToClient(&rect);
GetDlgItem(IDC_DATAGRID)->MoveWindow(rect.left,rect.top,rect.right,rect.bottom);
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);
// 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()
{ 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
可是程序一运行就出错。