在CFormView或对话框中动态添加CScrollView、CFormView
来源:互联网 发布:华为sim卡网络解锁nck 编辑:程序博客网 时间:2024/05/29 03:18
本代码可以在CFormView中,根据事先画好的控件位置创建CScrollView
也可以在CDialog中创建CScrollView、CFormView等
注:
若以下代码放在CMainRightView::OnCreate(LPCREATESTRUCT lpCreateStruct)内,则GetDlgItem()函数将调用失败,因为此时控件都还未被创建!
void CMainRightView::OnInitialUpdate()
...{
CFormView::OnInitialUpdate();
// TODO: Add your specialized code here and/or call the base class
//获得目标位置控件
UINT TargetCtrlID = IDC_STATIC_SCROLLVIEW;
CWnd *pWnd = this->GetDlgItem(TargetCtrlID);
CRect RectTargetCtrl;
pWnd->GetWindowRect(RectTargetCtrl);
pWnd->DestroyWindow();
this->ScreenToClient(RectTargetCtrl);
//在目标位置动态创建CScrollView
CEMapView *pEMapView = (CEMapView*)RUNTIME_CLASS(CEMapView)->CreateObject();
pEMapView->Create(NULL, NULL, AFX_WS_DEFAULT_VIEW, RectTargetCtrl, this, TargetCtrlID);
//使用CreateView创建的视图 不能自动调用OnInitialUpdate函数,需要人工调用OnInitialUpdate函数或者发送 WM_INITIALUPDATE消息
pEMapView->OnInitialUpdate();
//SetScrollSizes()必须被调用,否则运行时会出ASSERT错误,当然,也可以在目标View内的OnInitialUpdate()中调用
pEMapView->SetScrollSizes(MM_TEXT, CSize(RectTargetCtrl.Width()-10, RectTargetCtrl.Height()-10));
// 使用CreateView创建的视图不会自动显示并且激活,需要人工操作
pEMapView->ShowWindow(SW_SHOW);
}
...{
CFormView::OnInitialUpdate();
// TODO: Add your specialized code here and/or call the base class
//获得目标位置控件
UINT TargetCtrlID = IDC_STATIC_SCROLLVIEW;
CWnd *pWnd = this->GetDlgItem(TargetCtrlID);
CRect RectTargetCtrl;
pWnd->GetWindowRect(RectTargetCtrl);
pWnd->DestroyWindow();
this->ScreenToClient(RectTargetCtrl);
//在目标位置动态创建CScrollView
CEMapView *pEMapView = (CEMapView*)RUNTIME_CLASS(CEMapView)->CreateObject();
pEMapView->Create(NULL, NULL, AFX_WS_DEFAULT_VIEW, RectTargetCtrl, this, TargetCtrlID);
//使用CreateView创建的视图 不能自动调用OnInitialUpdate函数,需要人工调用OnInitialUpdate函数或者发送 WM_INITIALUPDATE消息
pEMapView->OnInitialUpdate();
//SetScrollSizes()必须被调用,否则运行时会出ASSERT错误,当然,也可以在目标View内的OnInitialUpdate()中调用
pEMapView->SetScrollSizes(MM_TEXT, CSize(RectTargetCtrl.Width()-10, RectTargetCtrl.Height()-10));
// 使用CreateView创建的视图不会自动显示并且激活,需要人工操作
pEMapView->ShowWindow(SW_SHOW);
}
注:如果需要在CDialog中创建CScrollView、CFormView,则需要overload、override这些View中以下的4个方法,否则会出ASSERT错误
afx_msg int OnMouseActivate(CWnd* pDesktopWnd, UINT nHitTest, UINT message);
afx_msg void OnDestroy();
virtual void PostNcDestroy();
virtual void OnActivateFrame(UINT nState, CFrameWnd* pDeactivateFrame);
afx_msg void OnDestroy();
virtual void PostNcDestroy();
virtual void OnActivateFrame(UINT nState, CFrameWnd* pDeactivateFrame);
int CFormViewPrint::OnMouseActivate(CWnd* pDesktopWnd, UINT nHitTest, UINT message)
{
// TODO: Add your message handler code here and/or call default
return CWnd::OnMouseActivate(pDesktopWnd, nHitTest, message);
}
void CFormViewPrint::OnDestroy()
{
CWnd::OnDestroy();
// TODO: Add your message handler code here
}
void CFormViewPrint::PostNcDestroy()
{
// TODO: Add your specialized code here and/or call the base class
CWnd::PostNcDestroy();
}
void CFormViewPrint::OnActivateFrame(UINT nState, CFrameWnd* pDeactivateFrame)
{
// TODO: Add your specialized code here and/or call the base class
CWnd::OnActivateFrame(nState, pDeactivateFrame);
}
{
// TODO: Add your message handler code here and/or call default
return CWnd::OnMouseActivate(pDesktopWnd, nHitTest, message);
}
void CFormViewPrint::OnDestroy()
{
CWnd::OnDestroy();
// TODO: Add your message handler code here
}
void CFormViewPrint::PostNcDestroy()
{
// TODO: Add your specialized code here and/or call the base class
CWnd::PostNcDestroy();
}
void CFormViewPrint::OnActivateFrame(UINT nState, CFrameWnd* pDeactivateFrame)
{
// TODO: Add your specialized code here and/or call the base class
CWnd::OnActivateFrame(nState, pDeactivateFrame);
}
原因可参考
View和Control的区别(如何在对话框上使用CView类)
http://www.seeitco.com/doc/Html/Visual%20C++/205707715.html
- 在CFormView或对话框中动态添加CScrollView、CFormView
- MFC中添加一张图片作为对话框(或CFormView)的背景
- CFormView
- 在CDockablePane中嵌入CFormView
- 在CFormView中如何让对话框内的控件大小跟随单文档的大小变化
- MFC中CFormView
- 浮动dockpane中cFormView对话框断言报错
- CFormView用法注意 CFormView对话框的格式设置
- MFC MDI在CFormView中当前关闭窗口的代码
- CFormView类关联对话框资源的问题
- 对话框中添加视图方法- CScrollView
- CFormView动态调整对话框的尺寸并成比例调整部署控件
- CFormView简介
- CFormView简介
- CFormView简介
- CFormView简介
- 在对话框中应用CScrollView显示图像
- EasySize宏在CFormView类中的使用
- 毕业设计的设计部分笔记5,高阶设计2
- 用不起Windows专辑(一) ---- 软件集锦(1.0)
- 女足 . IT . 技术
- {JS}JavaScript使用正则表达式
- 配置应用Visual C++ 2005 Express和MASM 8.0的汇编源环境
- 在CFormView或对话框中动态添加CScrollView、CFormView
- 北京网民网上开店要公示实名身份
- Visual Studio 2008 安装失败(“Web 创作组件”无法安装)的解决办法
- 最强烈推荐-我的java收藏夹
- 不可逆转的开源时代----未来值得关注十大潜力开源项目(转自LUPA)
- WordNet发展概况
- CTO如何识别优秀的程序员
- Photoshop菜单中英文对照
- C++程序员转行Symbian开发测试题