正文

SDI初始化机制探密 , 你知道吗?2006-12-15 15:25:00

【评论】 【打印】 【字体: 】 本文链接:http://blog.pfan.cn/yuqiexing/21611.html

分享到:

学习MFC这么久,直到前几天才弄明白了一个长久困扰我的问题.并且是一个很重要的问题,是关于MFC的机制.下面我拿出来和大家一起共享一下,请多指教.   大家都知道,对于一个SDI,不管是新建还是打开一份文档,都会引发一系列的操作.                               而我们的SDI开始运行时,都会自动先新建一份文档.确实它跟点击”新建”菜单项的操作是相同的.那么到底是在哪里自动调用这个菜单项的操作的呢?   到处都没找到.后来无意之间,在InitInstance中看到一个奇怪的家伙:   BOOL CManageApp::InitInstance() {        AfxEnableControlContainer();          // Standard initialization        // If you are not using these features and wish to reduce the size        //  of your final executable, you should remove from the following        //  the specific initialization routines you do not need.   #ifdef _AFXDLL        Enable3dControls();                     // Call this when using MFC in a shared DLL #else        Enable3dControlsStatic();      // Call this when linking to MFC statically #endif          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(CManageDoc),               RUNTIME_CLASS(CMainFrame),       // main SDI frame window               RUNTIME_CLASS(CManageView));        AddDocTemplate(pDocTemplate);          // Parse command line for standard shell commands, DDE, file open        CCommandLineInfo cmdInfo;        ParseCommandLine(cmdInfo);          // Dispatch commands specified on the command line        if (!ProcessShellCommand(cmdInfo))               return FALSE;          // The one and only window has been initialized, so show and update it.        m_pMainWnd->ShowWindow(SW_SHOW);        m_pMainWnd->UpdateWindow();          return TRUE; } 这个函数到底是干吗的?带着这种疑问,我去安装文件中找到:   BOOL  CWinApp ::  ProcessShellCommand(CCommandLineInfo  &info) {        …….        Switch (info .m_nshellCommand) {        Case  CComandLineInfo::FileNew:       If(!AfxGetApp( ) - >OnCmdMsg( ID_FILE_NEW, 0 ,NULL , NULL))                  OnFileNew( ); …….. }       原来如此!    

阅读(5888) | 评论(0)


版权声明:编程爱好者网站为此博客服务提供商,如本文牵涉到版权问题,编程爱好者网站不承担相关责任,如有版权问题请直接与本文作者联系解决。谢谢!

评论

暂无评论
您需要登录后才能评论,请 登录 或者 注册