Visual C++ and MFC Programming 2nd Edition

(Martin Jones) #1

Chapter 12: Dialog-Based Windows Visual C++ and MFC Fundamentals


After placing the control on the host. This would display the Properties window that
allows you to visually set the characteristics of the control.

In Visual C++ .Net, the Properties window displays, by default, to the lower right side of
the IDE.

If you are creating or designing a control using the Custom button, on the Properties
window and in the Class Name box, you can type the desired name as above for the
control.

If you are programmatically creating the control, pass its name as string to the
lpszClassName argument of the Create() or the CreateEx() methods. Here is an example
that would start an edit box:

void CSecondDlg::OnThirdControl()
{
// TODO: Add your control notification handler code here
CWnd *Memo = new CWnd;

Memo->Create("BUTTON", );
}

Another option you have is to either declare a WNDCLASS variable and initialize it, or
call the AfxRegisterWndClass() function and pass it the desired values. As we saw in
the previous lesson, this function returns a string. You can pass that string to the
CWnd::Create() method as the class name. Here is an example:

void Whatever()
{
// TODO: Add your control notification handler code here
CWnd *First = new CWnd;
CString StrClsName = AfxRegisterWndClass(
CS_VREDRAW | CS_HREDRAW,
LoadCursor(NULL, IDC_CROSS),
(HBRUSH)GetStockObject(BLACK_BRUSH),
LoadIcon(NULL, IDI_WARNING));
First->Create(StrClsName, );
}

The other option you have is to specify the class name as NULL. In this case, the
compiler would use a default name:

void Whatever ()
{
// TODO: Add your control notification handler code here
CWnd *Second = new CWnd;

Second->Create(NULL, );
}

Practical Learning: Creating a Control



  1. On the Controls toolbox, click the Custom Control button and click on the top
    left section of the dialog box (you do not need to be precise, anywhere you place it
    will be fine)

Free download pdf