MFC视图结构框架分析教学资料_第1页
MFC视图结构框架分析教学资料_第2页
MFC视图结构框架分析教学资料_第3页
MFC视图结构框架分析教学资料_第4页
MFC视图结构框架分析教学资料_第5页
已阅读5页,还剩50页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、Good is good, but better carries it.精益求精,善益求善。MFC视图结构框架分析MFC文档视图结构框架分析1:程序的“导火索”theAppCmyApptheApp;在声明对象的同时,调用其构造函数。按C+的语法,首先要调用其基类Cwinapp的构造函数.这个文件主要用于应用程序的一些初始化操作。classCWinApp:publicCWinThreadDECLARE_DYNAMIC(CWinApp)public:/ConstructorCWinApp(LPCTSTRlpszAppName=NULL);CWinApp:CWinApp(LPCTSTRlpszApp

2、Name)if(lpszAppName!=NULL)m_pszAppName=_tcsdup(lpszAppName);elsem_pszAppName=NULL;/initializeCWinThreadstateAFX_MODULE_STATE*pModuleState=_AFX_CMDTARGET_GETSTATE();AFX_MODULE_THREAD_STATE*pThreadState=pModuleState-m_thread;ASSERT(AfxGetThread()=NULL);pThreadState-m_pCurrentWinThread=this;ASSERT(AfxG

3、etThread()=this);m_hThread=:GetCurrentThread();m_nThreadID=:GetCurrentThreadId();/initializeCWinAppstateASSERT(afxCurrentWinApp=NULL);/onlyoneCWinAppobjectpleasepModuleState-m_pCurrentWinApp=this;ASSERT(AfxGetApp()=this);/innon-runningstateuntilWinMainm_hInstance=NULL;m_hLangResourceDLL=NULL;m_pszHe

4、lpFilePath=NULL;m_pszProfileName=NULL;m_pszRegistryKey=NULL;m_pszExeName=NULL;m_pRecentFileList=NULL;m_pDocManager=NULL;m_atomApp=m_atomSystemTopic=NULL;m_lpCmdLine=NULL;m_pCmdInfo=NULL;/initializewaitcursorstatem_nWaitCursorCount=0;m_hcurWaitCursorRestore=NULL;/initializecurrentprinterstatem_hDevMo

5、de=NULL;m_hDevNames=NULL;m_nNumPreviewPages=0;/notspecified(defaultsto1)/initializeDAOstatem_lpfnDaoTerm=NULL;/willbesetifAfxDaoInitcalled/otherinitializationm_bHelpMode=FALSE;m_eHelpType=afxWinHelp;m_nSafetyPoolSize=512;/defaultsize2:theApp之后的隐藏代码,由他控制整个程序的流程。_tWinMain(HINSTANCEhInstance,HINSTANCEh

6、PrevInstance,LPTSTRlpCmdLine,intnCmdShow)/callshared/exportedWinMainreturnAfxWinMain(hInstance,hPrevInstance,lpCmdLine,nCmdShow);其中有宏定义:#define_tWinMainwWinMainintAFXAPIAfxWinMain(HINSTANCEhInstance,HINSTANCEhPrevInstance,LPTSTRlpCmdLine,intnCmdShow)ASSERT(hPrevInstance=NULL);intnReturnCode=-1;CWinT

