mfc封装

MFC将大部分函数都进行了封装,程序员只要改写部分重要的virtual函数即可,这往往使初学者摸不着头脑,连个WinMain函数都看不到,程序从哪开始从哪结束?基本的条理搞不清,永远也不会有提高。下面简单讲下基运行过程.

1,CMyWinApp theApp  程序从这里开始

2,_tWinMain()   在APPMODUL.CPP 它实际上只调用AfxWinMain函数

3,AfxWinMain()   WINAMIN.CPP,去掉一些次要信息,它作的事就是:

int AFXAPI AfxWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,

LPTSTR lpCmdLine, int nCmdShow)

{

int nReturnCode = -1;

CWinThread* pThread = AfxGetThread();

CWinApp* pApp = AfxGetApp();  ->实际上就是取得CMyWinApp对象指针

AfxWinInit(hInstance, hPrevInstance, lpCmdLine, nCmdShow)

pApp->InitApplication()

pThread->InitInstance()

pThread->Run();

AfxWinTerm();

return nReturnCode;

}

其中:

AfxGetApp();   AFXWIN.CPP中

InitApplication()  AFXWIN.CPP中

InitInstance()   AFXWIN.CPP中

实际上AfxWinMainy就是调用:

CWinApp::InitApplication 因为我们程序没有改写它

CMyWinApp::InitInstance  我们改写了它且必须改写它,为什么?看源码就能证明一切

BOOL CWinApp::InitInstance() APPCORE.CPP中

{

return TRUE;

}

看到了吧,它什么也没干,直接return TRUE;

CWinApp::Run();

4:AfxWinInit()   AFX内部初始化操作,APPINIT.CPP中,贴下源码,如下:

BOOL AFXAPI AfxWinInit(HINSTANCE hInstance, HINSTANCE hPrevInstance,

LPTSTR lpCmdLine, int nCmdShow)

{

..,去掉部分

pModuleState->m_hCurrentInstanceHandle = hInstance;

pModuleState->m_hCurrentResourceHandle = hInstance;

CWinApp* pApp = AfxGetApp();

if (pApp != NULL)

{

  // Windows specific initialization (not done if no CWinApp)

  pApp->m_hInstance = hInstance;

  pApp->m_hPrevInstance = hPrevInstance;

  pApp->m_lpCmdLine = lpCmdLine;

  pApp->m_nCmdShow = nCmdShow;

  pApp->SetCurrentHandles();

}

if (!afxContextIsDLL)

  AfxInitThread();

return TRUE;

}

可以看到。它主要进行一些初始化工作.其中:

AfxInitThread()  在THRDCORE.CPP中

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值