在CMainFrame类中注册的类,为何在视类中也能识别呢?如下,首先在框架类中注册一个类 sunxin.org
在框架类的 PreCreateWindow 中注册类 sunxin.org
BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
{
if( !CFrameWnd::PreCreateWindow(cs) )
return FALSE;
// TODO: Modify the Window class or styles here by modifying
//  the CREATESTRUCT cs
WNDCLASS wndcls;
wndcls.cbClsExtra=0;
wndcls.cbWndExtra=0;
wndcls.hbrBackground=(HBRUSH)GetStockObject(BLACK_BRUSH);
wndcls.hCursor=LoadCursor(NULL,IDC_HELP);
wndcls.hIcon=LoadIcon(NULL,IDI_ERROR);
wndcls.hInstance=AfxGetInstanceHandle();
wndcls.lpfnWndProc=::DefWindowProc;
wndcls.lpszClassName="sunxin.org";
wndcls.lpszMenuName=NULL;
wndcls.style=CS_HREDRAW | CS_VREDRAW; RegisterClass(&wndcls);
cs.lpszClass="sunxin.org"; return TRUE;
}
然后,在视类中竟然可以引用这个才框架类中注册的类:xunxin.orgBOOL CP314View::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
//  the CREATESTRUCT cs //这里为何可以识别 sunxin.org 这个类名呢?
//这个类名是 CMainFrame 类中注册的呀???
cs.lpszClass="sunxin.org";
return CView::PreCreateWindow(cs);
}