WinMain函数简介
Winmain是windows平台下应用程序的入口函数。
程序实现的步骤为:Winmain函数的定义->创建一个窗口->进行消息的循环->编写窗口过程函数。
形式为:
Int WINAPI WinMain(
HINSTANCE hInstance, //当前实例的句柄
HINSTANCE hPrevInstance, //前一个实例的句柄
LPTSTR lpCmdLine, //命令行参数
Int nCmdShow //窗体显示形式(最大化、最小化)
);
MFC中为
Extern “C” int WINAPI
_tWinMain(HINSTANCE hinstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine,int nCmdShow)
{
// call shared/exported WinMain
Return AfxWinMain(hinstance, hPrevInstance, lpCmdLine, nCmdShow);
}
实际上 _tWinMain 就是WinMain 而WinMain函数实际调用AfxWinMain函数。
程序流程:全局变量空间开辟及初始化->WinMain->AfxWinMain->在AfxWinMain函数中获取pApp 和 pThread 类型变量->设计窗口类->注册窗口类->创建窗口->显示窗口->更新窗口->消息循环->窗口过程函数->pApp.InitApplication、pThread->InitInstance
theApp对象唯一标示MFC应用程序本身,派生于CWinApp应用程序类。
Int AFXAPI AfxWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,LPTSTR lpCmdLine,int nCmdShow)
{
…
CWinThread* pThread = AfxGetThread();
CwinApp* pApp = AfxGetApp();
…
}
- 上一篇: 截取字符串中的数据到数组
- 下一篇: C/C++ 获取文件长度(转)