15 мая 2023 года "Исходники.РУ" отмечают своё 23-летие!
Поздравляем всех причастных и неравнодушных с этим событием!
И огромное спасибо всем, кто был и остаётся с нами все эти годы!

Главная Форум Журнал Wiki DRKB Discuz!ML Помощь проекту


MDI Document Template with Multiple View

ГЦ °ж ·Д -- listen@klnet.co.kr
Friday, December 13, 1996

Environment : MSVC++ 4.0, Windows 95
Hello! 
I made an BBS Application that uses 3 Views and one Document type.
One of 3 Views is CScrollView and the rest of them is CFormView.
Here is My Source

	m_pTemplate1 = new CMultiDocTemplate(
		IDR_HANTYPE,
		RUNTIME_CLASS(CHanDoc),
		RUNTIME_CLASS(CChildFrame),
		RUNTIME_CLASS(CHanView));

	m_pTemplate2 = new CMultiDocTemplate(
		IDR_HANTYPE,
		RUNTIME_CLASS(CHanDoc),
		RUNTIME_CLASS(CChildFrame),
		RUNTIME_CLASS(CMyMenuView));

	m_pTemplate3 = new CMultiDocTemplate(
		IDR_HANTYPE,
		RUNTIME_CLASS(CHanDoc),
		RUNTIME_CLASS(CChildFrame),
		RUNTIME_CLASS(CMailForm));

	// create main MDI Frame window
	CMainFrame* pMainFrame = new CMainFrame;
	if (!pMainFrame->LoadFrame(IDR_MAINFRAME))
		return FALSE;
	m_pMainWnd = pMainFrame;

	// Parse command line for standard shell commands, DDE, file open
	CCommandLineInfo cmdInfo;
	ParseCommandLine(cmdInfo);

	// Dispatch commands specified on the command line
	if (!ProcessShellCommand(cmdInfo))
		return FALSE;

	// The main window has been initialized, so show and update it.
	pMainFrame->ShowWindow(m_nCmdShow);
	pMainFrame->UpdateWindow();

	AddDocTemplate(m_pTemplate1);

m_pTemplate1,m_pTemplate2,m_pTemplate3 is declared in Application
Object Class.

As you can see, I use main m_pTemplate1 as my application's
main Document Template. It means OnFileOpen and OnFileNew Function is
only supported for m_pTemplate1. And another 2 Views are manually
constructed with m_pTemplate2 and m_pTemplate3.

Problem is that if I close a MDI Child Window that created with
m_pTemplate1 and no Windows that has this type left, then creation of
MDI Child Window raise error.

So I want to have all control for Document Templates that I created.
But I don't know how to do that.
If Anyone knows about this or has this problem before, please
let me know.



Mike Blaszczak -- mikeblas@nwlink.com
Sunday, December 15, 1996

At 11:25 12/13/96 +0900,  wrote:
>Environment : MSVC++ 4.0, Windows 95

>As you can see, I use main m_pTemplate1 as my application's
>main Document Template. It means OnFileOpen and OnFileNew Function is
>only supported for m_pTemplate1. And another 2 Views are manually
>constructed with m_pTemplate2 and m_pTemplate3.

>Problem is that if I close a MDI Child Window that created with
>m_pTemplate1 and no Windows that has this type left, then creation of
>MDI Child Window raise error.

What error?  At runtime, or at compile time?  Is it an assertion, or
an exception?  What user interface command are you using to create
the MDI child window?  What code is it hooked to?  Can you show us
that code? What specific line of code is causing the problem?  What's
the  exact message you get from the compiler when it happens?  Or,
what's the exact message you get from the program or the operating
system when the error happens?  What's the stack trace (with symbols!)
tell you?

How can you possilbly exepct an answer from such a vague, incomplete
question?

.B ekiM
http://www.nwlink.com/~mikeblas/
I'm afraid I've become some sort of speed freak.
These words are my own. I do not speak on behalf of Microsoft.




Daniel Munoz -- dmunoz@socabim.fr
Tuesday, December 17, 1996

Environment: VC++ 4.2, Win 95, NT 3.51, NT 4.00

Hi,

I have a project with the same kind of thing: 1 document, 2 different
views, only one can be openned.

You can try to register all the views (call 3 times AddDocTemplate), and
say in the string resource that you don't want to open the document with
the standard dialog box.

IDR_SHEETTYPE "\nSheet\nWorksheet\nWorksheets (*.myc)\n.myc\n
MyCalcSheet\nMyCalc Worksheet"

To do that, just delete the second work of the string like this

IDR_SHEETTYPE "\nSheet\n\nWorksheets (*.myc)\n.myc\n MyCalcSheet\nMyCalc
Worksheet"


Daniel Munoz
dmunoz@socabim.fr




Dave Kolb -- sasdxk@wnt.sas.com
Thursday, December 19, 1996

[Mini-digest: 3 responses]



>----------
>From: 	Daniel Munoz[SMTP:dmunoz@socabim.fr]
>Sent: 	Tuesday, December 17, 1996 6:27 AM
>To: 	mfc-l@netcom.com
>Subject: 	Re: MDI Document Template with Multiple View
>
>Environment: VC++ 4.2, Win 95, NT 3.51, NT 4.00
>
>Hi,
>
>I have a project with the same kind of thing: 1 document, 2 different
>views, only one can be openned.
>
>You can try to register all the views (call 3 times AddDocTemplate), and
>say in the string resource that you don't want to open the document with
>the standard dialog box.
>
>IDR_SHEETTYPE "\nSheet\nWorksheet\nWorksheets (*.myc)\n.myc\n
>MyCalcSheet\nMyCalc Worksheet"
>
>To do that, just delete the second work of the string like this
>
>IDR_SHEETTYPE "\nSheet\n\nWorksheets (*.myc)\n.myc\n MyCalcSheet\nMyCalc
>Worksheet"

This doesn't seem to work for OLE servers as there is an ASSERT if this
substring is left out. And of course I need some way to NOT allow
creation of new documents for embedded servers like when you do an
Office Binder Insert Section (My app is a Viewer) as I only support
create from file for this appliation. Any ideas why this substring is
demanded by UpdateRegistry and AfxOleRegisterServerClass? Any way around
needing this substring or not creating new embedded server documents?
See code below that asserts in MFC 4.2b:


Dave Kolb
PC Research and Development
SAS Institute Inc.
919-677-8000 x6827

void COleTemplateServer::UpdateRegistry(OLE_APPTYPE nAppType,
	LPCTSTR* rglpszRegister, LPCTSTR* rglpszOverwrite)
{
...
	if (!m_pDocTemplate->GetDocString(strLocalShortName,
		CDocTemplate::fileNewName))
		strLocalShortName = strLocalServerName; // use long name
...
	// place entries in system registry
	if (!AfxOleRegisterServerClass(m_clsid, strServerName,
		strLocalShortName, strLocalServerName, nAppType,
		rglpszRegister, rglpszOverwrite, nIconIndex, strLocalFilterName))
	{
		// not fatal (don't fail just warn)
		AfxMessageBox(AFX_IDP_FAILED_TO_AUTO_REGISTER);
	}
}

