-
May 23rd, 2013, 10:17 PM
#1
creating an instance of a mfc derived class.
I need to create an object of a mfc derived CFormView class that's not in the doc/template (a second view class).
but it was generated with a protected ctor. Here's the code explanation with comments.
Code:
// I'm thinking all the normal classes of the Doc/View template are created
// starting with this code, but within the template code base.
CSingleDocTemplate* pDocTemplate;
pDocTemplate = new CSingleDocTemplate(IDR_MAINFRAME,
RUNTIME_CLASS(CViewSwitchDoc), //<-expands to-> ((CRuntimeClass*)(&CViewSwitchDoc::classCViewSwitchDoc)),
RUNTIME_CLASS(CMainFrame), // main SDI frame window
RUNTIME_CLASS(CViewSwitchView));
//
// But I have generated "another view" using the "Add Class" Wizard, it's a derived class of
// mfc CFormView which I named ViewForm. However I'm having a problem creating an instance
// of it because of the generated protected ctor and pulls a compile error of not being able to access ctor.
// Below are the header and implementation files of this said ViewForm class.
// Anybody got any idea on how to create an object of this view ?
// Did I go about it all the wrong way since it's not in the doc/template group ?
//=================================================
// ViewForm.h file
#pragma once
// ViewForm form view
class ViewForm : public CFormView
{
DECLARE_DYNCREATE(ViewForm)
//public: static const CRuntimeClass classViewForm; // These 3 lines are expansion of
//virtual CRuntimeClass* GetRuntimeClass() const; // DECLARE_DYNCREATE(ViewForm)
//static CObject* __stdcall CreateObject();
protected:
ViewForm(); // generated by Add Class wizard with
//protected constructor used by dynamic creation
virtual ~ViewForm();
. . . . . other code not pertinant
. . . . .
};
//===============================================
// ViewForm.cpp : implementation file
#include "stdafx.h"
#include "ViewSwitch.h"
#include "ViewForm.h"
IMPLEMENT_DYNCREATE(ViewForm, CFormView)
// the below is expansion of IMPLEMENT_DYNCREATE above,
// CObject* __stdcall ViewForm::CreateObject() { return new ViewForm; } // this is where obj would be created.
// including the embedded IMPLEMENT_RUNTIMECLASS below,
//__declspec(selectany) const CRuntimeClass ViewForm::classViewForm =
// { "ViewForm", sizeof(class ViewForm), 0xFFFF, ViewForm::CreateObject,
// ((CRuntimeClass*)(&CFormView::classCFormView)), 0, 0 };
//CRuntimeClass* ViewForm::GetRuntimeClass() const { return ((CRuntimeClass*)(&ViewForm::classViewForm)); }
ViewForm::ViewForm()
: CFormView(ViewForm::IDD)
{ }
ViewForm::~ViewForm()
{ }
. . . . other non pertinant code
. . . .
}
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|