在Dialog中创建一个htmlview(CHtmlView类)区,实现浏览网页

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;
}

 

我是在CXXDlgOnInitDialog()函数中调用CreateMyLogShView()的,如下:

BOOL CXXDlg::OnInitDialog()
{
    CDialog::OnInitDialog();

    .....

    .....

    ......

    // TODO:  在此添加额外的初始化

    CMyLogShView* pMyLogShView;

    pMyLogShView = CreateMyLogShView();

    return TRUE;  // return TRUE unless you set the focus to a control
}

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值