VC++深入详解-第三章学习心得

来源:互联网 发布:淘宝mp3 编辑:程序博客网 时间:2024/05/17 22:39

这个章节主要介绍MFC的执行过程,类似于Win32.。。。。

 

看了两遍,介绍MFC程序的运行是如何进行的,看的有点乱。

 

个人觉得不是特别重要,文章貌似主要在讲内部是如何实现的,既然已经封装好了,我们能用就行了。

 

看的不是特别明白,说说我看了以后了解到的内容

 

项目创建完成后有五个文件。分别是CMainFrame,CXXXApp,CXXXDoc,CXXXView,CAboutDolg

 

MFC的执行过程是通过类产生的对象进行控制的theApp,不同于Win32程序产生句柄,所以要对程序对应的对象进行初始化。

所以执行过程和Win32程序的执行有点区别,感觉作者给我们讲解的目的貌似是在说明:MFC的执行过程和Win32的

执行过程类似,只不过MFC进行了封装。

 

/////////////////////////////////////////////////////////////////////////////// Standard WinMain implementation//  Can be replaced as long as 'AfxWinInit' is called firstint AFXAPI AfxWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,LPTSTR lpCmdLine, int nCmdShow){ASSERT(hPrevInstance == NULL);int nReturnCode = -1;CWinThread* pThread = AfxGetThread();//指向上面的theAppCWinApp* pApp = AfxGetApp();//指向上面的theApp// AFX internal initializationif (!AfxWinInit(hInstance, hPrevInstance, lpCmdLine, nCmdShow))goto InitFailure;// App global initializations (rare)if (pApp != NULL && !pApp->InitApplication())goto InitFailure;// Perform specific initializationsif (!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:#ifdef _DEBUG// Check for missing AfxLockTempMap callsif (AfxGetModuleThreadState()->m_nTempMapLock != 0){TRACE1("Warning: Temp map lock count non-zero (%ld).\n",AfxGetModuleThreadState()->m_nTempMapLock);}AfxLockTempMaps();AfxUnlockTempMaps(-1);#endifAfxWinTerm();return nReturnCode;}/////////////////////////////////////////////////////////////////////////////

 

BOOL AFXAPI AfxEndDeferRegisterClass(LONG fToRegister){// mask off all classes that are already registeredAFX_MODULE_STATE* pModuleState = AfxGetModuleState();fToRegister &= ~pModuleState->m_fRegisteredClasses;if (fToRegister == 0)return TRUE;LONG fRegisteredClasses = 0;// common initializationWNDCLASS wndcls;//设计窗口类memset(&wndcls, 0, sizeof(WNDCLASS));   // start with NULL defaultswndcls.lpfnWndProc = DefWindowProc;wndcls.hInstance = AfxGetInstanceHandle();wndcls.hCursor = afxData.hcurArrow;INITCOMMONCONTROLSEX init;init.dwSize = sizeof(init);// work to register classes as specified by fToRegister, populate fRegisteredClasses as we goif (fToRegister & AFX_WND_REG){// Child windows - no brush, no icon, safest default class styleswndcls.style = CS_DBLCLKS | CS_HREDRAW | CS_VREDRAW;wndcls.lpszClassName = _afxWnd;if (AfxRegisterClass(&wndcls))//注册窗口类fRegisteredClasses |= AFX_WND_REG;}.....}/////////////////////////////////////////////////////////////////////////////

 

*

*

*

就不一一列举了,就那几个流程了

 

窗口类和窗口的关系

窗口类里面有具体的窗口定义。

当窗口类over了,窗口肯定也over了(窗口在窗口类里面)

当窗口over了,窗口类没over哦,只要窗口类愿意,窗口可以继续生成

 

 

在窗口中显示按钮。

想在哪里增加按钮就在那里添加WM_CREATE

然后添加BUTTON之类的东西,记得BUTTON的定义要放到类定义里面,不然花括号}结束 创建的BUTTON对象也就没有了,也就不会程序中显示出来

另外创建BUTTON之类的东西 记得要调用显示函数(showWindow),或者在BUTTON里的式样里指定显示WS_VISIBLE

代码如下:

int CAView::OnCreate(LPCREATESTRUCT lpCreateStruct) {if (CView::OnCreate(lpCreateStruct) == -1)return -1;// TODO: Add your specialized creation code herem_btn.Create("刘凯­",WS_CHILD |WS_VISIBLE| BS_AUTO3STATE   ,CRect(0,0,100,100),this,1);//m_btn.ShowWindow(SW_SHOWNORMAL);return 0;}