CHtmlView Navigate2和ExecWB执行

时间:2014-04-24 19:43:17

标签: internet-explorer visual-c++ mfc vc6 print-preview

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

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

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()。

问题在于:

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

我做错了吗?

1 个答案:

答案 0 :(得分:0)

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

我找到了事件OnNavigateComplete2()并覆盖了以下无障碍打印/预览操作。

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

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

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