最近又要重新学习MFC了。。。准备完整把MFC相关知识点记录下来,方便后面使用。
首先关注的是MFC的启动过程,MFC将WIN32 api函数封装到类里面使用,并隐藏了很多细节,先从启动过程来看。
程序一开始产生一个 CMFCApplication2App theApp; 由于是全局变量,所以在进入WinMain函数前就已经完成初始化了,该app类继承了CWinApp类,初始化时首先调用父类(CWinApp)的构造函数进行窗口类的设计。然后再进入WinMain函数(AfxWinMain)。
int AFXAPI AfxWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
_In_ LPTSTR lpCmdLine, int nCmdShow)
{
ASSERT(hPrevInstance == NULL);
int nReturnCode = -1;
CWinThread* pThread = AfxGetThread();
CWinApp* pApp = AfxGetApp();
// AFX internal initialization
if (!AfxWinInit(hInstance, hPrevInstance, lpCmdLine, nCmdShow))
goto InitFailure;
// App global initializations (rare)
if (pApp != NULL && !pApp->InitApplication())
goto InitFailure;
// Perform specific initializations
if (!pThread->InitInstance())
{
if (pThread->m_pMainWnd != NULL)