(整理)MFC视图结构框架分析..docxVIP

  • 1
  • 0
  • 约1.9万字
  • 约 30页
  • 2022-10-16 发布于山东
  • 举报
精品文档 MFC文档视图构造框架解析 1:程序的“导火索”theApp CmyApptheApp; 在声明象的同,用其构造函数。按C++的法,首先要用其基Cwinapp的 构造函数.个文件主要用于用程序的一些初始化操作。 classCWinApp:publicCWinThread { DECLARE_DYNAMIC(CWinApp) public: //Constructor CWinApp(LPCTSTRlpszAppName=NULL); ???? } CWinApp::CWinApp(LPCTSTRlpszAppName) { if(lpszAppName!=NULL) m_pszAppName=_tcsdup(lpszAppName); else m_pszAppName=NULL; //initializeCWinThreadstate AFX_MODULE_STATE*pModuleState=_AFX_CMDTARGET_GETSTATE( );AFX_MODULE_THREAD_STATE*pThreadState=pModuleState-m_thread;ASSERT(AfxGetThread( )==NULL); pThreadState-m_pCurrentWinThread=this; ASSERT(AfxGetThread( )==this); m_hThread=::GetCurrentThread( ); m_nThreadID=::GetCurrentThreadId( ); 精品文档 精品文档 //initializeCWinAppstate ASSERT(afxCurrentWinApp==NULL);//onlyoneCWinAppobjectplease pModuleState-m_pCurrentWinApp=this; ASSERT(AfxGetApp( )==this); innon-runningstateuntilWinMainm_hInstance=NULL;m_hLangResourceDLL=NULL;m_pszHelpFilePath=NULL;m_pszProfileName=NULL;m_pszRegistryKey=NULL;m_pszExeName=NULL;m_pRecentFileList=NULL;m_pDocManager=NULL; m_atomApp=m_atomSystemTopic=NULL; initializewaitcursorstatem_nWaitCursorCount=0;m_hcurWaitCursorRestore=NULL; initializecurrentprinterstate m_hDevMode=NULL; m_hDevNames=NULL; m_nNumPreviewPages=0;//notspecified(defaultsto1) //initializeDAOstate m_lpfnDaoTerm=NULL;//willbesetifAfxDaoInitcalled //otherinitialization m_bHelpMode=FALSE; m_eHelpType=afxWinHelp; m_nSafetyPoolSize=512;//defaultsize } 精品文档 精品文档 2:theApp之后的隐藏代码,由他控制整个程序的流程。 _tWinMain(HINSTANCEhInstance,HINSTANCEhPrevInstance, LPTSTRlpCmdLine,intnCmdShow) { //callshared/exportedWinMain returnAfxWinMain(hInstance,hPrevInstance,lpCmdLine,nCmdShow); } 其中有宏定义:#define_tWinMainwWinMain intAFXAPIAfxWinMain(HINSTANCEhInstance,HINSTANCEhPrevInstance, LPTSTRlpCmdLine,intnCmdShow) { ASSERT(hPrevInstance==NULL); intnReturnCode=-1; CWinThread*pThread=AfxGetThread( );;//CWinApp是从CWinThread派 生的, CWinApp*pApp=AfxGetApp( );//实质上就是pThread==pApp //AFXinternalinitialization if(!AfxWinInit(hInstance,hPrevInstance,lpCmdLine,n

文档评论(0)

1亿VIP精品文档

相关文档