Visual C++ and MFC Programming 2nd Edition

(Martin Jones) #1

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


If you visually add controls to your application, their identifiers are automatically added
to this file. Even if you change the identifier of the control, Visual C++ updates this file.
You can also manually add identifiers to this file, provided you know why you are doing
that.

If you are programmatically creating a control using the CreateWindow() or the
CreateWindowEx() functions, you do not need to specify the identifier. If you are
programmatically creating a control, you can locally set an identifier by specifying a
(randomly selected) decimal or hexadecimal number as the nID argument of the Create()
or the second version of the CreateEx() methods. Here are examples:

BOOL CBordersDlg::OnInitDialog()
{
CDialog::OnInitDialog();

// TODO: Add extra initialization here
CWnd* btnApply = new CWnd;
RECT Recto = {12, 16, 128, 64};
btnApply->Create("BUTTON", "&Apply", WS_CHILD | WS_VISIBLE,
Recto, this, 0x10);

CWnd *btnDismiss = new CWnd;
btnDismiss->Create("BUTTON", "&Dismiss", WS_CHILD | WS_VISIBLE,
CRect(12, 68, 128, 120), this, 258 );

return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
Free download pdf