Chapter 12: Dialog-Based Windows Visual C++ and MFC Fundamentals
Win32 application. If you are creating the main window of your application, it does not
have a parent. In this case, pass the hWndParent as NULL.
If you are creating an MFC application, pass the handle of the parent as the pParentWnd
argument of the Create() method. For a main frame, the kind we have created so far,
specify this argument as NULL:
CMainFrame::CMainFrame()
{
// Declare a window class variable
WNDCLASS WndCls;
const char *StrWndName = "Windows Fundamentals";
Create(StrClass, StrWndName, WS_OVERLAPPEDWINDOW, rectDefault, NULL);
}
Practical Learning: Parenting the Application
- Since the current window does not have a parent or owner, pass the NULL constant
as the parent:
//---------------------------------------------------------------------------
INT WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPSTR lpCmdLine, int nCmdShow )
{
hWnd = CreateWindowEx(0,
StrClassName,
StrWndName,
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
NULL, );
return 0;
}
//---------------------------------------------------------------------------
- Save All
10.2.7..The Window's Menu...........................................................................
If you want the window to display a menu, first create or design the resource menu.
Visual C++ provides a convenient way to design a basic menu. To do this, display the
Add Resource dialog box and select Menu. Then add the desired items.
After creating the menu, assign its name to the lpszMenuName name to your
WNDCLASS variable for a Win32 variable. If you had created the menu and gave it an
identifier, use the MAKEINTRRESOURCE macro to convert it. If the window you are
creating is a child window that will need to display its particular menu when that child
window is displaying, create its menu and pass its handle as the hMenu argument of the