Question

This is Linking to my previous question.

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

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

Here is the problem:

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

Am I doing anything wrong?

Was it helpful?

Solution

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.

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);
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top