void CMDI_csdnView::OnInitialUpdate() { CView::OnInitialUpdate(); CFrameWnd *pFrame=this->GetParentFrame(); if(pFrame) { pFrame->SetWindowPos(NULL,0,0,160,160,SWP_NOZORDER); } // TODO: Add your specialized code here and/or call the base class }
// 多文档工程下面 BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs) { if( !CFrameWnd::PreCreateWindow(cs) ) return FALSE; // TODO: Modify the Window class or styles here by modifying // the CREATESTRUCT cs cs.cx = 100; cs.cy= 100; return TRUE; }
A:通常,你可以调用函数MoveWindow()或者SetWindowPos()来改变窗口的大小。在用MFC库开发的应用程序中, 视图是被框架窗口所围绕的一个子窗口。为了改变一个视图的大小,你可以通过在视图的InitialUpdate(...)中调用函数GetParentFrame()来得到框架窗口的指针,然后调用函数MoveWindow()/SetWindowPos()来改变父窗口的大小。当父框架窗口改变大小时,视图也会自动地改变大小来适应父窗口。
{
CView::OnInitialUpdate(); CFrameWnd *pFrame=this->GetParentFrame();
if(pFrame)
{
pFrame->SetWindowPos(NULL,0,0,160,160,SWP_NOZORDER);
}
// TODO: Add your specialized code here and/or call the base class
}
BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
{
if( !CFrameWnd::PreCreateWindow(cs) )
return FALSE;
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
cs.cx = 100;
cs.cy= 100;
return TRUE;
}
{
if( !CFrameWnd::PreCreateWindow(cs) )
return FALSE;
cs.style&=WS_POPUPWINDOW;
cs.cx=160;
cs.cy=160;
return TRUE;
}