Chapter 15: Fundamental Controls Visual C++ and MFC Fundamentals
happen. In the same way, when this method is called with the SW_HIDE argument, the
control would be hidden, whether it was already hidden or not.
If you want to check the visibility of a control before calling the ShowWindow() method,
you can call the CWnd::IsWindowVisible() method. Its syntax is:
BOOL IsWindowVisible() const;
This method returns TRUE if the control that called it is already visible. If the control is
hidden, the method returns FALSE.
14.2.10The Window’s Availability...............................................................
We saw that when a control has been created, it is available to the user who can interact
with its value. This is because a control usually has its Disable property to False or
unchecked. A control is referred to as disabled if the user can see it but cannot change its
value.
If for any reason a control is disabled, to enable it, you can call the
CWnd::EnableWindow() method. In fact, the EnableWindow() method is used either
to enable or to disable a window. Its syntax is:
BOOL EnableWindow(BOOL bEnable = TRUE);
Here is an example that disables a control called Memo:
void CSecondDlg::OnDisableMemo()
{
// TODO: Add your control notification handler code here
Memo->EnableWindow(FALSE);
}
When calling the EnableWindow() method, if you pass the FALSE value, the control is
disabled, whether it was already disabled or not. If you pass the TRUE constant, it gets
enabled even it was already enabled. Sometimes you may want to check first whether the
control is already enabled or disabled. This can be accomplished by calling the
CWnd::IsWindowEnabled(). Its syntax is:
BOOL IsWindowEnabled( ) const;
This method checks the control that called it. If the control is enabled, the member
function returns TRUE. If the control is disabled, this method returns FALSE. Here is an
example:
void CSecondDlg::OnDisableMemo()
{
// TODO: Add your control notification handler code here
if( Memo->IsWindowEnabled() == TRUE )
Memo->EnableWindow(FALSE);
else // if( !Memo->IsWindowEnabled() )
Memo->EnableWindow();
}
Here is a simplified version of the above code: