VC中怎么添加一个视图类

来源:百度知道 编辑:UC知道 时间:2024/05/21 09:58:25
VC中怎么添加一个视图类,手动添加一个类时,有选择了继承一个VIEW的类,但是新建的类里面都是空的。

这使用这个类时会出问题。
cx.m_pNewViewClass=RUNTIME_CLASS(CMyView);
像这里面的CMyView类,是自定义的,手动加一个类 里面是没有内容的,它要怎么自动生成呢。

按CTRL +W
然后按Add Class
在其中选new
在随后的对话框中输入CMyView
在base Class里选一个基类//可以随便选
CView CEditView都行
cx.m_pNewViewClass=RUNTIME_CLASS(CMyView);
这一句一般是由VC自动生成不需要自己写
//出现在下面这个函数里
CFrameWnd* CDocTemplate::CreateNewFrame(CDocument* pDoc, CFrameWnd* pOther)
{
if (pDoc != NULL)
ASSERT_VALID(pDoc);
// create a frame wired to the specified document

ASSERT(m_nIDResource != 0); // must have a resource ID to load from
CCreateContext context;
context.m_pCurrentFrame = pOther;
context.m_pCurrentDoc = pDoc;
context.m_pNewViewClass = m_pViewClass;
context.m_pNewDocTemplate = this;

if (m_pFrameClass == NULL)
{
TRACE0("Error: you must override CDocTemplate::CreateNewFrame.\n");
ASSERT(FALSE);
return NULL;
}
CFrameWnd* pFrame = (CFrameWnd*)m_pFrameClass->CreateObject();
if (pFrame == NULL)
{
TRACE1("Warning: D