1,CWnd
--窗口操作相关的基类;
--CWnd m_wd; //此时,m_wd作为CWnd类可以使用,但其m_hwnd并没有关联上窗口;
--w_hwnd = CreateWindowEx(); //窗口创建了以后,才是CWnd和窗口关联起来,此时w_hwnd才能使用;
--CWnd如何和窗口相关联;
--其封装了Win32 API,比如CreateWindowEx(), ::ShowWindow(); UpdateWindow()等;
--CWnd成员HWND m_hwnd用来记录创建的窗口,这样可以通过获取CWnd类m_hwnd来随时获取窗口;
--CWnd类销毁时,其存放的窗口必须销毁,应为类的生命周期到了,m_hwnd指示窗口应该释放掉;
--窗口销毁时,CWnd类的生命周期未必到了,所以CWnd未必和窗口一起销毁,CWnd生命周期可以更长;
-------------------------------------
2,MFC程序执行流程
--在C**App()::C**App()处设断点,appmodul.cpp的 _tWinMain()处设置断点
--调试: 先进入C**App()::C**App() , 而后 _tWinMain();
1,全局对象/变量先于 WinMain();
--C**App theApp全局对象代表了应用程序本省,相当于Win32 Console程序的hInstance;
--C**App: public CWinApp,所以会调用CWinApp::CWinApp();
2,WinMain()
--C:/Program Files/Microsoft Visual Studio 9.0/VC/atlmfc/src/mfc
--搜索文件包含的文字 "WinMain" => appmodul.cpp
--验证其为mfc程序入口点: 用classwizard生成mfc程序,在appmodul.cpp的 _tWinMain()处设置断点,启动程序断住,验证成功;
--调用AfxWinMain();
1,CWinThread* pThread = AfxGetThread(); //获取指向theApp的指针;
2,CWinApp* pApp = AfxGetApp(); //获取指向theApp的指针; [CWinApp:public CWinThread]
3,pThread->InitInstance(); //虚函数,将调用CMy9_styleApp::InitInstance();
3.1,AfxEndDeferRegisterClass(); //注册窗口类;--可看到mfc默认注册过的窗口类;
--调用AfxRegisterClass()注册窗口类;
3.2,ProcessShellCommand(cmdInfo) //cmdInfo.m_nShellcode = newfile;
--CFrameWnd::LoadFrame()
1,CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
--CFrameWnd::PreCreateWindow(CREATESTRUCT& cs) //检验是否注册,给窗口赋属性;
2,,CFrameWnd::Create() //创建窗口;
--CWnd::CreateEx();
4,nReturnCode = pThread->Run(); //消息循环;
--CWinThread::Run();
--AfxInternalPumpMessage();
::GetMessage(&(pState->m_msgCur), NULL, NULL, NULL)
::TranslateMessage(&(pState->m_msgCur))
::DispatchMessage(&(pState->m_msgCur));
-------------------------------------
3,CWinApp
--C:/Program Files/Microsoft Visual Studio 9.0/VC/atlmfc/src/mfc
--搜索文件包含的文字 "CWinApp" => appcore.cpp
--构造函数 CWinApp::CWinApp(LPCTSTR lpszAppName); //默认参数
--将this(theApp)指针传入 pThreadState->m_pCurrentWinThread = this;