AfxGetApp()为什么能获取到theApp的指针?

2025-04-28 04:35:50
推荐回答(1个)
回答1:

基类CWinApp的构造里有设置:

pModuleState->m_pCurrentWinApp = this;


然后AfxGetApp可以获得这个结构,从里面拿出m_pCurrentWinApp

_AFXWIN_INLINE CWinApp* AFXAPI AfxGetApp()
{ return afxCurrentWinApp; }
#define afxCurrentWinApp    AfxGetModuleState()->m_pCurrentWinApp