BOOL AFXAPI AfxOleRegisterServerClass(
	REFCLSID clsid, LPCTSTR lpszClassName, LPCTSTR lpszShortTypeName,
	LPCTSTR lpszLongTypeName, OLE_APPTYPE nAppType, LPCTSTR*
rglpszRegister,
	LPCTSTR* rglpszOverwrite, int nIconIndex,
	LPCTSTR lpszFilterName)
{
	ASSERT(AfxIsValidString(lpszClassName));
	ASSERT(AfxIsValidString(lpszShortTypeName));
	ASSERT(*lpszShortTypeName != 0);
...
>
-----From: kvasilak@cyberoptics.com

     =

Here is a solution I found in "Essential Visual C++ 4". I have modified i=
t to =

close the previous frame AFTER creating the new one..

The first code fragment,OnFileMag(), is called in response to a toolbar b=
utton =

press. The Second Fragment just returns the CMultiDocTemplate pointer, =

m_pTemplate2 or such.


void CMainFrame::OnFileMag() =

{
   CFrameWnd *pOldFrame;

   CMDIChildWnd *pActiveChild =3D MDIGetActive();
   if( pActiveChild !=3D0 )
   {
      CDocument *pDocument =3D pActiveChild->GetActiveDocument();
      if( pDocument !=3D0)
      {

         CBuildApp   *pApp =3D (CBuildApp *)AfxGetApp();
         CDocTemplate  *pTemp;
         CFrameWnd    *pFrame;
         =

         //Get a pointer to the previous frame So we can close it
         pOldFrame =3D GetActiveFrame( ); =


         pTemp =3D pApp->GetMagTemplate();//This selects what doc templat=
e to use
         pFrame =3D pTemp->CreateNewFrame(pDocument,pActiveChild);
         if(pFrame !=3D0 )
         {
            //Kill that old frame so we dont have it lying around unsued
            pOldFrame->SendMessage(WM_CLOSE);
            pTemp->InitialUpdateFrame(pFrame,pDocument);
         }

      }
   }

}

// @mfunc Returns a pointer to the CMultiDocTemplate created in =

().
// @rdesc Returns CDocTemplate *
CDocTemplate *CBuildApp::GetMagTemplate() const
{
        return m_pMagTemplate;
}


Keith V
______________________________ Reply Separator __________________________=
_______
Subject: MDI Document Template with Multiple View
Author:  AT o` =A3_  at INTERNET
Date:    12/13/96 11:25 AM


Environment : MSVC++ 4.0, Windows 95 =

Hello! =

I made an BBS Application that uses 3 Views and one Document type. =

One of 3 Views is CScrollView and the rest of them is CFormView. =

Here is My Source
     =

        m_pTemplate1 =3D new CMultiDocTemplate(
                IDR_HANTYPE,
                RUNTIME_CLASS(CHanDoc),
                RUNTIME_CLASS(CChildFrame),
                RUNTIME_CLASS(CHanView));
     =

        m_pTemplate2 =3D new CMultiDocTemplate(
                IDR_HANTYPE,
                RUNTIME_CLASS(CHanDoc),
                RUNTIME_CLASS(CChildFrame),
                RUNTIME_CLASS(CMyMenuView));
     =

        m_pTemplate3 =3D new CMultiDocTemplate(
                IDR_HANTYPE,
                RUNTIME_CLASS(CHanDoc),
                RUNTIME_CLASS(CChildFrame),
                RUNTIME_CLASS(CMailForm));
     =

        // create main MDI Frame window
        CMainFrame* pMainFrame =3D new CMainFrame; =

        if (!pMainFrame->LoadFrame(IDR_MAINFRAME))
                return FALSE;
        m_pMainWnd =3D pMainFrame;
     =

        // Parse command line for standard shell commands, DDE, file open=
 =

        CCommandLineInfo cmdInfo;
        ParseCommandLine(cmdInfo);
     =

        // Dispatch commands specified on the command line =

        if (!ProcessShellCommand(cmdInfo))
                return FALSE;
     =

        // The main window has been initialized, so show and update it. =

        pMainFrame->ShowWindow(m_nCmdShow);
        pMainFrame->UpdateWindow();
     =

        AddDocTemplate(m_pTemplate1);
     =

m_pTemplate1,m_pTemplate2,m_pTemplate3 is declared in Application =

Object Class.
     =

As you can see, I use main m_pTemplate1 as my application's
main Document Template. It means OnFileOpen and OnFileNew Function is =

only supported for m_pTemplate1. And another 2 Views are manually =

constructed with m_pTemplate2 and m_pTemplate3.
     =

Problem is that if I close a MDI Child Window that created with =

m_pTemplate1 and no Windows that has this type left, then creation of =

MDI Child Window raise error.
     =

So I want to have all control for Document Templates that I created. =

But I don't know how to do that.
If Anyone knows about this or has this problem before, please =

let me know.
-----From: kvasilak@cyberoptics.com

     Environment : MSVC++ 4.1, Windows 95
     =

     Here is a solution I found in "Essential Visual C++ 4". I have =

     modified it to close the previous frame AFTER creating the new one..=

     =

     The first code fragment,OnFileMag(), is called in response to a =

     toolbar button press. The Second Fragment just returns the =

     CMultiDocTemplate pointer, m_pTemplate2 or such.
     =

     =

     void CMainFrame::OnFileMag() =

     {
     CFrameWnd *pOldFrame;
     =

     CMDIChildWnd *pActiveChild =3D MDIGetActive(); if( pActiveChild !=3D=
0 )
     {
     CDocument *pDocument =3D pActiveChild->GetActiveDocument(); if( =

     pDocument !=3D0)
     {
     =

     CBuildApp   *pApp =3D (CBuildApp *)AfxGetApp(); CDocTemplate  *pTemp=
;
     CFrameWnd    *pFrame;
     =

     //Get a pointer to the previous frame So we can close it pOldFrame =3D=
 =

     GetActiveFrame( ); =

     =

     pTemp =3D pApp->GetMagTemplate();//This selects what doc template to=
 use =

     pFrame =3D pTemp->CreateNewFrame(pDocument,pActiveChild);
     if(pFrame !=3D0 )
     {
     //Kill that old frame so we dont have it lying around unsued =

     pOldFrame->SendMessage(WM_CLOSE);
     pTemp->InitialUpdateFrame(pFrame,pDocument);
     }
     =

     }
     }
     =

     }
     =

     // @mfunc Returns a pointer to the CMultiDocTemplate created in ().
     // @rdesc Returns CDocTemplate *
     CDocTemplate *CBuildApp::GetMagTemplate() const {
     return m_pMagTemplate;
     }
     =

     =

     Keith V
     ______________________________ Reply Separator =

     _________________________________ Subject: MDI Document Template wit=
h =

     Multiple View
     Author:  AT o` =A3_  at INTERNET Date:    12/13/=
96 =

     11:25 AM
     =

     =

     Environment : MSVC++ 4.0, Windows 95 Hello! =

     I made an BBS Application that uses 3 Views and one Document type. O=
ne =

     of 3 Views is CScrollView and the rest of them is CFormView. Here is=
 =

     My Source
     =

     m_pTemplate1 =3D new CMultiDocTemplate(
     IDR_HANTYPE,
     RUNTIME_CLASS(CHanDoc),
     RUNTIME_CLASS(CChildFrame),
     RUNTIME_CLASS(CHanView));
     =

     m_pTemplate2 =3D new CMultiDocTemplate(
     IDR_HANTYPE,
     RUNTIME_CLASS(CHanDoc),
     RUNTIME_CLASS(CChildFrame),
     RUNTIME_CLASS(CMyMenuView));
     =

     m_pTemplate3 =3D new CMultiDocTemplate(
     IDR_HANTYPE,
     RUNTIME_CLASS(CHanDoc),
     RUNTIME_CLASS(CChildFrame),
     RUNTIME_CLASS(CMailForm));
     =

     // create main MDI Frame window
     CMainFrame* pMainFrame =3D new CMainFrame; if =

     (!pMainFrame->LoadFrame(IDR_MAINFRAME))
     return FALSE;
     m_pMainWnd =3D pMainFrame;
     =

     // Parse command line for standard shell commands, DDE, file open =

     CCommandLineInfo cmdInfo;
     ParseCommandLine(cmdInfo);
     =

     // Dispatch commands specified on the command line if =

     (!ProcessShellCommand(cmdInfo))
     return FALSE;
     =

     // The main window has been initialized, so show and update it. =

     pMainFrame->ShowWindow(m_nCmdShow);
     pMainFrame->UpdateWindow();
     =

     AddDocTemplate(m_pTemplate1);
     =

     m_pTemplate1,m_pTemplate2,m_pTemplate3 is declared in Application =

     Object Class.
     =

     As you can see, I use main m_pTemplate1 as my application's
     main Document Template. It means OnFileOpen and OnFileNew Function i=
s =

     only supported for m_pTemplate1. And another 2 Views are manually =

     constructed with m_pTemplate2 and m_pTemplate3.
     =

     Problem is that if I close a MDI Child Window that created with =

     m_pTemplate1 and no Windows that has this type left, then creation o=
f =

     MDI Child Window raise error.
     =

     So I want to have all control for Document Templates that I created.=
 =

     But I don't know how to do that.
     If Anyone knows about this or has this problem before, please let me=
 =

     know.




| Вернуться в корень Архива |