patrickm
asked on
Creating a new Document from a View
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_chan geDue);
GetDocument()->UpdateAllVi ews(NULL);
OnFilePrint();
//CPosApp::OnFileNew();
//CDocument* pDoc = GetDocument();
//CDocTemplate::CreateNewF rame(pDoc, NULL);
CWinApp::OnFileNew(); // <----- ERROR HERE
}
void CPosView::OnCash()
{
DoTotals();
CTendered dlg;
m_ctlNetDue.SetWindowText(
GetDocument()->UpdateAllVi
OnFilePrint();
//CPosApp::OnFileNew();
//CDocument* pDoc = GetDocument();
//CDocTemplate::CreateNewF
CWinApp::OnFileNew(); // <----- ERROR HERE
}
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(CBiographChi ldFrame), // custom MDI child frame
RUNTIME_CLASS(CBiographVie w));
Now when I want to create a new Doc/View, call OpenDocumentFile.
CDocument* pDoc = pApp->m_pBiographTemplate- >OpenDocum entFile( NULL );
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(CBiographChi
RUNTIME_CLASS(CBiographVie
Now when I want to create a new Doc/View, call OpenDocumentFile.
CDocument* pDoc = pApp->m_pBiographTemplate-
ASKER
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->SetContainer Info(IDR_P OSTYPE_CNT R_IP);
AddDocTemplate(pDocTemplat e);
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()->UpdateAllVi ews(NULL);
OnFilePrint();
CMultiDocTemplate* pApp = CPosApp::pDocTemplate;
CDocument* pDoc = pApp->OpenDocumentFile(NUL L);
CWinApp::OnFileNew();
}
Where specifically do I put the declarations, static members, pointers, etc... to make this happen.
Thanks again for your time
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)
RUNTIME_CLASS(CPosView));
pDocTemplate->SetContainer
AddDocTemplate(pDocTemplat
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()->UpdateAllVi
OnFilePrint();
CMultiDocTemplate* pApp = CPosApp::pDocTemplate;
CDocument* pDoc = pApp->OpenDocumentFile(NUL
CWinApp::OnFileNew();
}
Where specifically do I put the declarations, static members, pointers, etc... to make this happen.
Thanks again for your time
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I'm not sure what the dynamics are exactly, but it works.
Thanks again for all your help.
Pat...
Thanks again for all your help.
Pat...
You're welcome Pat.
Phillip
Phillip
ASKER