MFC encapsulates many commonly used controls, the class name also to the encapsulation, did not provide a clear interface, with the win API to write the window program, the first step is to register the window class.
At this point the class name and title name are registered together, so the title can be very good for users to set, the class name should be very simple, unfortunately, MFC did not do so, perhaps because the window name can be constantly changed, and the class name cannot. The class name of the window is a create to determine, to create, to the window to select a registered window class name, as a parameter window to create the OK, CWnd's create finally came to the CreateEx, see CreateEx will be clear many
BOOL Cwnd::createex (DWORD dwexstyle, LPCTSTR lpszClassName,
LPCTSTR lpszWindowName, DWORD dwstyle,
Const rect& RECT, cwnd* pParentWnd, UINT NID,
LPVOID lpparam/* = NULL */)
{
Return CreateEx (dwExStyle, lpszClassName, lpszWindowName, Dwstyle,
Rect.left, Rect.top, Rect.right-rect.left, Rect.bottom-rect.top,
Pparentwnd->getsafehwnd (), (Hmenu) (uint_ptr) NID, Lpparam);
}
BOOL Cwnd::createex (DWORD dwexstyle, LPCTSTR lpszClassName,
LPCTSTR lpszWindowName, DWORD dwstyle,
int x, int y, int nwidth, int nheight,
HWND hwndparent, Hmenu nidorhmenu, LPVOID lpparam)
{
ASSERT (lpszclassname = NULL | | AfxIsValidString (lpszclassname) | |
Afxisvalidatom (lpszClassName));
Ensure_arg (lpszWindowName = = NULL | | AfxIsValidString (lpszWindowName));
Allow modification of several common create parameters
CREATESTRUCT cs;
Cs.dwexstyle = dwExStyle;
Cs.lpszclass = lpszClassName;
Cs.lpszname = lpszWindowName;
Cs.style = dwstyle;
cs.x = x;
Cs.y = y;
cs.cx = nwidth;
Cs.cy = nheight;
Cs.hwndparent = hwndparent;
Cs.hmenu = Nidorhmenu;
Cs.hinstance = AfxGetInstanceHandle ();
Cs.lpcreateparams = Lpparam;
if (! PreCreateWindow (CS))
{
PostNcDestroy ();
return FALSE;
}
Afxhookwindowcreate (this);
HWND hwnd =:: Afxctxcreatewindowex (Cs.dwexstyle, Cs.lpszclass,
Cs.lpszname, Cs.style, Cs.x, Cs.y, cs.cx, Cs.cy,
Cs.hwndparent, Cs.hmenu, Cs.hinstance, cs.lpcreateparams);
#ifdef _DEBUG
if (hWnd = NULL)
{
TRACE (traceappmsg, 0, "Warning:window creation Failed:getlasterror returns 0x%8.8x\n",
GetLastError ());
}
#endif
if (! Afxunhookwindowcreate ())
PostNcDestroy (); Cleanup if CreateWindowEx fails too soon
if (hWnd = NULL)
return FALSE;
ASSERT (hWnd = = m_hwnd); Should have been set in Send MSG hook
return TRUE;
}