Question

I have a MDI application in which there are some reports and the Reports are printed and print preview in way that the was given by the MFC Printing Architecture.

But now the scenario changed and the Reports need to be formatted as a HTML File and need to be shown in the different perspective, based on a preference. I have choose a solution based on the Application architecture as there are many Document/View in my CWinApp. Created all Doc/view Templates there and the new Doc/View will be created based on the setting, once the application starts.

class CMyWinApp: public CWinApp
{
    public:
        virtual BOOL InitInstance();
    protected:

}

BOOL CMyWinApp::InitInstance()
{
    // Lot of Code Here
    CreateDocumentTemplates();
}

void CMyWinApp::CreateDocumentTemplates()
{

    // Some Other Doc/Templates are here


    if(m_bNewView) // Based on the Setting I am creating the new View and Old Doc
    {
        pDocTemplate = new CMultiDocTemplate(
            IDR_REPORTS,
            RUNTIME_CLASS(CMyDoc),
            RUNTIME_CLASS(CMyFrame), // custom MDI child frame
            RUNTIME_CLASS(CMyNewView));
        pDocTemplate->SetContainerInfo(IDR_TYPE_CNTR_IP);
        AddDocTemplate(pDocTemplate);   
    }
    else // This is a Old View and Doc
    {
        pDocTemplate = new CMultiDocTemplate(
            IDR_REPORTS,
            RUNTIME_CLASS(CMyDoc),
            RUNTIME_CLASS(CMyFrame), // custom MDI child frame
            RUNTIME_CLASS(CMyView));
        pDocTemplate->SetContainerInfo(IDR_TYPE_CNTR_IP);
        AddDocTemplate(pDocTemplate);
    }
}

Now the scenario is, this preference can be set anytime and the further Reports need to be shown in a appropriate context.

How this can be achieved on the run time? Please help me :(

Was it helpful?

Solution

In your app class, create and save both CMultiDocTemplate pointers from your CreateDocumentTemplates function and use these to create your documents on demand(e.g override ID_FILE_NEW/ID_FILE_OPEN or similar). Look at OpenDocumentFile of CDocTemplate.

Then in your OnFileNew function or similar you can use something like this: if(m_bNewView) { m_pNewDocTemplate->OpenDocumentFile(...); } else { m_pOldDocTemplate->OpenDocumentFile(...); }

OTHER TIPS

I would integrate CMyNewView in CMyView, if you need to switch the view dynamically. If you work with at least Visuals Studio 2008 (incl. feature pack), I recommend deriving your view class from CTabView to switch the view of the document using a handy tab next to the horizontal scrollbar of the child window.

TabbedView Sample from the Visual C++ 2008 Feature Pack Samples

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top