Creating new views w/o using DocTemplate 
Author Message
 Creating new views w/o using DocTemplate

I'm relatively new to MFC and have, until now, used the MultiDocTemplate
option for creating and displaying views.  I need to create a view from
another view when a button is pressed and need to pass this view some
initial values.  How do I create the frame/view/doc without using the
MultiDocTemplate?  I've experimented with the whole Createcontext,
CRuntimeclass stuff but keep running into a wall.  I figure I can put the
appropriate values to pass in the current doc and use it to create the new
view.

Thanks for your help.

remove ns from the beginning of my email address



Sat, 28 Jul 2001 03:00:00 GMT  
 Creating new views w/o using DocTemplate
CCreateContext is the key. You have to override OnCreateClient() to get to
the view class in your Child Frame window. You should save this context in
your frame window. You would need this to create the view.

Once you have this class name for view, you can do the following to create a
view:

CView* CMyClass::CreateView(CRuntimeClass *pViewClass, UINT nID)
{
 CView* pView = (CView*)pViewClass->CreateObject();
 if (pView == NULL) {
  TRACE1("Warning: Dynamic create of view type %hs failed.\n",
   pViewClass->m_lpszClassName);
  return NULL;
 }

 ASSERT_KINDOF(CView, pView);

 CCreateContext* pContext = GetCreateContext(); // You have to provide this
method which
                                                // returns the context saved
when
                                                // OnCreateClient is called

 if (!pView->Create(NULL, NULL, WS_CHILD | WS_BORDER,
  CRect(0,0,0,0), this, nID, pContext)) {
  TRACE0("Warning: could not create view for frame.\n");
  return NULL;
 }

Quote:
}

Ajay
Quote:

>I'm relatively new to MFC and have, until now, used the MultiDocTemplate
>option for creating and displaying views.  I need to create a view from
>another view when a button is pressed and need to pass this view some
>initial values.  How do I create the frame/view/doc without using the
>MultiDocTemplate?  I've experimented with the whole Createcontext,
>CRuntimeclass stuff but keep running into a wall.  I figure I can put the
>appropriate values to pass in the current doc and use it to create the new
>view.

>Thanks for your help.

>remove ns from the beginning of my email address



Sat, 28 Jul 2001 03:00:00 GMT  
 Creating new views w/o using DocTemplate

Ajay thanks for the response.

I follow you on most of this.  In my situation, I know the View class from the start.  I did the following and it seems to work but I still don't feel I have a full grasp of how all of this works.

 CStaticListDoc* theDoc = (CStaticListDoc*) GetDocument();

 theDoc->m_pRS = pRS;

 m_pProfileFrame = new CProfileFrame;

 CCreateContext createcontext;

 createcontext.m_pCurrentFrame = m_pProfileFrame;
 createcontext.m_pCurrentDoc = theDoc;
 createcontext.m_pNewViewClass = RUNTIME_CLASS(CTestView);

 m_pProfileFrame->Create(NULL, "", WS_CHILD,CRect(0,0,0,0),NULL , &createcontext);

 m_pProfileFrame->InitialUpdateFrame(theDoc, TRUE);

Does this look reasonable?  The only problem I'm having with this is that the new frame is not appearing as a new tab within my Objective Toolkit WDI interface.  It overwrites the current worksheet.  This is a separate issue, I think.  Any other time, I've been creating the new views with MultiDocTemplate and OpenDocumentFile.

Quote:

>CCreateContext is the key. You have to override OnCreateClient() to get to
>the view class in your Child Frame window. You should save this context in
>your frame window. You would need this to create the view.

>Once you have this class name for view, you can do the following to create a
>view:

>CView* CMyClass::CreateView(CRuntimeClass *pViewClass, UINT nID)
>{
> CView* pView = (CView*)pViewClass->CreateObject();
> if (pView == NULL) {
>  TRACE1("Warning: Dynamic create of view type %hs failed.\n",
>   pViewClass->m_lpszClassName);
>  return NULL;
> }

> ASSERT_KINDOF(CView, pView);

> CCreateContext* pContext = GetCreateContext(); // You have to provide this
>method which
>                                                // returns the context saved
>when
>                                                // OnCreateClient is called

> if (!pView->Create(NULL, NULL, WS_CHILD | WS_BORDER,
>  CRect(0,0,0,0), this, nID, pContext)) {
>  TRACE0("Warning: could not create view for frame.\n");
>  return NULL;
> }
>}

>Ajay


>>I'm relatively new to MFC and have, until now, used the MultiDocTemplate
>>option for creating and displaying views.  I need to create a view from
>>another view when a button is pressed and need to pass this view some
>>initial values.  How do I create the frame/view/doc without using the
>>MultiDocTemplate?  I've experimented with the whole Createcontext,
>>CRuntimeclass stuff but keep running into a wall.  I figure I can put the
>>appropriate values to pass in the current doc and use it to create the new
>>view.

