对话框与视图
查看了论坛的一些帖子,似乎可以在对话框上追加视图(基于CView、CFormView、CScrollView),
想要求助的问题:
1、对话框上是否可以放置视图
2、在对话框的Class内容如何实现放置一个视图
以上
[解决办法]
#include "MyScrollView.h"
BOOL CViewDlg::OnInitDialog()
{
CDialog::OnInitDialog();
CRect rect;
GetWindowRect(rect);//获取对话框窗口尺寸
CRuntimeClass *pViewClass=RUNTIME_CLASS(CMyScrollView);
CCreateContext* pContext;
pContext=new CCreateContext;
pContext->m_pCurrentDoc=NULL;
pContext->m_pCurrentFrame=NULL;
pContext->m_pLastView=NULL;
pContext->m_pNewDocTemplate=NULL;
pContext->m_pNewViewClass=pViewClass;
//CWnd *pWnd=NULL;
m_pWnd=DYNAMIC_DOWNCAST(CWnd,pViewClass->CreateObject());//创建视图窗口
m_pWnd->Create(NULL,NULL,AFX_WS_DEFAULT_VIEW,CRect(0,0,0,0),this,0,pContext);
delete pContext;
CMyScrollView *pScrollView=DYNAMIC_DOWNCAST(CMyScrollView,m_pWnd);
//设置视图的滚动条范围
pScrollView->SetScrollSizes(MM_TEXT,CSize(rect.Width()-20,rect.Height()-80));
//设置视图的位置和大小
pScrollView->MoveWindow(rect.left+10,rect.top+110,rect.Width()-125,rect.Height()-150,TRUE);
// Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE);// Set big icon
SetIcon(m_hIcon, FALSE);// Set small icon
// TODO: Add extra initialization here
return TRUE; // return TRUE unless you set the focus to a control
}