Codejock Forums Homepage
Forum Home Forum Home > Codejock Products > Visual C++ MFC > Toolkit Pro
  New Posts New Posts RSS Feed - Question about DockPane, CView & Document
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

Question about DockPane, CView & Document

 Post Reply Post Reply
Author
Message
freesong View Drop Down
Newbie
Newbie


Joined: 30 June 2005
Status: Offline
Points: 3
Post Options Post Options   Thanks (0) Thanks(0)   Quote freesong Quote  Post ReplyReply Direct Link To This Post Topic: Question about DockPane, CView & Document
    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

 



Edited by freesong
Back to Top
freesong View Drop Down
Newbie
Newbie


Joined: 30 June 2005
Status: Offline
Points: 3
Post Options Post Options   Thanks (0) Thanks(0)   Quote freesong Quote  Post ReplyReply Direct Link To This Post 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.

Back to Top
pascal View Drop Down
Groupie
Groupie


Joined: 07 February 2005
Location: Germany
Status: Offline
Points: 25
Post Options Post Options   Thanks (0) Thanks(0)   Quote pascal Quote  Post ReplyReply Direct Link To This Post 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
Back to Top
freesong View Drop Down
Newbie
Newbie


Joined: 30 June 2005
Status: Offline
Points: 3
Post Options Post Options   Thanks (0) Thanks(0)   Quote freesong Quote  Post ReplyReply Direct Link To This Post 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.

 



Edited by freesong
Back to Top
stranzl View Drop Down
Newbie
Newbie


Joined: 28 November 2005
Status: Offline
Points: 1
Post Options Post Options   Thanks (0) Thanks(0)   Quote stranzl Quote  Post ReplyReply Direct Link To This Post 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.

Back to Top
 Post Reply Post Reply
  Share Topic   

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 12.04
Copyright ©2001-2021 Web Wiz Ltd.

This page was generated in 0.172 seconds.