>>Thanks for your help.

>>remove ns from the beginning of my email address



Sun, 29 Jul 2001 03:00:00 GMT  
 Creating new views w/o using DocTemplate

Quote:
> It may be easier to add additional doc templates in you CWinApp
> derived class. I have an app that does this, when I want to create a
> new view of a specific type, it then looks like this:

// this code occurs in the one doc class used in the project
// this doc has multiple views

 // make a new frame!
 CDocTemplate* pTemplate;
 CFrameWnd* pFrame;
// here's the other template
 pTemplate = ((NDIApp*)AfxGetApp())->p_theTemplate2D;
 ASSERT_VALID(pTemplate);
 pFrame = pTemplate->CreateNewFrame(this, NULL);
 if (pFrame == NULL)
 {
  TRACE0("Warning: failed to create new frame\n");
  AfxMessageBox(AFX_IDP_COMMAND_FAILURE);
  return;        // command failed
 }

 // this function makes frame call the view class OnInitialUpdate()
 pTemplate->InitialUpdateFrame(pFrame, this);

Good Luck!
Dave F.



Sun, 29 Jul 2001 03:00:00 GMT  
 Creating new views w/o using DocTemplate
I guess my confusion probably centers around the CDocument.  I need to use
the same CDocument instance for the new view as the current view is
associated with.  How do I do this using the CMultiDocTemplate?  I thought
it created a new document for each new template when OpenDocumentFile is
called.  Let's say I have 3 different CDocument derived classes.  If I use
CDocument_1 for 3 of the templates, will each one create a new CDocument_1
when the frame/view is created?  or does this depend on how I create/open
the template?  I'm using the OpenDocumentFile.

Maybe I'm using the Doc/View paradigm incorrectly.  I just read something
that said you should have 1 DocTemplate for each type of CDocument.  I'm not
using the CDocument class for much more than holding a few pointers to
variables, etc.  I have a DocTemplate for each of the 12 or so CFormViews
I've created so far.  My current problem has me creating what could be
considered multiple views of the same CDocument.  So it was my understanding
that I should use a DocTemplate in this case, I should just create a new
frame/view.  I hope you can clear this up for me.

Thanks much.

Quote:



>>I'm relatively new to MFC and have, until now, used the MultiDocTemplate
>>option for creating and displaying views.  I need to create a view from
>>another view when a button is pressed and need to pass this view some
>>initial values.  How do I create the frame/view/doc without using the
>>MultiDocTemplate?  I've experimented with the whole Createcontext,
>>CRuntimeclass stuff but keep running into a wall.  I figure I can put the
>>appropriate values to pass in the current doc and use it to create the new
>>view.

>Does CMultiDocTemplate not meet your needs?

>You could always post a WM_COMMAND message with a command ID and have
>CMainFrame create it for you...

>------------------------------------------------------------------------
>Andy Yee                   Corporate E-Mail:    See Above
>Software Engineer          Coporate Web Page:   http://www.jasc.com

>                           Personal Web Page:   http://www.visi.com/~nde

>Question authority...and the authorities will question YOU!
>------------------------------------------------------------------------



Sun, 29 Jul 2001 03:00:00 GMT  
 Creating new views w/o using DocTemplate

Quote:
>I'm relatively new to MFC and have, until now, used the MultiDocTemplate
>option for creating and displaying views.  I need to create a view from
>another view when a button is pressed and need to pass this view some
>initial values.  How do I create the frame/view/doc without using the
>MultiDocTemplate?  I've experimented with the whole Createcontext,
>CRuntimeclass stuff but keep running into a wall.  I figure I can put the
>appropriate values to pass in the current doc and use it to create the new
>view.

Does CMultiDocTemplate not meet your needs?

You could always post a WM_COMMAND message with a command ID and have
CMainFrame create it for you...

------------------------------------------------------------------------
Andy Yee                   Corporate E-Mail:    See Above
Software Engineer          Coporate Web Page:   http://www.jasc.com

                           Personal Web Page:   http://www.visi.com/~nde

Question authority...and the authorities will question YOU!
------------------------------------------------------------------------



Mon, 30 Jul 2001 03:00:00 GMT  
 
 [ 6 post ] 

 Relevant Pages 

1. Creating new views w/o using DocTemplate

2. Creating new views w/o using DocTemplate

3. create a new doc/view pair from another view

4. Problems creating new IE views (Html views)

5. Create new View from within a view

6. Create mutiple views of one document using different view classes

7. Create mutiple views of one document using different view classes

8. Help - Using Create to dynamiclly create a CFormView view

9. Help adding new DocTemplates

10. HELP : Doctemplate and View

11. How does a DocTemplate remove a view (Newbie Q)

12. SDI: creating new views

 

 
Powered by phpBB® Forum Software