CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 15 of 15
  1. #1
    Join Date
    Jun 2002
    Location
    India,bangalore
    Posts
    295

    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
    Attached Files Attached Files

  2. #2
    Join Date
    Nov 2002
    Location
    California
    Posts
    4,556

    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

  3. #3
    Join Date
    Jun 2002
    Location
    India,bangalore
    Posts
    295

    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

  4. #4
    Join Date
    Jun 2005
    Location
    Tirunelveli-Tamil Nadu-India
    Posts
    354

    Re: Multiple Views Single Document (MDI)

    use splitter window. for any help look MSDN
    If I Helped You, "Rate This Post"

    Thanks
    Guna

  5. #5
    Join Date
    Jun 2002
    Location
    India,bangalore
    Posts
    295

    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

  6. #6
    Join Date
    Jun 2005
    Location
    Tirunelveli-Tamil Nadu-India
    Posts
    354

    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.
    If I Helped You, "Rate This Post"

    Thanks
    Guna

  7. #7
    Join Date
    Jun 2002
    Location
    India,bangalore
    Posts
    295

    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

  8. #8
    Join Date
    Jun 2005
    Location
    Tirunelveli-Tamil Nadu-India
    Posts
    354

    Smile 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.
    If I Helped You, "Rate This Post"

    Thanks
    Guna

  9. #9
    Join Date
    Jun 2002
    Location
    India,bangalore
    Posts
    295

    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

  10. #10
    Join Date
    Jun 2005
    Location
    Tirunelveli-Tamil Nadu-India
    Posts
    354

    Smile 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.
    If I Helped You, "Rate This Post"

    Thanks
    Guna

  11. #11
    Join Date
    Jun 2002
    Location
    India,bangalore
    Posts
    295

    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

  12. #12
    Join Date
    Jun 2005
    Location
    Tirunelveli-Tamil Nadu-India
    Posts
    354

    Re: Multiple Views Single Document (MDI)

    wait i will search code in my PC and send u later.
    If I Helped You, "Rate This Post"

    Thanks
    Guna

  13. #13
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,430

    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.

  14. #14
    Join Date
    Jun 2002
    Location
    India,bangalore
    Posts
    295

    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

  15. #15
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,430

    Re: Multiple Views Single Document (MDI)

    Sorry, brraj, I have no time now to dig in your code.
    Try to find/understand where and why it is crashing!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured