Home Index  | Back

New Page 1
Lesson 1 -Building Your First Windows Application

1.1 : Creating a Windows Application

1.2 : Creating a Dialog-Based Application

1.3 : Creating DLLs, Console Applications, and More

1.4 : Changing Your AppWizard Decisions
 1.5 : Understanding AppWizard’s Code
 1.6 : Understanding a MDI Application
 1.7 : Understanding the Components of a Dialog-Based Application

Lesson 2 - Dialogs and Controls

2.1 : Understanding Dialog Boxes

2.2 : Creating a Dialog Box Resource

 2.3 : Writing a Dialog Box Class
 2.4 : Using the Dialog Box Class
Lesson 3 - Messages and Commands

3.1 : Understanding Message Routing

3.2 : Understanding Message Loops

 3.3 : Reading Message Maps
 3.4 : Learning How ClassWizard Helps You Catch Messages
 3.5 : Recognizing Messages
 3.6 : Understanding Commands
 3.7 : Understanding Command Updates
 3.8 : Learning How ClassWizard Helps You Catch Commands and Command Updates

Lesson 4 - Documents and Views

4.1 : Understanding the Document Class

4.2 : Understanding the View Class

4.3 : Creating the Rectangles Application

 4.4 : Other View Classes

4.5 : Document Templates, Views, and Frame Windows

Lesson 5 - Drawing on the Screen

5.1 :Understanding Device Contexts

 5.2 : Introducing the Paint1 Application
 5.3 : Building the Paint1 Application
 5.4 : Scrolling Windows
 5.5 : Building the Scroll Application
Lesson 6 - Building a Complete Application: ShowString

6.1 : Building an Application That Displays a String

 6.2 : Building the ShowString Menus
 6.3 : Building the ShowString Dialog Boxes
 6.4 : Making the Menu Work
 6.5 : Making the Dialog Box Work
 6.6 : Adding Appearance Options to the Options Dialog Box
Lesson 7 -  Status Bars and Toolbars

7.1 : Working with Toolbars

 7.2 : Working with Status Bars
Lesson 8 - Common Controls

8.1 : The Progress Bar Control

 8.2 : The Up-Down Control
 8.3 : The Image List Control
 8.4 : The List View Control
 8.5 : The Tree View Control
 8.6 : The Rich Edit Control
 8.7 : The Date Picker Control
 8.8 : Month Calendar Control
 8.9 : Scrolling the View
Lesson 9 - Property Pages and Sheets

9.1 : Introducing Property Sheets

 9.2 : Creating the Property Sheet Demo Application
 9.3 : Running the Property Sheet Demo Application
Lesson 10 - ActiveX Concepts

10.1 : The Purpose of ActiveX

10.2 : Object Linking

10.3 : Object Embedding

 10.4 : Containers and Servers
 10.5 : Toward a More Intuitive User Interface
 10.6 : The Component Object Model  

10.7 : Automation

 10.8 : ActiveX Controls

Lesson 11 -  Building an ActiveX Control

11.1 : Creating a Rolling-Die Control

11.2 : Displaying the Current Value

11.3 : Reacting to a Mouse Click and Rolling the Die 

 11.4 : Creating a Better User Interface
 11.5 : Generating Property Sheets
Lesson 12 - Database Access

12.1 : Understanding Database Concepts

12.2 : Creating an ODBC Database Program

 12.3 : Choosing Between ODBC and DAO
 12.4 : OLE DB

Lesson -8:Common Controls

8.3- The Image List Control

Often you need to use images that are related in some way. For example, your application might have a toolbar with many command buttons, each of which uses a bitmap for its icon. In a case like this, it would be great to have some sort of program object that could not only hold the bitmaps but also organize them so that they can be accessed easily. That’s exactly what an image list control does for you—it stores a list of related images. You can use the images any way that you see fit in your program. Several common controls rely on image lists. These controls include the following:

· List view controls

· Tree view controls

· Property pages

· Toolbars

You will undoubtedly come up with many other uses for image lists. You might, for example, have an animation sequence that you’d like to display in a window. An image list is the perfect storage place for the frames that make up an animation, because you can easily access any frame just by using an index.

