1 Attachment(s)
Multiple Views Single Document (MDI)
Hi All,
I was looking into the article for Multiple Views Single Document (MDI)
I was able to do SDI but have problems with MDI
I have attached a sample application TestMDI.
In this the multiple views are not treating the document as same document.
If i debug and see i will not be getting same document for different views.
thanks
rajs
Re: Multiple Views Single Document (MDI)
You're playing with the framework, instead of allowing it to do its job automatically. For example, here is your CWinAPP:OnInitInstance method:
Code:
BOOL CTestMDIApp::InitInstance()
{
AfxEnableControlContainer();
// Standard initialization
#ifdef _AFXDLL
Enable3dControls(); // Call this when using MFC in a shared DLL
#else
Enable3dControlsStatic(); // Call this when linking to MFC statically
#endif
// Change the registry key under which our settings are stored.
SetRegistryKey(_T("Local AppWizard-Generated Applications"));
LoadStdProfileSettings(); // Load standard INI file options (including MRU)
// Register document templates
m_pMultiDocTemplate = new CMultiDocTemplate(
IDR_TESTMDTYPE,
RUNTIME_CLASS(CTestMDIDoc),
RUNTIME_CLASS(CChildFrame), // custom MDI child frame
RUNTIME_CLASS(CTestMDIView));
AddDocTemplate(m_pMultiDocTemplate);
CMainFrame* pMainFrame = new CMainFrame;
m_glDocument=new CTestMDIDoc;
m_glDocument->SetTitle("Demo");
CCreateContext context;
context.m_pCurrentDoc=m_glDocument;
context.m_pNewViewClass=NULL;
context.m_pNewDocTemplate=m_pMultiDocTemplate;
context.m_pLastView=NULL;
context.m_pCurrentFrame=NULL;
if (!pMainFrame->LoadFrame(IDR_MAINFRAME,WS_OVERLAPPEDWINDOW | FWS_ADDTOTITLE,NULL, &context ))
return FALSE;
m_pMainWnd = pMainFrame;
OnViewView1();
// 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;
pMainFrame->ShowWindow(m_nCmdShow);
pMainFrame->UpdateWindow();
return TRUE;
}
What are you trying to accomplish with this code that the framework doesn't do for you automatically? The framework has a document template manager that uses the CMultiDocTemplate object to create new documents and to link each of the views to the document. This happens automatically for you, in the sequence explained here: "Creating New Documents, Windows, and Views" at http://msdn.microsoft.com/library/en....and_Views.asp
Why are you trying to alter that automatic behavior?
Mike
Re: Multiple Views Single Document (MDI)
Hi Mike
Thanks for the reply
I am trying to point a single document which is m_glDocument in this case to different views which i create.
I want all the views to be pointed to the same document.
bydefault this will not happen in doc/view architecture.
any solution ?
regards
rajs
Re: Multiple Views Single Document (MDI)
use splitter window. for any help look MSDN
Re: Multiple Views Single Document (MDI)
Hi Gunaamirthavelu
The requiremnt is not splitter windows. but the two views should be in different childframe with the same document different views.
regards
rajs
Re: Multiple Views Single Document (MDI)
Quote:
Originally Posted by brraj
The requiremnt is not splitter windows. but the two views should be in different childframe with the same document different views.
ya thats why i told use spiltter window.
in splitter window one document but u can create number of childframe using splitter window. i used the splitter window and got the 2 views in one document. if u want i will post the code.
Re: Multiple Views Single Document (MDI)
Hi Gunaamirthavelu
I understand that using splitter windows we can accomplish. But we cannot use splitter windows here.
Our requirement is we should have an
- MDI application
- which contains two diffrent child frame (not using splitter windows) with two different views which points to same document.
regards
rajs
Re: Multiple Views Single Document (MDI)
ya now i got the point. u can use one more view for example firstview and second view both class contain same properties and same functions but u can access the views using GetActiveView() method try this method u will get the answer.
Re: Multiple Views Single Document (MDI)
Hi Gunaamirthavelu,
In the technique you have mentioned
"firstview and second view both class contain same properties and same functions "
here in my requirement both classes can contain different properties and different funtions but point to same document.
Two views are totally different if you see my example (testMDI),
but should point to same document.
regards
rajs
Re: Multiple Views Single Document (MDI)
ok no problem. but u can access the view(that means which one is active) through the GetActiveView() function.
Re: Multiple Views Single Document (MDI)
Hi Gunaamirthavelu,
can you post the stepby step code as i am not getting your point as to point same document to different views, using getActiveView().
regards
rajs
Re: Multiple Views Single Document (MDI)
wait i will search code in my PC and send u later.
Re: Multiple Views Single Document (MDI)
Quote:
Originally Posted by brraj
Our requirement is we should have an
- MDI application
- which contains two diffrent child frame (not using splitter windows) with two different views which points to same document.
It is not a problem! :)
You should have two C<..>View derived classes for your views, the first view will be createad by framework automatically according to CMultiDocTemplate settings, the second view you could created from your own code. One of the possibles ways could be:
Send the message to main frame to create a new child window:
Code:
AfxGetMainWnd()->SendMessage(WM_COMMAND, ID_WINDOW_NEW);
This will cause the CChildFrame::OnCreateClient() to be called. Inside the CChildFrame::OnCreateClient() you could use some flags pointing out which kind of a View must be created. To create a view the CFrameWnd::CreateView should be called.
Re: Multiple Views Single Document (MDI)
Hi VictorN
If you can alter my sample application it would be fine. Because i did the changes which you told,
but its crashing when i call
AfxGetMainWnd()->SendMessage(WM_COMMAND, ID_WINDOW_NEW);
regards
rajs
Re: Multiple Views Single Document (MDI)
Sorry, brraj, I have no time now to dig in your code. :sick:
Try to find/understand where and why it is crashing!