Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Switching between multiple views in an SDI 1

Status
Not open for further replies.

coredump

Technical User
Jul 9, 2001
7
US

I'm writing an SDI program which requires three views of the same document. I know its possible, MS published a sample application called collection that does this (in MSDN that shipped with vc++ 6).

According to the example, this should create the new view when placed in the CMainFrame class. But when I try to compile it I get (among others) a CINV_trial3View is not a class or namespace name error. Are there special requirements for a view class, other than setting the base class to (in my case) CFormView? I know you have to write the constructor yourself and call CFormView::CFormView() at the end of it, but that should be it, right?

CRuntimeClass* pNewViewClass = RUNTIME_CLASS(CINV_trial3View);
CCreateContext context;
context.m_pNewViewClass = pNewViewClass;
context.m_pCurrentDoc = GetActiveDocument();

CView* PNewView = STATIC_DOWNCAST(CView, CreateView(&context));

pNewView->ShowWindow(SW_SHOW);
pNewView->OnInitialUpdate();
SetActiveView(pNewWindow);
RecalcLayout();
m_nCurrentExample = nCmdID;


Thanks in advance!
 
I think you just forgot aan #include, something like:
#include "INV_trial3View.h" before your code. I suppose this code is in the CMainFrame class. s-)

Blessed is he who in the name of justice and goodwill, sheperds the weak through the valley of darkness...
 
Yep. That's what it was. Thanks.
Now for the next snag: To create the second view class I copied the header/implementation files generated by the MFC app wizard, and used the find/replace feature to replace every instance of CINV_trial_3View with CView1. The program compiles correctly but when I change the document template code, replacing the wizard's view class with my new class:

CSingleDocTemplate* pNewDocTemplate = new CSingleDocTemplate(
IDR_EDITFORMVIEW_TMPL,
RUNTIME_CLASS(CINV_trial_3Doc), //document class
RUNTIME_CLASS(CMainFrame), // frame class
RUNTIME_CLASS(CView2)); // view class

AddDocTemplate(pNewDocTemplate);


But I get a debug assertion failed error at runtime. The line of the error is listed as line 69 of viewform.cpp When I debug the app, it points me to the following code

#ifdef _DEBUG
//dialog template must exist and be invisible with WS_CHILD
//set

if (!_AfxCheckDialogTemplate(m_lpszTemplateName, TRUE))
{
(line69)=> ASSERT(FALSE); // invalid dialog template name
PostNcDestroy(); // cleanup if Create fails too soon
return FALSE;
}
#endif //_DEBUG


I'm not sure what to make of this, especially since the MFC wizard view class works fine.

Thanks again.
 
IDR_EDITFORMVIEW_TMPL is a resource. Go look after it in the string table maybe you have to replace some part of it.

the you put
RUNTIME_CLASS(CView2)); // view class

I think you meant CView1.

Do you still have the problem? If so, give me more details.
s-)

Blessed is he who in the name of justice and goodwill, sheperds the weak through the valley of darkness...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top