If the word index makes you think of arrays, you’re beginning to understand how an image list stores images. An image list is very similar to an array that holds pictures rather than integers or floating-point numbers. Just as with an array, you initialize each "element" of an image list and thereafter can access any part of the "array" by using an index.

You won’t, however, see an image list control in your running application in the same way that you can see a status bar or a progress bar control. This is because (again, similar to an array) an image list is only a storage structure for pictures. You can display the images stored in an image list, but you can’t display the image list itself. Figure 8.2 shows how an image list is organized.

FIG. 10.2 An image list is much like an array of pictures.

8.3.1 Creating the Image List

In the Common Controls App application, image lists are used with the list view and tree view controls, so the image lists for the controls are created in the CreateListView() and CreateTreeView() local member functions and are called from CCommonView::OnCreate(). Just as with the other controls, add calls to these functions to OnCreate() and then add the functions to the class. You will see the full code for those functions shortly, but because they are long, this section presents the parts that are relevant to the image list.

A list view uses two image lists: one for small images and the other for large ones. The member variables for these lists have already been added to the class, so start coding CreateListView() with a call to each list’s Create() member function, like this:

m_smallImageList.Create(16, 16, FALSE, 1, 0);

m_largeImageList.Create(32, 32, FALSE, 1, 0);

The Create() function’s five arguments are

· The width of the pictures in the control

· The height of the pictures

· A Boolean value indicating whether the images contain a mask

· The number of images initially in the list

· The number of images by which the list can dynamically grow

This last value is 0 to indicate that the list isn’t allowed to grow during runtime. The Create() function is overloaded in the CImageList class so that you can create image lists in various ways.

8.3.2 Initializing the Image List

After you create an image list, you will want to add images to it. After all, an empty image list isn’t of much use. The easiest way to add the images is to include the images as part of your application’s resource file and load them from there. Add these four lines to CreateListView() to fill each list with images:

HICON hIcon = ::LoadIcon (AfxGetResourceHandle(),

MAKEINTRESOURCE(IDI_ICON1));

m_smallImageList.Add(hIcon);

hIcon = ::LoadIcon (AfxGetResourceHandle(),

MAKEINTRESOURCE(IDI_ICON2));

m_largeImageList.Add(hIcon);

Here the program first gets a handle to the icon. Then it adds the icon to the image list by calling the image list’s Add() member function. (In this case, the list includes only one icon. In other applications, you might have a list of large icons for folders, text files, and so on, as well as another list of small icons for the same purposes.) To create the first icon, choose Insert, Resource and double-click Icon. Then edit the new blank icon in the Resource Editor. (It will automatically be called IDI_ICON1.) Click the New Device Image toolbar button next to the drop-down box that says Standard (32*32) and choose Small (16*16) on the dialog that appears; click OK. You can spend a long time making a beautiful icon or just quickly fill in the whole grid with black and then put a white circle on it with the Ellipse tool. Add another icon, IDI_ICON2, and leave it as 32*32. Draw a similar symbol on this icon.

You can use many member functions to manipulate an object of the CImageList class, adjusting colors, removing images, and much more. 

You can write the first few lines of CreateTreeView() now. It uses one image list that starts with three images. Here’s the code to add:

m_treeImageList.Create(13, 13, FALSE, 3, 0);

HICON hIcon = ::LoadIcon(AfxGetResourceHandle(),

MAKEINTRESOURCE(IDI_ICON3));

m_treeImageList.Add(hIcon);

hIcon = ::LoadIcon(AfxGetResourceHandle(),

MAKEINTRESOURCE(IDI_ICON4));

m_treeImageList.Add(hIcon);

hIcon = ::LoadIcon(AfxGetResourceHandle(),

MAKEINTRESOURCE(IDI_ICON5));

m_treeImageList.Add(hIcon);

Create IDI_ICON3, IDI_ICON4, and IDI_ICON5 the same way you did the first two icons. All three are 32*32. Draw circles as before. If you leave the background the same murky green you started with, rather than fill it with black, the circles will appear on a transparent background—a nice effect.

 

Next>>
 
© Dewsoft Overseas