使用
CObject::IsKindOf
BOOL IsKindOf( const CRuntimeClass* pClass ) const;ExampleSee CObList::CObList for a listing of the CAge class used in all CObject examples.// example for CObject::IsKindOf
CAge a(21); // Must use IMPLEMENT_DYNAMIC or IMPLEMENT_SERIAL
ASSERT( a.IsKindOf( RUNTIME_CLASS( CAge ) ) );
ASSERT( a.IsKindOf( RUNTIME_CLASS( CObject ) ) );
CObject::IsKindOf
BOOL IsKindOf( const CRuntimeClass* pClass ) const;ExampleSee CObList::CObList for a listing of the CAge class used in all CObject examples.// example for CObject::IsKindOf
CAge a(21); // Must use IMPLEMENT_DYNAMIC or IMPLEMENT_SERIAL
ASSERT( a.IsKindOf( RUNTIME_CLASS( CAge ) ) );
ASSERT( a.IsKindOf( RUNTIME_CLASS( CObject ) ) );
解决方案 »
- 请问如何响应子窗口的子窗口的消息?
- MFC的GDI+基础
- 散分++
- rich edit的问题,我再线等啊,好急!!!
- 如何让我正在播放的视频把其中的一桢存为BMP
- 在那里可以找ADO返回的ErrorCode的定义?
- 为什么给一个类的成页函数开线程编译会出现内存错误问题?
- 我在主程序中开了个线程,怎么样在主程序关闭的时候,关闭未完成的线程啊?
- 请问 MFC 自己生成的toolbar上可以加上由Button 控制读输入的 input box 吗?
- 设计按钮闪烁功能
- SHBrowseForFolder()显示模态文件夹对话框,如何显示非模态的文件夹对话框
- 请问如何象网上邻居那样枚举局域网中每个计算机的共享文件!?
我判断出来了,怎样才能新建指定的模版文档呢?
{
if (m_templateList.IsEmpty())
{
TRACE0("Error: no document templates registered with CWinApp.\n");
AfxMessageBox(AFX_IDP_FAILED_TO_CREATE_DOC);
return;
} CDocTemplate* pTemplate = (CDocTemplate*)m_templateList.GetHead();
if (m_templateList.GetCount() > 1)
{
// more than one document template to choose from
// bring up dialog prompting user
CNewTypeDlg dlg(&m_templateList);
int nID = dlg.DoModal();
if (nID == IDOK)
pTemplate = dlg.m_pSelectedTemplate;
else
return; // none - cancel operation
} ASSERT(pTemplate != NULL);
ASSERT_KINDOF(CDocTemplate, pTemplate); pTemplate->OpenDocumentFile(NULL);
// if returns NULL, the user has already been alerted
}可以使用GetFirstDocTemplatePosition
GetNextDocTemplate替代。
POSITION curTemplatePos = GetFirstDocTemplatePosition(); while(curTemplatePos != NULL)
{
CDocTemplate* curTemplate =
GetNextDocTemplate(curTemplatePos);
CString str;
curTemplate->GetDocString(str, CDocTemplate::docName);
if(str == _T("Bounce"))
{
curTemplate->OpenDocumentFile(NULL);
return;
}
}
strDoc 为 Doc Name
即:void OnFileNew(CString strDoc)
{
POSITION pos; pos = GetFirstDocTemplatePosition(); CDocTemplate* pTemplate = GetNextDocTemplate(pos);
CString strBuf; while (pTemplate != NULL) {
pTemplate->GetDocString(strBuf, CDocTemplate::docName);
if (strBuf.Compare(LPCTSTR(strDoc)) == 0)
{
pTemplate->OpenDocumentFile(NULL);
return;
}
}
}
GetDocString(str, CDocTemplate::docName);
第二个参数有很多选择,依你程序而定,具体看 MSDN 吧。