CHtmlView Navigate2和ExecWB执行 [英] CHtmlView Navigate2 and ExecWB Execution

查看:238
本文介绍了CHtmlView Navigate2和ExecWB执行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是链接到我之前的问题.

This is Linking to my previous question.

我已经设法为应用程序生成的报告的新类型的视图创建了一个从CHtmlView派生的新视图,但是我在新的视图中发现了soem问题

I have managed to make a new view derived from the CHtmlView for the new type of View for the my application generated reports but I find soem problem in the new View

class CMyHtmlView : public CHtmlView
{
protected: // create from serialization only
    CMyHtmlView();
    DECLARE_DYNCREATE(CMyHtmlView)

// Attributes
public:
    CReportDoc* GetDocument();

    CString          m_sFileName;

// Operations
public:

// Overrides
    // ClassWizard generated virtual function overrides
    //{{AFX_VIRTUAL(CMyHtmlView)
    public:
    virtual void OnDraw(CDC* pDC);  // overridden to draw this view
    virtual BOOL PreCreateWindow(CREATESTRUCT& cs);
    protected:
    virtual void OnInitialUpdate(); // called first time after construct
    virtual void OnFilePrintPreview();
    virtual void OnFilePrint();
    //}}AFX_VIRTUAL

// Implementation
public:
    virtual ~CMyHtmlView();
    //{{AFX_MSG(CMyHtmlView)
        // NOTE - the ClassWizard will add and remove member functions here.
    //}}AFX_MSG
    DECLARE_MESSAGE_MAP()
};

void CMyHtmlView::OnFilePrintPreview()
{   
    // Before this I will call a Function Generate a HTML File in a Location and Updated in m_sFileName
    Navigate2(m_sFileName);
    ExecWB(OLECMDID_PRINTPREVIEW, OLECMDEXECOPT_PROMPTUSER, NULL, NULL );
}

void CMyHtmlView::OnInitialUpdate()
{
    CHtmlView::OnInitialUpdate();
    Navigate2(_T("about:blank"));
}

void CMyHtmlView::OnFilePrint()
{
    // Before this I will call a Function Generate a HTML File in a Location and Updated in m_sFileName
    Navigate2(m_sFileName,NULL,NULL);
    CHtmlView::OnFilePrint();
}

在此打印中,OnFilePrint()可以正常工作.但是问题出在OnFilePrintPreview()中.

In this Printing OnFilePrint() is working without any problem. But the problem exists in the OnFilePrintPreview().

问题出在这里

在Navigate()之后调用ExecWB()时,仅在应用程序中创建基于HTML视图的窗口,没有显示打印预览窗口

On Calling ExecWB() after a Navigate() makes only the HTML view based Window in the App, no print preview window been shown

我做错什么了吗?

推荐答案

我找到了解决Navigate()之后打印"和打印预览"问题的方法.正如user1793036所提到的,这是一个异步调用,我需要等待该操作完成.这就是打印预览和打印"正在加载空白页面的原因.

I found out a way to end the problem with Print and Print Preview after Navigate(). As user1793036 mentioned it is an asynchrous call and I need to wait for that operation to complete. This is the reason that the Print Preview and Print is loading an empty page.

我发现了事件 OnNavigateComplete2(),并为以下内容进行了覆盖轻松的打印/预览操作.

I found the event OnNavigateComplete2() and overridden as below for the hassle free Print/preview operations.

void CMyHtmlView::OnNavigateComplete2(LPCTSTR strURL)
{
    if(m_ePrintMode == PREVIEW)
        ExecWB(OLECMDID_PRINTPREVIEW, OLECMDEXECOPT_PROMPTUSER, NULL, NULL );
    else if(m_ePrintMode == PRINT)
        CHtmlView::OnFilePrint();
    else
        return;
}

并将我的打印"和打印预览"事件修改为

And modified my Print and Print Preview events as

void CMyHtmlView::OnFilePrintPreview()
{
    OnSaveHtmlReport();

    m_ePrintMode = PREVIEW; // an Enum

    Navigate2(m_sFileName);
}

void CMyHtmlView::OnFilePrint()
{
    OnSaveHtmlReport();

    m_ePrintMode = PRINT; // an Enum

    Navigate2(m_sFileName,NULL,NULL);
}

这篇关于CHtmlView Navigate2和ExecWB执行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