标签:
1. 单文档窗体
BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs) { if( !CFrameWndEx::PreCreateWindow(cs) ) return FALSE; WNDCLASS wndclass; ::GetClassInfo(AfxGetInstanceHandle(),cs.lpszClass,&wndclass); wndclass.lpszClassName=_T("CMainFrame"); VERIFY(AfxRegisterClass(&wndclass)); cs.lpszClass=wndclass.lpszClassName; return TRUE; }
2. 对话框窗体
2.1 注册新窗体类,在InitInstance()进行注册,如 RegisterDialogClass(_T("CMainFrame"));
void RegisterDialogClass(LPCTSTR szNewClassName) { WNDCLASSEX wc; wc.cbSize = sizeof(wc); GetClassInfoEx(0, _T("#32770"), &wc); wc.style &= ~CS_GLOBALCLASS; wc.lpszClassName = szNewClassName; RegisterClassEx(&wc); }
2.2 修改窗体类名为新注册的类名
.在资源视图里xxx.rc上右键选择属性,修改属性Mfc Mode为False
.选择对话框,将属性Class Name改为CMainFrame
3.Win32项目
修改MyRegisterClass函数中的lpszClassName值,同时调用CreateWindow创建窗体时对应的lpClassName传入值为CMainFrame
ATOM MyRegisterClass(HINSTANCE hInstance) { WNDCLASSEX wcex; wcex.cbSize = sizeof(WNDCLASSEX); wcex.style = CS_HREDRAW | CS_VREDRAW; wcex.lpfnWndProc = WndProc; wcex.cbClsExtra = 0; wcex.cbWndExtra = 0; wcex.hInstance = hInstance; wcex.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_WIN32)); wcex.hCursor = LoadCursor(NULL, IDC_ARROW); wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1); wcex.lpszMenuName = MAKEINTRESOURCE(IDC_WIN32); wcex.lpszClassName = _T("CMainFrame"); wcex.hIconSm = LoadIcon(wcex.hInstance, MAKEINTRESOURCE(IDI_SMALL)); return RegisterClassEx(&wcex); }
标签:
原文地址:http://www.cnblogs.com/rainboy2010/p/4422639.html