Visual C++ and MFC Programming 2nd Edition

(Martin Jones) #1

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


10.1.5..Frame Display Options.......................................................................


The nCmdShow argument of the WinMain() function specifies whether and how you
want to display the window when the user attempts to open it. This is a constant value
that is actually passed to a function that is in charge of displaying the window.

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_MAXIMIZE Maximizes the window to occupy the whole screen
area
SW_RESTORE If the window was minimized or maximized, it would
be restored to its previous location and size

One of the ways you can use this value is to pass it to the WinExec() Win32 function
which can be used to open an application. The syntax of this function is:

UINT WinExec(LPCSTR lpCmdLine, UINT nCmdShow);

The lpCmdLine argument is a null-terminated string that specifies either the name of the
application or its complete path.

In the following example, the SW_MAXIMIZE nCmdShow value is passed to the
WinExec() function to open Solitaire maximized:

void CWindowDlg::OnOpenSolitaire()
{
WinExec("SOL.EXE", SW_MAXIMIZE);
}

10.1.6..Window Class Initialization..............................................................


A win32 application is built using either the WNDCLASS or the WNDCLASSEX
classes.

The WNDCLASS class is defined as follows:

typedef struct _WNDCLASS {
UINT style;
Free download pdf