Custom window class name in MFC

Source: Internet
Author: User
Tags assert bool

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;
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.