Solved

Creating a new Document from a View

Posted on 1998-07-16
6
219 Views
Last Modified: 2013-11-20
I have an MDI application, how do I create a New Document from my View Class.  I have a function in my View Class that does some calculations, then writes to a recordset.  I would then like to close the document in the view and create a new one.  I tried the following, but got an error  'illegal call of non-static member function' and 'cannot access protected member declared in class 'CWinApp''

void CPosView::OnCash()
{
      DoTotals();
      CTendered dlg;
      m_ctlNetDue.SetWindowText(dlg.m_changeDue);
      GetDocument()->UpdateAllViews(NULL);
      OnFilePrint();
      //CPosApp::OnFileNew();
      //CDocument* pDoc = GetDocument();
      //CDocTemplate::CreateNewFrame(pDoc, NULL);

      CWinApp::OnFileNew(); // <----- ERROR HERE
}


0
Comment
Question by:patrickm
  • 3
  • 3
6 Comments
 

Author Comment

by:patrickm
ID: 1319337
Edited text of question
0
 
LVL 7

Expert Comment

by:psdavis
ID: 1319338
A view is tied to a document, you would be creating the view from the document, not vice versa.

One way to accomplish your task is to create additional CMultiDocTemplates in your CWinApp application.  The m_pBiographTemplate in this case is stored within my CWinApp.

m_pBiographTemplate = new CMultiDocTemplate(
  IDR_TENPRINTTYPE,
  RUNTIME_CLASS(CBiographDoc),
  RUNTIME_CLASS(CBiographChildFrame), // custom MDI child frame
  RUNTIME_CLASS(CBiographView));


Now when I want to create a new Doc/View, call OpenDocumentFile.

CDocument* pDoc = pApp->m_pBiographTemplate->OpenDocumentFile( NULL );      


0
 

Author Comment

by:patrickm
ID: 1319339
Thank you for your time. I understand the view is attached to the document. I tried your code snippet, but could not get it to function. I must be missing something simple.

in my App.h

class CPosApp : public CWinApp
{
public:
      CPosApp();
public:
      static CMultiDocTemplate* pDocTemplate;
public:
      virtual BOOL InitInstance();
};

In my App.cpp

CPosApp::CPosApp()
{
}

CPosApp theApp;

BOOL CPosApp::InitInstance()
{
//      CMultiDocTemplate* pDocTemplate;
      pDocTemplate = new CMultiDocTemplate(
            IDR_POSTYPE,
            RUNTIME_CLASS(CPosDoc),
            RUNTIME_CLASS(CChildFrame), // custom MDI  
            RUNTIME_CLASS(CPosView));
      pDocTemplate->SetContainerInfo(IDR_POSTYPE_CNTR_IP);
      AddDocTemplate(pDocTemplate);
etc....
      return TRUE;
}

In my View.cpp

CPosView::CPosView()
      : CFormView(CPosView::IDD)
{
}

CPosView::~CPosView()
{
}

void CPosView::OnCash()
{
      DoTotals();
      CTendered dlg;
      if (dlg.DoModal() == IDCANCEL) return;
      GetDocument()->UpdateAllViews(NULL);
      OnFilePrint();

      CMultiDocTemplate* pApp = CPosApp::pDocTemplate;
      CDocument* pDoc = pApp->OpenDocumentFile(NULL);
      CWinApp::OnFileNew();
}

Where specifically do I put the declarations, static members, pointers, etc... to make this happen.

Thanks again for your time

0
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 
LVL 7

Accepted Solution

by:
psdavis earned 50 total points
ID: 1319340
Ahhh..

1) In your OnCash function.
   The pApp is not pDocTemplate but rather a pointer to your class.

For example:

CPosApp* pApp = (CPosApp*) AfxGetApp( );

2) I haven't used the SetContainerInfo.  Not sure what affect it will have.

3) Remember, you can have several different Doc/View templates added to your CWinApp.  

0
 

Author Comment

by:patrickm
ID: 1319341
I'm not sure what the dynamics are exactly, but it works.
Thanks again for all your help.

Pat...
0
 
LVL 7

Expert Comment

by:psdavis
ID: 1319342
You're welcome Pat.

Phillip

0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Decoding 32 bit binary streams 6 31
format the code in java 6 72
Fibonacci challenge 11 84
wordmultiple challenge 12 90
Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now