Visual C++ and MFC Programming 2nd Edition

(Martin Jones) #1

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


?? The CButton class is based on CWnd. Therefore, CWnd is the parent class of
CButton
?? When a button is placed on a form, the form, which is based on CView
(indirectly) is the window parent of the button and not its class parent

If you are creating an independent window, as we have done with the frames so far, you
can simply call its Create() method and define its characteristics. Such a class or window
is a prime candidate for parenthood.

11.2 Parent Controls.............................................................................................


11.2.1..Definition..............................................................................................


An object is referred to as a parent or container when its main job is to host other
controls. This is done by adding controls to it. Besides all of the characteristics of
WNDCLASS, the WNDCLASSEX structure requires that you specify the size of the
structure and it allows you to set a small icon for your application.

Besides the CreateWindow() function, the Win32 library provides the
CreateWindowEx() function you can use to create a window. Once again, the
CreateWindowEx() function has the followsing syntax:

HWND CreateWindowEx(
DWORD dwExStyle,
LPCTSTR lpClassName,
LPCTSTR lpWindowName,
DWORD dwStyle,
int x,
int y,
int nWidth,
int nHeight,
HWND hWndParent,
HMENU hMenu,
HINSTANCE hInstance,
LPVOID lpParam
);

11.2.2..Parent Windows Styles.......................................................................


The role of a parent object is very important to the other controls it is hosting. Based on
this, the parent window must possess some valuable characteristics. For example, you
must provide a way to close the parent window. If necessary, you can also allow moving
the parent. This is usually done by the user dragging the title bar of a frame or a dialog
box. If the parent is a toolbar, you can make it dockable, in which case it can be moved
and positioned to various parts of the frame window. You can also allow the user to move
a parent such as a dialog box by dragging its body. We will review the characteristics of
parent window when studying dialog boxes

11.3 Windows Controls.......................................................................................

Free download pdf