CHtmlView Navigate2 和 ExecWB 执行

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

This is Linking to my previous question.

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

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 some 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() 只会在 App 中生成基于 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);
}

相关文章