7、hread*pThread=AfxGetThread();;/CWinApp是从CWinThread派生的,CWinApp*pApp=AfxGetApp();/实质上就是pThread=pApp/AFXinternalinitializationif(!AfxWinInit(hInstance,hPrevInstance,lpCmdLine,nCmdShow)/用于初始化gotoInitFailure;/Appglobalinitializations(rare)if(pApp!=NULL&!pApp-InitApplication()/用于初始化gotoInitFailure;/Perfor

8、mspecificinitializationsif(!pThread-InitInstance()/注意多态性virtualBOOLInitInstance();/又因为pThread=pApp,所以调用pApp-InitInstance()if(pThread-m_pMainWnd!=NULL)TRACE(traceAppMsg,0,Warning:Destroyingnon-NULLm_pMainWndn);pThread-m_pMainWnd-DestroyWindow();nReturnCode=pThread-ExitInstance();gotoInitFailure;nRetu

9、rnCode=pThread-Run();/控制消息循环InitFailure:#ifdef_DEBUG/CheckformissingAfxLockTempMapcallsif(AfxGetModuleThreadState()-m_nTempMapLock!=0)TRACE(traceAppMsg,0,Warning:Tempmaplockcountnon-zero(%ld).n,AfxGetModuleThreadState()-m_nTempMapLock);AfxLockTempMaps();AfxUnlockTempMaps(-1);#endifAfxWinTerm();retur

10、nnReturnCode;由上面的程序可以看到几个很重要的函数(1)AfxWinInit(hInstance,hPrevInstance,lpCmdLine,nCmdShow)gotoInitFailure;(2)pApp-InitApplication()(3)pThread-InitInstance()(4)pThread-Run()其中1,2也是完成程序的一些初始化工作,4主要是为了处理消息,3呢,很关键,我们运行时看到的窗口就是从这里产生。下面一一介绍3:程序自动产生的InitInstance()函数以下是自动生成的InitInstance()源程序:BOOLCmyApp:InitIn

11、stance()/如果一个运行在WindowsXP上的应用程序清单指定要/使用ComCtl32.dll版本6或更高版本来启用可视化方式,/则需要InitCommonControls()。否则,将无法创建窗口。InitCommonControls();CWinApp:InitInstance();/初始化OLE库if(!AfxOleInit()AfxMessageBox(IDP_OLE_INIT_FAILED);returnFALSE;AfxEnableControlContainer();/标准初始化/如果未使用这些功能并希望减小/最终可执行文件的大小,则应移除下列/不需要的特定初始化例程/更

12、改用于存储设置的注册表项/TODO:应适当修改该字符串,/例如修改为公司或组织名SetRegistryKey(_T(应用程序向导生成的本地应用程序);LoadStdProfileSettings(4);/加载标准INI文件选项(包括MRU)/注册应用程序的文档模板。文档模板/将用作文档、框架窗口和视图之间的连接CMultiDocTemplate*pDocTemplate;pDocTemplate=newCMultiDocTemplate(IDR_myTYPE,RUNTIME_CLASS(CmyDoc),RUNTIME_CLASS(CChildFrame),/自定义MDI子框架RUNTIME_C

13、LASS(CmyView);if(!pDocTemplate)returnFALSE;AddDocTemplate(pDocTemplate);/创建主MDI框架窗口CMainFrame*pMainFrame=newCMainFrame;if(!pMainFrame|!pMainFrame-LoadFrame(IDR_MAINFRAME)returnFALSE;m_pMainWnd=pMainFrame;/仅当具有后缀时才调用DragAcceptFiles/在MDI应用程序中,这应在设置m_pMainWnd之后立即发生/分析标准外壳命令、DDE、打开文件操作的命令行CCommandLineIn

14、focmdInfo;ParseCommandLine(cmdInfo);/调度在命令行中指定的命令。如果/用/RegServer、/Register、/Unregserver或/Unregister启动应用程序,则返回FALSE。if(!ProcessShellCommand(cmdInfo)/引发窗口注册returnFALSE;/主窗口已初始化,因此显示它并对其进行更新pMainFrame-ShowWindow(m_nCmdShow);pMainFrame-UpdateWindow();returnTRUE;其中,注册窗口用到了一下函数,比较长,如下:BOOLAFXAPIAfxEndDefe

15、rRegisterClass(LONGfToRegister)/maskoffallclassesthatarealreadyregisteredAFX_MODULE_STATE*pModuleState=AfxGetModuleState();fToRegister&=pModuleState-m_fRegisteredClasses;if(fToRegister=0)returnTRUE;LONGfRegisteredClasses=0;/commoninitializationWNDCLASSwndcls;memset(&wndcls,0,sizeof(WNDCLASS);/startw

16、ithNULLdefaultswndcls.lpfnWndProc=DefWindowProc;/窗口处理函数wndcls.hInstance=AfxGetInstanceHandle();wndcls.hCursor=afxData.hcurArrow;INITCOMMONCONTROLSEXinit;init.dwSize=sizeof(init);/worktoregisterclassesasspecifiedbyfToRegister,populatefRegisteredClassesaswegoif(fToRegister&AFX_WND_REG)/Childwindows-no

17、brush,noicon,safestdefaultclassstyleswndcls.style=CS_DBLCLKS|CS_HREDRAW|CS_VREDRAW;wndcls.lpszClassName=_afxWnd;if(AfxRegisterClass(&wndcls)fRegisteredClasses|=AFX_WND_REG;if(fToRegister&AFX_WNDOLECONTROL_REG)/OLEControlwindows-useparentDCforspeedwndcls.style|=CS_PARENTDC|CS_DBLCLKS|CS_HREDRAW|CS_VR

18、EDRAW;wndcls.lpszClassName=_afxWndOleControl;if(AfxRegisterClass(&wndcls)fRegisteredClasses|=AFX_WNDOLECONTROL_REG;if(fToRegister&AFX_WNDCONTROLBAR_REG)/Controlbarwindowswndcls.style=0;/controlbarsdonthandledoubleclickwndcls.lpszClassName=_afxWndControlBar;wndcls.hbrBackground=(HBRUSH)(COLOR_BTNFACE

19、+1);if(AfxRegisterClass(&wndcls)fRegisteredClasses|=AFX_WNDCONTROLBAR_REG;if(fToRegister&AFX_WNDMDIFRAME_REG)/MDIFramewindow(alsousedforsplitterwindow)wndcls.style=CS_DBLCLKS;wndcls.hbrBackground=NULL;if(_AfxRegisterWithIcon(&wndcls,_afxWndMDIFrame,AFX_IDI_STD_MDIFRAME)fRegisteredClasses|=AFX_WNDMDI

20、FRAME_REG;if(fToRegister&AFX_WNDFRAMEORVIEW_REG)/SDIFrameorMDIChildwindowsorviews-normalcolorswndcls.style=CS_DBLCLKS|CS_HREDRAW|CS_VREDRAW;wndcls.hbrBackground=(HBRUSH)(COLOR_WINDOW+1);if(_AfxRegisterWithIcon(&wndcls,_afxWndFrameOrView,AFX_IDI_STD_FRAME)fRegisteredClasses|=AFX_WNDFRAMEORVIEW_REG;if

21、(fToRegister&AFX_WNDCOMMCTLS_REG)/thisflagiscompatiblewiththeoldInitCommonControls()APIinit.dwICC=ICC_WIN95_CLASSES;fRegisteredClasses|=_AfxInitCommonControls(&init,AFX_WIN95CTLS_MASK);fToRegister&=AFX_WIN95CTLS_MASK;if(fToRegister&AFX_WNDCOMMCTL_UPDOWN_REG)init.dwICC=ICC_UPDOWN_CLASS;fRegisteredCla

22、sses|=_AfxInitCommonControls(&init,AFX_WNDCOMMCTL_UPDOWN_REG);if(fToRegister&AFX_WNDCOMMCTL_TREEVIEW_REG)init.dwICC=ICC_TREEVIEW_CLASSES;fRegisteredClasses|=_AfxInitCommonControls(&init,AFX_WNDCOMMCTL_TREEVIEW_REG);if(fToRegister&AFX_WNDCOMMCTL_TAB_REG)init.dwICC=ICC_TAB_CLASSES;fRegisteredClasses|=

23、_AfxInitCommonControls(&init,AFX_WNDCOMMCTL_TAB_REG);if(fToRegister&AFX_WNDCOMMCTL_PROGRESS_REG)init.dwICC=ICC_PROGRESS_CLASS;fRegisteredClasses|=_AfxInitCommonControls(&init,AFX_WNDCOMMCTL_PROGRESS_REG);if(fToRegister&AFX_WNDCOMMCTL_LISTVIEW_REG)init.dwICC=ICC_LISTVIEW_CLASSES;fRegisteredClasses|=_

24、AfxInitCommonControls(&init,AFX_WNDCOMMCTL_LISTVIEW_REG);if(fToRegister&AFX_WNDCOMMCTL_HOTKEY_REG)init.dwICC=ICC_HOTKEY_CLASS;fRegisteredClasses|=_AfxInitCommonControls(&init,AFX_WNDCOMMCTL_HOTKEY_REG);if(fToRegister&AFX_WNDCOMMCTL_BAR_REG)init.dwICC=ICC_BAR_CLASSES;fRegisteredClasses|=_AfxInitCommo

25、nControls(&init,AFX_WNDCOMMCTL_BAR_REG);if(fToRegister&AFX_WNDCOMMCTL_ANIMATE_REG)init.dwICC=ICC_ANIMATE_CLASS;fRegisteredClasses|=_AfxInitCommonControls(&init,AFX_WNDCOMMCTL_ANIMATE_REG);if(fToRegister&AFX_WNDCOMMCTL_INTERNET_REG)init.dwICC=ICC_INTERNET_CLASSES;fRegisteredClasses|=_AfxInitCommonCon

26、trols(&init,AFX_WNDCOMMCTL_INTERNET_REG);if(fToRegister&AFX_WNDCOMMCTL_COOL_REG)init.dwICC=ICC_COOL_CLASSES;fRegisteredClasses|=_AfxInitCommonControls(&init,AFX_WNDCOMMCTL_COOL_REG);if(fToRegister&AFX_WNDCOMMCTL_USEREX_REG)init.dwICC=ICC_USEREX_CLASSES;fRegisteredClasses|=_AfxInitCommonControls(&ini

27、t,AFX_WNDCOMMCTL_USEREX_REG);if(fToRegister&AFX_WNDCOMMCTL_DATE_REG)init.dwICC=ICC_DATE_CLASSES;fRegisteredClasses|=_AfxInitCommonControls(&init,AFX_WNDCOMMCTL_DATE_REG);if(fToRegister&AFX_WNDCOMMCTL_LINK_REG)init.dwICC=ICC_LINK_CLASS;fRegisteredClasses|=_AfxInitCommonControls(&init,AFX_WNDCOMMCTL_L

28、INK_REG);/savenewstateofregisteredcontrolspModuleState-m_fRegisteredClasses|=fRegisteredClasses;/specialcaseforallcommoncontrolsregistered,turnonAFX_WNDCOMMCTLS_REGif(pModuleState-m_fRegisteredClasses&AFX_WIN95CTLS_MASK)=AFX_WIN95CTLS_MASK)pModuleState-m_fRegisteredClasses|=AFX_WNDCOMMCTLS_REG;fRegi

29、steredClasses|=AFX_WNDCOMMCTLS_REG;/musthaveregisteredatleastasmamyclassesasrequestedreturn(fToRegister&fRegisteredClasses)=fToRegister;他是在PreCreateWindow中调用的注册,BOOLCFrameWnd:PreCreateWindow(CREATESTRUCT&cs)if(cs.lpszClass=NULL)VERIFY(AfxDeferRegisterClass(AFX_WNDFRAMEORVIEW_REG);cs.lpszClass=_afxWn

30、dFrameOrView;/COLOR_WINDOWbackgroundif(cs.style&FWS_ADDTOTITLE)cs.style|=FWS_PREFIXTITLE;cs.dwExStyle|=WS_EX_CLIENTEDGE;returnTRUE;BOOLCMainFrame:PreCreateWindow(CREATESTRUCT&cs)if(!CFrameWnd:PreCreateWindow(cs)returnFALSE;/TODO:ModifytheWindowclassorstylesherebymodifying/theCREATESTRUCTcsreturnTRUE

31、;BOOLCView:PreCreateWindow(CREATESTRUCT&cs)ASSERT(cs.style&WS_CHILD);if(cs.lpszClass=NULL)VERIFY(AfxDeferRegisterClass(AFX_WNDFRAMEORVIEW_REG);cs.lpszClass=_afxWndFrameOrView;/COLOR_WINDOWbackgroundif(cs.style&WS_BORDER)cs.dwExStyle|=WS_EX_CLIENTEDGE;cs.style&=WS_BORDER;returnTRUE;BOOLCTestView:PreC

32、reateWindow(CREATESTRUCT&cs)/TODO:ModifytheWindowclassorstylesherebymodifying/theCREATESTRUCTcsreturnCView:PreCreateWindow(cs);有几点要说明(1)m_pMainWnd,头文件里并没有这个变量呀?噢,这个在基类里定义的public类型的变量,所以,他是通过继承得到的。(2)你注意过吗,当我们一点运行,会默认出来一个视图窗口,这是谁调用的呢?哦,就是下面这几行,它调用了opendocument()函数。CCommandLineInfocmdInfo;ParseCommand

33、Line(cmdInfo);if(!ProcessShellCommand(cmdInfo)returnFALSE;(3)这个函数有个关键的地方CMultiDocTemplate*pDocTemplate;pDocTemplate=newCMultiDocTemplate(IDR_myTYPE,RUNTIME_CLASS(CmyDoc),RUNTIME_CLASS(CChildFrame),/自定义MDI子框架RUNTIME_CLASS(CmyView);if(!pDocTemplate)returnFALSE;AddDocTemplate(pDocTemplate);通过它,把视图,窗口和文

34、档结合起来。4:主窗口CMainFrame的创建(1)通过CMainFrame*pMainFrame=newCMainFrame;我们得到的是不断调用的基类CMainFrame:CMainFrame()/TODO:在此添加成员初始化代码CMDIFrameWnd:CMDIFrameWnd()m_hWndMDIClient=NULL;CFrameWnd:CFrameWnd()ASSERT(m_hWnd=NULL);m_nWindow=-1;/unknownwindowIDm_bAutoMenuEnable=TRUE;/autoenableonbydefaultm_lpfnCloseProc=NUL

35、L;m_hMenuDefault=NULL;m_hAccelTable=NULL;m_nIDHelp=0;m_nIDTracking=0;m_nIDLastMessage=0;m_pViewActive=NULL;m_cModalStack=0;/initializemodalitysupportm_phWndDisable=NULL;m_pNotifyHook=NULL;m_hMenuAlt=NULL;m_nIdleFlags=0;/noidleworkatstartm_rectBorder.SetRectEmpty();m_bHelpMode=HELP_INACTIVE;/notinShi

36、ft+F1helpmodem_dwPromptContext=0;m_pNextFrameWnd=NULL;/notinlistyetm_bInRecalcLayout=FALSE;m_pFloatingFrameClass=NULL;m_nShowDelay=-1;/nodelaypendingAddFrameWnd();(2)pMainFrame-LoadFrame(IDR_MAINFRAME)所引发的一系列BOOLCMDIFrameWnd:LoadFrame(UINTnIDResource,DWORDdwDefaultStyle,CWnd*pParentWnd,CCreateContex

37、t*pContext)if(!CFrameWnd:LoadFrame(nIDResource,dwDefaultStyle,pParentWnd,pContext)returnFALSE;/savemenutousewhennoactiveMDIchildwindowispresentASSERT(m_hWnd!=NULL);m_hMenuDefault=:GetMenu(m_hWnd);if(m_hMenuDefault=NULL)TRACE(traceAppMsg,0,Warning:CMDIFrameWndwithoutadefaultmenu.n);returnTRUE;BOOLCFr

38、ameWnd:LoadFrame(UINTnIDResource,DWORDdwDefaultStyle,CWnd*pParentWnd,CCreateContext*pContext)/onlydothisonceASSERT_VALID_IDR(nIDResource);ASSERT(m_nIDHelp=0|m_nIDHelp=nIDResource);m_nIDHelp=nIDResource;/IDforhelpcontext(+HID_BASE_RESOURCE)CStringstrFullString;if(strFullString.LoadString(nIDResource)

39、AfxExtractSubString(m_strTitle,strFullString,0);/firstsub-stringVERIFY(AfxDeferRegisterClass(AFX_WNDFRAMEORVIEW_REG);/attempttocreatethewindowLPCTSTRlpszClass=GetIconWndClass(dwDefaultStyle,nIDResource);CStringstrTitle=m_strTitle;if(!Create(lpszClass,strTitle,dwDefaultStyle,rectDefault,pParentWnd,MA

40、KEINTRESOURCE(nIDResource),0L,pContext)returnFALSE;/willselfdestructonfailurenormally/savethedefaultmenuhandleASSERT(m_hWnd!=NULL);m_hMenuDefault=:GetMenu(m_hWnd);/loadacceleratorresourceLoadAccelTable(MAKEINTRESOURCE(nIDResource);if(pContext=NULL)/sendinitialupdateSendMessageToDescendants(WM_INITIA

41、LUPDATE,0,0,TRUE,TRUE);returnTRUE;BOOLCFrameWnd:Create(LPCTSTRlpszClassName,LPCTSTRlpszWindowName,DWORDdwStyle,constRECT&rect,CWnd*pParentWnd,LPCTSTRlpszMenuName,DWORDdwExStyle,CCreateContext*pContext)HMENUhMenu=NULL;if(lpszMenuName!=NULL)/loadinamenuthatwillgetdestroyedwhenwindowgetsdestroyedHINSTA

42、NCEhInst=AfxFindResourceHandle(lpszMenuName,RT_MENU);if(hMenu=:LoadMenu(hInst,lpszMenuName)=NULL)TRACE(traceAppMsg,0,Warning:failedtoloadmenuforCFrameWnd.n);PostNcDestroy();/perhapsdeletetheC+objectreturnFALSE;m_strTitle=lpszWindowName;/savetitleforlaterif(!CreateEx(dwExStyle,lpszClassName,lpszWindo

43、wName,dwStyle,rect.left,rect.top,rect.right-rect.left,rect.bottom-rect.top,pParentWnd-GetSafeHwnd(),hMenu,(LPVOID)pContext)TRACE(traceAppMsg,0,Warning:failedtocreateCFrameWnd.n);if(hMenu!=NULL)DestroyMenu(hMenu);returnFALSE;returnTRUE;因为CFrameWnd没有重新写CreateEX,所以是调用的基类的CreateEx的函数:BOOLCWnd:CreateEx(D

44、WORDdwExStyle,LPCTSTRlpszClassName,LPCTSTRlpszWindowName,DWORDdwStyle,intx,inty,intnWidth,intnHeight,HWNDhWndParent,HMENUnIDorHMenu,LPVOIDlpParam)/allowmodificationofseveralcommoncreateparametersCREATESTRUCTcs;cs.dwExStyle=dwExStyle;cs.lpszClass=lpszClassName;cs.lpszName=lpszWindowName;cs.style=dwSt

45、yle;cs.x=x;cs.y=y;cs.cx=nWidth;cs.cy=nHeight;cs.hwndParent=hWndParent;cs.hMenu=nIDorHMenu;cs.hInstance=AfxGetInstanceHandle();cs.lpCreateParams=lpParam;if(!PreCreateWindow(cs)PostNcDestroy();returnFALSE;AfxHookWindowCreate(this);HWNDhWnd=:CreateWindowEx(cs.dwExStyle,cs.lpszClass,cs.lpszName,cs.style

46、,cs.x,cs.y,cs.cx,cs.cy,cs.hwndParent,cs.hMenu,cs.hInstance,cs.lpCreateParams);#ifdef_DEBUGif(hWnd=NULL)TRACE(traceAppMsg,0,Warning:Windowcreationfailed:GetLastErrorreturns0 x%8.8Xn,GetLastError();#endifif(!AfxUnhookWindowCreate()PostNcDestroy();/cleanupifCreateWindowExfailstoosoonif(hWnd=NULL)return

47、FALSE;ASSERT(hWnd=m_hWnd);/shouldhavebeensetinsendmsghookreturnTRUE;可以看到,:CreateWindowEx是一个全局的函数,在其中触发WM_CREATE消息,进而调用我们自己定义的CMainFrame:OnCreate()intCMainFrame:OnCreate(LPCREATESTRUCTlpCreateStruct)if(CMDIFrameWnd:OnCreate(lpCreateStruct)=-1)return-1;if(!m_wndToolBar.CreateEx(this,TBSTYLE_FLAT,WS_CH

48、ILD|WS_VISIBLE|CBRS_TOP|CBRS_GRIPPER|CBRS_TOOLTIPS|CBRS_FLYBY|CBRS_SIZE_DYNAMIC)|!m_wndToolBar.LoadToolBar(IDR_MAINFRAME)TRACE0(未能创建工具栏n);return-1;/未能创建if(!m_wndStatusBar.Create(this)|!m_wndStatusBar.SetIndicators(indicators,sizeof(indicators)/sizeof(UINT)TRACE0(未能创建状态栏n);return-1;/未能创建/TODO:如果不需要工具

49、栏可停靠,则删除这三行m_wndToolBar.EnableDocking(CBRS_ALIGN_ANY);EnableDocking(CBRS_ALIGN_ANY);DockControlBar(&m_wndToolBar);return0;5:运行后为什么能产生CMainFarme,文档,视图以及视图外包围的farme呢?你注意过吗,当我们一点运行,会默认出来一个视图窗口,这是谁调用的呢?哦,就是下面这几行,它调用voidCWinApp:OnFileNew()函数.CCommandLineInfocmdInfo;ParseCommandLine(cmdInfo);if(!ProcessSh

50、ellCommand(cmdInfo)returnFALSE;你可以自己跟踪以下。这里有个小技巧,你可以在BOOLCmyDoc:OnNewDocument()处设立断点,然后“跳出”,最后你会达到起始点!ProcessShellCommand(cmdInfo)voidCWinApp:OnFileNew()if(m_pDocManager!=NULL)m_pDocManager-OnFileNew();/接着调用下面的函数voidCDocManager:OnFileNew()if(m_templateList.IsEmpty()TRACE(traceAppMsg,0,Error:nodocume

51、nttemplatesregisteredwithCWinApp.n);AfxMessageBox(AFX_IDP_FAILED_TO_CREATE_DOC);return;CDocTemplate*pTemplate=(CDocTemplate*)m_templateList.GetHead();if(m_templateList.GetCount()1)/morethanonedocumenttemplatetochoosefrom/bringupdialogpromptinguserCNewTypeDlgdlg(&m_templateList);INT_PTRnID=dlg.DoModa

52、l();if(nID=IDOK)pTemplate=dlg.m_pSelectedTemplate;elsereturn;/none-canceloperationASSERT(pTemplate!=NULL);ASSERT_KINDOF(CDocTemplate,pTemplate);pTemplate-OpenDocumentFile(NULL);/接着调用下面的函数/ifreturnsNULL,theuserhasalreadybeenalertedCDocument*CMultiDocTemplate:OpenDocumentFile(LPCTSTRlpszPathName,BOOLb

53、MakeVisible)CDocument*pDocument=CreateNewDocument();/产生模板控制之一:文档if(pDocument=NULL)TRACE(traceAppMsg,0,CDocTemplate:CreateNewDocumentreturnedNULL.n);AfxMessageBox(AFX_IDP_FAILED_TO_CREATE_DOC);returnNULL;ASSERT_VALID(pDocument);BOOLbAutoDelete=pDocument-m_bAutoDelete;pDocument-m_bAutoDelete=FALSE;/dontdestroyifsomethingg

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论