使用
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 ) ) );

解决方案 »

  1.   

    可是CWinApp::OnFileNew()中没有参数呀
    我判断出来了,怎样才能新建指定的模版文档呢?
      

  2.   

    重载OnFileNew函数:替换调原来的默认实现。
      

  3.   

    参照这段代码的实现.void CDocManager::OnFileNew()
    {
    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替代。
      

  4.   

    MSDN示例的代码,在一个消息映射函数里的,即打开名为bounce的类模板的消息映射函数(此函数在WinApp里)
    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;
    }
    }
      

  5.   

    你这样试试, 创建一个新的Doc,
    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;
    }
    }
    }
      

  6.   

    补充一句,解决问题的关键在于函数:
    GetDocString(str, CDocTemplate::docName);
    第二个参数有很多选择,依你程序而定,具体看 MSDN 吧。
      

  7.   

    MFC 经典问答  里有详细的讨论 和例子