Visual C++ and MFC Fundamentals Chapter 15: Fundamental Controls
BOOL ShowWindow(int nCmdShow);
This method is used to display or hide any window that is a descendent of CWnd. Its
argument, nCmdShow, specifies what to do with the appearance or disappearance of the
object. Its possible values are:
Value Description
SW_SHOW Displays a window and makes it visible
SW_SHOWNORMAL Displays the window in its regular size. In most
circumstances, the operating system keeps track of the
last location and size a window such as Internet
Explorer or My Computer had the last time it was
displaying. This value allows the OS to restore it
SW_SHOWMINIMIZED Opens the window in its minimized state, representing
it as a button on the taskbar
SW_SHOWMAXIMIZED Opens the window in its maximized state
SW_SHOWMINNOACTIVE Opens the window but displays only its icon. It does
not make it active
SW_SHOWNA As previous
SW_SHOWNOACTIVATE Retrieves the window's previous size and location and
displays it accordingly
SW_HIDE Used to hide a window
SW_MINIMIZE shrinks the window and reduces it to a button on the
taskbar
SW_RESTORE If the window was minimized or maximized, it would
be restored to its previous location and size
To use one of these constants, pass it to the ShowWindow() method. For example, to
minimize a window that is minimizable, you would use code as follows:
ShowWindow(SW_SHOWMINIMIZED);
Remember that this method is used to either hide or to display a control by passing the
appropriate constant, SW_HIDE to hide and SW_SHOW to display it. Here is an
example that displays a control that missed the WS_VISIBLE property when it was
created:
void CSecondDlg::OnFirstControl()
{
// 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, NULL, WS_CHILD);
First->ShowWindow(SW_SHOW);
}
When the ShowWindow() method is called with the SW_SHOW value, if the control
was hidden, it would become visible; if the control was already visible, nothing would