VC初学者入门系列之一:窗口类的诞生
2006-07-20 11:38:32 来源:WEB开发网核心提示: #define AfxDeferRegisterClass(fClass) \((afxRegisteredClasses & fClass) ? TRUE:AfxEndDeferRegisterClass(fClass) #define afxRegisteredClasses AfxG
#define AfxDeferRegisterClass(fClass) \
((afxRegisteredClasses & fClass) ? TRUE:AfxEndDeferRegisterClass(fClass)
#define afxRegisteredClasses AfxGetModuleState()->m_fRegisteredClasses
BOOL AFXAPI AfxEndDeferRegisterClass(short fClass)
{
WNDCLASS wndCls;
wndCls.lpfnWndProc = DefWindowProc;
if(fClass & AFX_WND_REG)
{
wndCls.lpszClassName=_afxWnd;
AfxRegisterClass(&wndCls);
}else if(fClass & AFX_WNDOLECONTROL_REG)
{
wndCls.lpszClassName=_afxWndOleControl;
AfxRegisterClass(&wndCls);
}else if(fClass & AFX_WNDCONTROLBAR_REG)
{
wndCls.lpszClassName=_afxWndControlBar;
AfxRegisterClass(&wndCls);
}else if(fClass & AFX_WNDMDIFRAME_REG)
{
RegisterWithIcon(&wndCls,_afxWndMDIFrame,AFX_IDI_MDIFRAME);
}else if(fClass & AFX_WNDFRAMEORVIEW_REG)
{
RegisterWithIcon(&wndCls,_afxWndFrameOrView,AFX_IDI_STD_FRAME);
}else if(fClass & AFX_WNDCOMMCTLS_REG)
{
InitCommonControls();
}
}
从上面的代码可以看出,AfxDeferRegisterClass函数首先判断该窗口类是否注册,如已注册则直接返回,否则调用AfxEndDeferRegisterClass进行注册,即注册要求的默认窗口类。其中RegisterWithIcon和InitCommonControls最终也是转化为调用AfxRegisterClass,而AfxRegisterClass函数调用RegisterClass进行注册,啊,终于看到SDK中的RegisterClass了,看到它总有一种亲切感!
更多精彩
赞助商链接