windows应用程序:
设计窗口类
注册窗口类
产生窗口
显示窗口
更新窗口
消息循环
将消息路由到消息处理过程函数中处理
WinMain入口函数。
记得:大小写敏感!
1、MFC微软基础类
2、使用appwized生成的5个类都是派生出来的。以单文档为例:
CFrameWnd CView CDialog是由CWnd(所有与窗口有关的)派生的
类名C开头 表示一个类
CAboutDlg :CDialog
CMainFrame:CFrameWnd
CTestApp C+工程名+App :CWinApp
CTestDoc C+工程名+Doc :CDocument
CTestView C+工程名+View :CView
3、WinMain函数在哪呢?
编译时由链接器将它链接到程序中。
它在MFC文件夹/APPMODUL.CPP里面。
extern "C" int WINAPI
_tWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPTSTR lpCmdLine, int nCmdShow)
{
// call shared/exported WinMain
return AfxWinMain(hInstance, hPrevInstance, lpCmdLine, nCmdShow);
}
查找它的定义的地方:
#define _tWinMain WinMain
那怎么关联的呢?
CTestApp::CTestApp()
{
// TODO: add construction code here,
// Place all significant initialization in InitInstance
}
/
// The one and only CTestApp object
CTestApp theApp;
全局对象
先构造应用程序theApp对象,唯一表示这个应用程序,然后才进入WinMain函数。
构造函数的调用导致父对象构造函数的调用。
CWinApp在 APPCORE.CPP中。
CWinApp(LPCTSTR lpszAppName = NULL); // app name
在CTestApp无参数,实际上用的是默认参数NULL
在CWinApp构造函数种有:
pThreadState->m_pCurrentWinThread = this;
this指的是CTestApp的对象theApp
WinMain通过AfxWinMain完成功能
AfxWinMain 在MFC/WINMAIN.CPP中。
A:Application应用程序 f:Framework 框架 x无意义
找到:int AFXAPI AfxWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPTSTR lpCmdLine, int nCmdShow)
里面有
CWinApp* pApp = AfxGetApp();
pApp就是theApp
在这个函数里面完成上面的几个步骤
注册在哪?
在WINCORE.CPP中,函数名:BOOL AFXAPI AfxEndDeferRegisterClass(LONG fToRegister)