Print Page | Close Window

Question about DockPane, CView & Document

Printed From: Codejock Forums
Category: Codejock Products
Forum Name: Toolkit Pro
Forum Description: Topics Related to Codejock Toolkit Pro
URL: http://forum.codejock.com/forum_posts.asp?TID=2496
Printed Date: 18 July 2025 at 9:46pm
Software Version: Web Wiz Forums 12.04 - http://www.webwizforums.com


Topic: Question about DockPane, CView & Document
Posted By: freesong
Subject: Question about DockPane, CView & Document
Date Posted: 02 July 2005 at 5:44am

I'd like to create two DocPanes at the begin of program starting up, and I intend to add the imbeded views to the doc's view list,  thus I can manage all views more easily, but error was occured for the doc obj. itself was not initialized.

who know how the MFC framework could concord the doctemplate, doc, MainFrame, and views, why I cannot associate my newly created views with the Doc?  

I tried to use CCreateContext, but at the time, I can use this->GetActiveDocument(), or use this->GetActiveView()->GetDocument() in MainFrame to obtain the right Doc ptr.

I'm Waiting for the correct methods.

Best Regards

 




Replies:
Posted By: freesong
Date Posted: 02 July 2005 at 10:36am

Hi, Does anyone has ideas, don't hesitate, just reply it.

I'm wondering how the virtual function of OnCreateClient can pass the CCreateContext object correctly.

How to construct it, wow, I'm bothering with it.



Posted By: pascal
Date Posted: 07 July 2005 at 3:18pm

Hi,

Ok, just a simple example:

in your Applic.h:
CMultiDocTemplate* m_pTemplate;

in your Applic.cpp:

m_pTemplate = new CMultiDocTemplate(IDR_MAINFRAME,
RUNTIME_CLASS(CYourDocument),
RUNTIME_CLASS(CYourFrame),
RUNTIME_CLASS(CYourView));

AddDocTemplate(m_pTemplate);

What happened? you have created a document template, which will help you to create some views (CYourView) inside some frame windows (CYourframe) which are linked to a document (CYourDocument)

Now we will create programatically a new view attached to the document. We have saved the templates's pointer to use it anywhere in the application class.
First, we create a document:
CDocument* pDocument = m_pTemplate->CreateNewDocument();
ASSERT_VALID(pDocument);

then, we create the frame and give it the document because the frame will create the view in the method OnCreateClient(...):
CFrameWnd *pFrameWnd = m_pTemplate->CreateNewFrame( pDocument, NULL );
ASSERT_VALID(pFrameWnd);

And a least, we call the InitialUpdate frame.
m_pTemplate->InitialUpdateFrame( pFrameWnd, pDocument );

You have now a new MDI window. If you want to create a view inside a docking pane, that is very easy  and you will find in this site a lot of example. A simple example now (from the MainFrm.cpp):

CXTPDockingPane* pwndPane = m_paneManager.CreatePane(
IDR_PANE_SETTINGS, // Pane ID
rcLeftPane, // Bounding rectangle
xtpPaneDockLeft);

ASSERT(pwndPane);

pwndPane ->AttachView( this, RUNTIME_CLASS(CYourView), m_pDocument, NULL);

//m_pDocument can be created from a template class

Now you have a docking pane with a view attached to a document. If you need to use your own frame (and not a CFrameWnd), have a look at the method "AttachView".

 

I Hope I helped you

regards

 



-------------
Pascal Verdier
Software Engineer Manager


Posted By: freesong
Date Posted: 08 July 2005 at 10:39am

Thank you, though I've implemented this days before.

I don't know if your method could attach newly created view to the viewlist of the document.

I use app_ptr to get existed doc_ptr, and existed view_ptr, so I can construct a context, by this way I succeed in completing one doc- severay view structure.

 



Posted By: stranzl
Date Posted: 28 November 2005 at 10:03pm

This works fine.  But if you open and close more than one document thus destroying and creating the pane with a new view/doc attached, the application crashes when you exit.  What is the proper function call sequence for "unattaching" the view after call AttachView?  I'm getting a crash in the DocumentTemplate class when my app closes.




Print Page | Close Window

Forum Software by Web Wiz Forums® version 12.04 - http://www.webwizforums.com
Copyright ©2001-2021 Web Wiz Ltd. - https://www.webwiz.net