订阅所有文章
文章搜索

高级搜索这是社么?这是顶尖最新推出的文章增强型搜索功能!
全网 本站
您现在的位置: 顶尖设计 >> IT学院 >> 编程开发 >> VC >> 文章正文

《明明白白看MFC之程序框架(二)》

作者:eliner  来源:CSDN  点击  更新:2006-12-19 7:04:23  编辑: 画王w  字体

二、         MFC应用程序结构

在《明明白白看MFC之程序框架(一)》中我分析了一个经典的SDK应用程序的结构,现在可是要进入主题“MFC应用程序结构”了。MFC应用程序有好多种,为了能够更清楚地与前面的文章形成对比,我们在这里看一个SDI的应用程序,当然例子还是经典的“Hello World”了。在使用向导生成应用程序后,会发现有好几个文件,首先我们不管有哪些文件,按照程序执行得主线抽取主要的源程序分析一下再说(因为MFC生成的应用程序不是很方便阅读,所以在这里我将他们重新编辑了)。

 

CHelloWorldApp theApp;

int AFXAPI AfxWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,

     LPTSTR lpCmdLine, int nCmdShow)

{

    

     CWinThread* pThread = AfxGetThread();

     CWinApp* pApp = AfxGetApp();

 

     // AFX internal initialization

     if (!AfxWinInit(hInstance, hPrevInstance, lpCmdLine, nCmdShow))

            goto InitFailure;

 

     // App global initializations (rare)

     if (pApp != NULL && !pApp->InitApplication())

            goto InitFailure;

 

     // Perform specific initializations

     if (!pThread->InitInstance())

     {

            if (pThread->m_pMainWnd != NULL)

            {

                   TRACE0("Warning: Destroying non-NULL m_pMainWnd\n");

                   pThread->m_pMainWnd->DestroyWindow();

            }

            nReturnCode = pThread->ExitInstance();

            goto InitFailure;

     }

     nReturnCode = pThread->Run();

 

InitFailure:

……………………

 

     AfxWinTerm();

     return nReturnCode;

}

 

BOOL CWinApp::InitApplication()

{

     if (CDocManager::pStaticDocManager != NULL)

     {

            if (m_pDocManager == NULL)

                   m_pDocManager = CDocManager::pStaticDocManager;

            CDocManager::pStaticDocManager = NULL;

     }

 

     if (m_pDocManager != NULL)

            m_pDocManager->AddDocTemplate(NULL);

     else

            CDocManager::bStaticInit = FALSE;

 

     return TRUE;

}

BOOL CHelloWorldApp::InitInstance()

{

     AfxEnableControlContainer();

 

     ………………………………

 

     // Change the registry key under which our settings are stored.

     // TODO: You should modify this string to be something appropriate

     // such as the name of your company or organization.

     SetRegistryKey(_T("Local AppWizard-Generated Applications"));

 

     LoadStdProfileSettings();  // Load standard INI file options (including MRU)

 

     // Register the application's document templates.  Document templates

     //  serve as the connection between documents, frame windows and views.

 

     CSingleDocTemplate* pDocTemplate;

     pDocTemplate = new CSingleDocTemplate(

            IDR_MAINFRAME,

            RUNTIME_CLASS(CHelloWorldDoc),

            RUNTIME_CLASS(CMainFrame),       // main SDI frame window

            RUNTIME_CLASS(CHelloWorldView));

     AddDocTemplate(pDocTemplate);

 

     // Parse command line for standard shell commands, DDE, file open

     CCommandLineInfo cmdInfo;

     Pa

[1] [2] 下一页

  • 上一篇文章:

  • 下一篇文章:
  •      
    热门文章  
    推荐文章  
    相关文章    
     发表评论
      关于我们 | 联系我们 | 站点地图 | 广告投放 | 友情链接 | 在线留言 | 版权申明
    版权所有 © 2004-2007 顶尖设计(bobd.cn)
    未经授权禁止转载,摘编,复制本站内容或建立镜像. 沪ICP备05002835号