Visual C++ and MFC Programming 2nd Edition

(Martin Jones) #1

Visual C++ and MFC Fundamentals Chapter 2: Introduction to MFC


CRect();
CRect(int l, int t, int r, int b);
CRect(const RECT& srcRect);
CRect(LPCRECT lpSrcRect);
CRect(POINT point, SIZE size);
CRect(POINT topLeft, POINT bottomRight);

The default constructor is used to declare a CRect variable whose dimensions are not
known. On the other hand, if you know the left, the top, the right, and the bottom
measures of the rectangle, as seen on the RECT structure, you can use them to declare
and initialize a rectangle. In the same way, you can assign a CRect, a RECT, a pointer to
CRect, or a pointer to a RECT variable to create or initialize a CRect instance.

If you do not know or would not specify the location and dimension of a window, you
can specify the value of the rect argument as rectDefault. In this case, the compiler would
use its own internal value for this argument.

Practical Learning: Controlling a Window's Size



  1. To specify the location and the size of the window, change the MainFrm.cpp file as
    follows:


CSimpleFrame::CSimpleFrame()
{
// Create the window's frame
Create(NULL, "Windows Application", WS_OVERLAPPEDWINDOW,
CRect(120, 100, 700, 480));
}


  1. Test the application. After viewing the window, close it and return to your
    programming environment.


2.2.8 Windows Parents....................................................................................


Many applications are made of different windows, as we will learn eventually. When an
application uses various windows, most of these objects depend on a particular one. It
could be the first window that was created or another window that you designated. Such a
window is referred to as the parent window. All the other windows depend on it directly
or indirectly.

If the window you are creating is dependent of another, you can specify that it has a
parent. This is done with the pParentWnd argument of the CFrameWnd::Create()
method. If the window does not have a parent, pass the argument with a NULL value.

Practical Learning: Specifying a Window's Parent



  1. To specify that the current window does not have a parent, change the Create()
    method as follows:


CSimpleFrame::CSimpleFrame()
{
// Create the window's frame
Free download pdf