在MFC中检索doc模板

时间:2014-04-08 09:50:27

标签: visual-c++ mfc mdi

我正在使用MFC MDI应用程序,我正在添加两个doc模板,如下面的代码所示:

BOOL CEmuDiagnosticsClientApp::InitInstance()
{
INITCOMMONCONTROLSEX InitCtrls;
InitCtrls.dwSize = sizeof(InitCtrls);
// Set this to include all the common control classes you want to use
// in your application.
InitCtrls.dwICC = ICC_WIN95_CLASSES;
InitCommonControlsEx(&InitCtrls);

CWinAppEx::InitInstance();

// Initialize OLE libraries
if (!AfxOleInit())
{
    AfxMessageBox(IDP_OLE_INIT_FAILED);
    return FALSE;
}
AfxEnableControlContainer();

//Added new code

    CMultiDocTemplate* pDocTemplate;
    pDocTemplate = new CMultiDocTemplate(IDR_STRING_FILTERWINDOW,
        RUNTIME_CLASS(CEmuDiagnosticsClientDoc),
        RUNTIME_CLASS(CChildFrame), // custom MDI child frame
        RUNTIME_CLASS(CFilterWindow));
    if (!pDocTemplate)
        return FALSE;
    AddDocTemplate(pDocTemplate);

SetRegistryKey(_T("Local AppWizard-Generated Applications"));
LoadStdProfileSettings(4);  // Load standard INI file options (including MRU)

InitContextMenuManager();

InitKeyboardManager();

InitTooltipManager();
CMFCToolTipInfo ttParams;
ttParams.m_bVislManagerTheme = TRUE;
theApp.GetTooltipManager()->SetTooltipParams(AFX_TOOLTIP_TYPE_ALL,
    RUNTIME_CLASS(CMFCToolTipCtrl), &ttParams);


AddDocTemplate(new CMultiDocTemplate(IDR_STRING_SIGNALWINDOW,
    RUNTIME_CLASS(CEmuDiagnosticsClientDoc),
    RUNTIME_CLASS(CChildFrame), // custom MDI child frame
    RUNTIME_CLASS(CSignalWindow)));

// create main MDI Frame window
CMainFrame* pMainFrame = new CMainFrame;
if (!pMainFrame || !pMainFrame->LoadFrame(IDR_MAINFRAME))
{
    delete pMainFrame;
    return FALSE;
}
m_pMainWnd = pMainFrame;

// Parse command line for standard shell commands, DDE, file open
CCommandLineInfo cmdInfo;
ParseCommandLine(cmdInfo);

// Dispatch commands specified on the command line.  Will return FALSE if
// app was launched with /RegServer, /Register, /Unregserver or /Unregister.
if (!ProcessShellCommand(cmdInfo))
    return FALSE;
// The main window has been initialized, so show and update it
pMainFrame->ShowWindow(m_nCmdShow);
pMainFrame->UpdateWindow();

return TRUE;
}

我正在使用此代码迭代文档并在我的CMainFrame类中获取视图类的引用。

CFilterWindow* p = NULL;
CSignalWindow* p1 = NULL;
for( POSITION pos = AfxGetApp()->GetFirstDocTemplatePosition(); pos != NULL; )
{
    CDocTemplate* pTempl = AfxGetApp()->GetNextDocTemplate( pos );

    for( POSITION pos1 = pTempl->GetFirstDocPosition(); pos!= NULL; )
    {
        CDocument* pDoc = pTempl->GetNextDoc( pos1 );

        for( POSITION pos2 = pDoc->GetFirstViewPosition(); pos2 != NULL; )
        {
            CView* pView = pDoc->GetNextView( pos2 );
            if( pView->IsKindOf( RUNTIME_CLASS(CFilterWindow) ) )
            {
                p = (CFilterWindow*)pView;
                p->UpdateUI();
                // Do what you need with the view...
            }
            else
            {
                p1 = (CSignalWindow*)pView;
                p1->UpdateUI();
            }
        }
    }
}

问题在于循环for( POSITION pos2 = pDoc->GetFirstViewPosition(); pos2 != NULL; )  因为pDoc->GetFirstViewPosition();总是返回NULL 令我感到困惑的是它为什么返回NULL。

有人能说出我错的地方吗?

0 个答案:

没有答案