• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 235
  • Last Modified:

Creating MDI application for the First time!

Im having 2Views, 2Docs and 2childframes
I also got 2 menu-items hooked to 2 different forms (say one Form for persons'details and another Form for company's details). How can i invoke these forms? (Ive got the Form's Id message-maps to the menu), but what code invoke the form??
Something like: OpenDocumentFile(NULL)
I havnt got a clue and im lost to begin with!!
0
coldest
Asked:
coldest
  • 3
  • 2
1 Solution
 
ZoppoCommented:
Hi coldest,

Creating a new document is done via CDocumentTemplate::CreateNewDocument().
i.e.:

class CMyApp:: public CWinApp {
....
 CMultiDocTemplate *m_pFormTemplate1;
 CMultiDocTemplate *m_pFormTemplate2;
....
};

CMyApp::InitInstance(...)
{
....
m_pFormTemplate1 = new CMultiDocTemplate(
            IDR_FORM1,
            RUNTIME_CLASS(CForm1Doc),
            RUNTIME_CLASS(CForm1Frame),
            RUNTIME_CLASS(CForm1View)
);
AddDocTemplate(m_pFormTemplate1);
m_pFormTemplate2 = new CMultiDocTemplate(
            IDR_FORM2,
            RUNTIME_CLASS(CForm2Doc),
            RUNTIME_CLASS(CForm2Frame),
            RUNTIME_CLASS(CForm2View)
);
AddDocTemplate(m_pFormTemplate2);
....
}

CMyApp::OnAddForm1Doc() // message handler for menu
{
 m_pFormTemplate1->CreateNewDocument(); // create a new document with a view and a child frame
 ...
}

CMyApp::OnAddForm2Doc() // message handler for menu
{
 m_pFormTemplate2->CreateNewDocument(); // create a new document with a view and a child frame
 ...
}

hope that helps,

ZOPPO
0
 
inprasCommented:
Here is a sample code to add templates
      pDocTemplate5 = new CMultiDocTemplate(
            IDR_STATUSVIEW,
            RUNTIME_CLASS(CAppsDoc),
            RUNTIME_CLASS(CChildFrm4), // custom MDI child frame
            RUNTIME_CLASS(CStatusView));

      pDocTemplate6 = new CMultiDocTemplate(
            IDR_STATISTICSVIEW,
            RUNTIME_CLASS(CAppDoc),
            RUNTIME_CLASS(CChildFrm5), // custom MDI child frame
            RUNTIME_CLASS(CStatisticsView));

------------------------------------------
this is how U a document
      CString strDocName;
      CDocTemplate* pSelectedTemplate;
      POSITION pos = GetFirstDocTemplatePosition();
      while(pos != NULL)
      {
            pSelectedTemplate = (CDocTemplate*)GetNextDocTemplate(pos);
            ASSERT(pSelectedTemplate != NULL);
            ASSERT(pSelectedTemplate -> IsKindOf(RUNTIME_CLASS(CDocTemplate)));
            pSelectedTemplate -> GetDocString(strDocName, CDocTemplate :: docName);
            if (strDocName == str)
            {
                  pSelectedTemplate -> OpenDocumentFile(NULL);
                  return TRUE;
            }
      }
0
 
coldestAuthor Commented:
Thanks a lot zoppo and inpras,
Dear zoppo, I've still got this tiny problem: I cannot invoke my second form using menu!!

-------------This is your fragment---  
CMyApp::OnAddForm2Doc() // message handler for menu
{
 m_pFormTemplate2->CreateNewDocument(); // create a new document with a view and a child frame
 ...
}
------------------------
and I've tried it and nothing is happend!
0
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
ZoppoCommented:
Sorry, forgot to mention following:

the frame is by default created invisible and OnInitialUpdate of the new child is not called. To do this correct do following:

CMyApp::OnAddForm2Doc() // message handler for menu
{
CDocument *pDoc = m_pFormTemplate2->CreateNewDocument();
CFrameWnd *pNewFrame = m_pFormTemplate2->CreateNewFrame( pDoc, NULL );
pFormTemplate2->InitialUpdateFrame( pNewFrame, pDoc, TRUE );
....
}

hope this work now,

ZOPPO
0
 
coldestAuthor Commented:
Sorry Zoppo, it didnt work and im even more confused!!
It crashes. When i debugged it, on the second line: CreateNewFrame(...)..
it takes me to the Create() function:

//virtual override of CWnd::Create
BOOL CFormView::Create(...)
{
 ......
 //dialog template must exist and be    //invisible with WS_CHILD

ASSERT(FALSE)//invalid dialog template  
              // name

 .....
}


any ideal?

Let me tell you about my classes:

(CChildFrame, CMainFrame, CMDIprogApp)

Two sets of doc,view,frame:

(CMDIprogDoc,CMDIprogView,CMDIprogFrame)
(Cprog2Doc  ,Cprog2View  ,Cprog2Frame)

views base class is     CFormView
frames base class is    CMDIChildWnd
ducs base calss is      CDocument

am i doing something wrong? or could you send me a sample please....

thanks a lot zoppo
yours
coldest
0
 
ZoppoCommented:
please send me your e-mail to zoppo@cdsgmbh.de, then I'll send you a sample project...
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now