Visual C++ and MFC Programming 2nd Edition

(Martin Jones) #1

Chapter 20: List-Based Controls Visual C++ and MFC Fundamentals



  1. Access the PreCreateWindow() event of the CMainFrame class and change it as
    follows:


BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
{
if( !CFrameWnd::PreCreateWindow(cs) )
return FALSE;
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
cs.style &= ~FWS_ADDTOTITLE;
cs.cx = 420;
cs.cy = 280;

return TRUE;
}


  1. Test the application and return to MSVC


20.3.2..Image List Creation.............................................................................


In an MFC application, an image list is based on the CImageList class. This object is
created in two main steps that do not necessarily follow each other. On one hand, you
must have the pictures that will make the list. On the other hand, you must have a
CImageList variable or pointer.

The easiest way is probaly to first create the picture. There are two kinds: masked or
nonmasked. A nonmasked image list is designed as an array of pictures where all pictures
have the same width and the same height but the pictures do not have to be square. Here
is an example:

A masked image list contains two pictures of the same with and height. Unlike the
unmasked image list, both pictures of the masked image normally represent the same
illustration. The first picture is in color and the second would be monochrome. Here is an
example:

To actually create an image list, declare a CImageList variable or pointer and call one of
its Create() methods to initialize it. It is provided in various versions as follows:

BOOL Create(int cx, int cy, UINT nFlags, int nInitial, int nGrow);
BOOL Create(UINT nBitmapID, int cx, int nGrow, COLORREF crMask );
BOOL Create(LPCTSTR lpszBitmapID, int cx, int nGrow, COLORREF crMask );
BOOL Create(CImageList& imagelist1, int nImage1,
CImageList& imagelist2, int nImage2, int dx, int dy);
BOOL Create(CImageList* pImageList);

The first version of this method allows you to describe the type of image list that will be
created. This is done by specifying the width (cx) of each picture, the height (cy) of each
picture, and a flag for the type of image list to create. The nInitial argument is the number
Free download pdf