Visual C++ and MFC Programming 2nd Edition

(Martin Jones) #1

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


If you specify negative values for the left and top distances, either the left or the top
borders, respectively, will be hidden.

To set the dimensions of the control, if you are using the CreateWindow(), the
CreateWindowEx() functions, or the first version of the CreateEx() member function,
specify the nWidth for the width and the nHeight for the height of the control. If you
specify measures that are higher than the width of the body of the parent - x or the height
of the of the parent - y, the right border or the bottom border, respectively, of the control
will be hidden.

To specify the location and the dimensions of the control at the same time, pass a RECT
or a CRect variable as the rect 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, );

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

CWnd* Panel = new CStatic;
Panel->CreateEx(WS_EX_DLGMODALFRAME, "STATIC", NULL,
WS_CHILD | WS_VISIBLE | WS_BORDER,
132, 16, 220, 120, );

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