1 派生一个CDocument类,并设置对话框为该类的友元,如:
class CXXDlg;
class CMyDocument : public CDocument
{
DECLARE_DYNCREATE(CMyDocument)
friend class CXXDlg;
public:
CMyDocument();
virtual ~CMyDocument();
#ifndef _WIN32_WCE
virtual void Serialize(CArchive& ar); // 为文档 I/O 重写
#endif
#ifdef _DEBUG
virtual void AssertValid() const;
#ifndef _WIN32_WCE
virtual void Dump(CDumpContext& dc) const;
#endif
#endif
protected:
virtual BOOL OnNewDocument();
DECLARE_MESSAGE_MAP()
};
2 派生一个CDocument类,并设置对话框为该类的友元,如:
class CXXDlg;
class CMyLogShView : public CHtmlView
{
DECLARE_DYNCREATE(CMyLogShView)
friend class CXXDlg;
protected:
CMyLogShView(); // 动态创建所使用的受保护的构造函数
virtual ~CMyLogShView();
public:
#ifdef _DEBUG
virtual void AssertValid() const;
virtual void Dump(CDumpContext& dc) const;
#endif
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV 支持
DECLARE_MESSAGE_MAP()
};
3 在CXXDlg中定义一个创建HTMLVIEW的函数(当然你也可以不用定义):
CMyLogShView* CXXDlg::CreateMyLogShView(void)
{
CCreateContext pContext;
CWnd* pFramewnd = this;
pContext.m_pCurrentDoc = new CMyDocument;
pContext.m_pNewViewClass = RUNTIME_CLASS(CMyLogShView);
CMyLogShView *pMyLogShView =
(CMyLogShView *)((CFrameWnd*)pFramewnd)->CreateView(&pContext);
if (pMyLogShView == NULL)
{
return NULL;
}
pMyLogShView->ShowWindow(SW_NORMAL);
CRect rectWindow;
GetWindowRect(rectWindow);
rectWindow.left -= 5;
rectWindow.right += 15;
rectWindow.top -= 22; //这些是用来设置htmlview的位置的,可以任意设置个人认为合理的
pMyLogShView->MoveWindow(rectWindow);
return pMyLogShView;
}
我是在CXXDlg的OnInitDialog()函数中调用CreateMyLogShView()的,如下:
BOOL CXXDlg::OnInitDialog()
{
CDialog::OnInitDialog();
.....
.....
......
// TODO: 在此添加额外的初始化
CMyLogShView* pMyLogShView;
pMyLogShView = CreateMyLogShView();
return TRUE; // return TRUE unless you set the focus to a control
}
本文详细介绍了如何派生CDocument类,并将其与对话框设置为友元,进而自定义文档视图。通过实现动态创建特定视图类并调整其显示位置,实现灵活的文档视图管理。
1645

被折叠的 条评论
为什么被折叠?



