Visual C++ and MFC Fundamentals Chapter 15: Fundamental Controls
Horz Align: Default
Vert Align: Top
Horz Align: Left
Vert Align: Default
Horz Align: Default or Center
Vert Align: Default or Center
Horz Align: Right
Vert Align: Default
Horz Align: Default
Vert Align: Bottom
After creating a control, to make sure that it displays when its host control comes up, set
its Visible property to True or checked (the default). Otherwise, if you want it to be
hidden for example to wait for an intermediary action from the user, you can set its
Visible property to False or unchecked. For example, to display a control, whether it is
hidden or not, call the CWnd::ShowWindow() method and pass SW_SHOW as its
argument:
BOOL CDialog5Dlg::OnInitDialog()
{
CDialog::OnInitDialog();
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
// TODO: Add extra initialization here
m_Submit.ShowWindow(SW_SHOW);
return TRUE; // return TRUE unless you set the focus to a control
}
In the same way, to hide a control, call it by passing the SW_HIDE constant as argument.
For the user to be able to use a control such as clicking a button, the control must allow it.
This characteristic of Windows objects is controlled by the CWnd::EnableWindow()
method. Its syntax is:
BOOL EnableWindow(BOOL bEnable = TRUE);
This method is used to enable or disable a control. The default value of the argument
bEnable is set to TRUE, which would display a control. To disable a control, set the
argument to FALSE. Here is an example:
void CDialog5Dlg::OnLetItBe()
{
// TODO: Add your control notification handler code here
m_Submit.EnableWindow(FALSE);
}
15.4.3..Buttons Messages................................................................................
The most regular action users perform on a button is to click it. When a user does this, the
button sends a BN_CLICKED message. In some but rare circumstances, you may also
ask the user to double-click a button. Over all, you will take care of most message
handling when the user clicks a button.