哈哈,幸亏遇到我了:
===》
使用ScrollView,在OnInitUpdate中添加如下代码
加入指定高度和宽度h,w.
// 设置包容窗体尺寸
CMainFrame *pFrame=(CMainFrame*)AfxGetMainWnd();
ASSERT_KINDOF(CMainFrame,pFrame);
CRect rc;
pFrame->GetClientRect(&rc);
if(rc.Width()>=w&&rc.Height()>=h&&(w>0||h>0))
ResizeParentToFit(FALSE);
===》
使用ScrollView,在OnInitUpdate中添加如下代码
加入指定高度和宽度h,w.
// 设置包容窗体尺寸
CMainFrame *pFrame=(CMainFrame*)AfxGetMainWnd();
ASSERT_KINDOF(CMainFrame,pFrame);
CRect rc;
pFrame->GetClientRect(&rc);
if(rc.Width()>=w&&rc.Height()>=h&&(w>0||h>0))
ResizeParentToFit(FALSE);
cs.style &= ~WS_THICKFRAME;
(加在第一句,也就是CFrameWnd::PreCreateWindow(cs)之前)
void CMainFrame::OnGetMinMaxInfo(MINMAXINFO FAR* lpMMI)
{
// TODO: Add your message handler code here and/or call default
lpMMI->ptMinTrackSize.x=40;
lpMMI->ptMinTrackSize.y=20;
lpMMI->ptMaxTrackSize.x=430;
lpMMI->ptMaxTrackSize.y=210;//220;//210; //210 for no menu! CFrameWnd::OnGetMinMaxInfo(lpMMI);
}
(1)在mianfrm.h和ChildFrm.h中增加两个整形变量,用于保存窗口的高度和宽度。
int iHeight;
int iWidth;
(2)对BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)和BOOL CChildFrame::PreCreateWindow(CREATESTRUCT& cs)
重载。
BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
{
cs.cx=200;
cs.cy=350;
iHeight=cs.cy;
iWidth=cs.cx;
//移去极大化按钮
cs.style^=WS_MAXIMIZEBOX;
return CFrameWnd::PreCreateWindow(cs);
}
BOOL CChildFrame::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs cs.cx=100;
cs.cy=150;
iHeight=cs.cy;
iWidth=cs.cx;
cs.style^=WS_MAXIMIZEBOX;
return CMDIChildWnd::PreCreateWindow(cs) ;
}
(3)定义void CMainFrame::OnSize()函数和void CChildFrame::OnSize()函数
void CChildFrame::OnSize(UINT nType, int cx, int cy)
{
CMDIChildWnd::OnSize(nType, cx, cy);
SetWindowPos(&wndTop,0,0,iWidth,iHeight,SWP_NOMOVE);
// TODO: Add your message handler code here
}
void CMainFrame::OnSize(UINT nType, int cx, int cy)
{
CFrameWnd::OnSize(nType, cx, cy);
// TODO: Add your message handler code here
SetWindowPos(&wndTop,0,0,iWidth,iHeight,SWP_NOMOVE);
}
这样旧可以实现了。我已经试过了。