Download Special Edition Using Visual C++ 6
Transcript
Special Edition Using Visual C++ 6 -- Ch 10 -- Common Controls The List View Control A list view control simplifies the job of building an application that works with lists of objects and organizes those objects in such a way that the program's user can easily determine each object's attributes. For example, consider a group of files on a disk. Each file is a separate object associated with a number of attributes, including the file's name, size, and the most recent modification date. When you explore a folder, you see files either as icons in a window or as a table of entries, each entry showing the attributes associated with the files. You have full control over the way that the file objects are displayed, including which attributes are shown and which are unlisted. The common controls include something called a list view control, so you can organize lists in exactly the same way. If you'd like to see an example of a full-fledged list view control, open the Windows Explorer (see Figure 10.3). The right side of the window shows how the list view control can organize objects in a window. (The left side of the window contains a tree view control, which you will learn about later in this chapter in the section titled "The Tree View Control.") In the figure, the list view is currently set to the report view, in which each object in the list receives its own line, showing not only the object's name but also the attributes associated with that object. FIG. 10.3 Windows Explorer uses a list view control to organize file information. The user can change the way objects are organized in a list view control. Figure 10.4, for example, shows the list view portion of the Explorer set to the large-icon setting, and Figure 10.5 shows the small-icon setting, which enables the user to see more objects (in this case, files) in the window. With a list view control, the user can edit the names of objects in the list and in the report view can sort objects, based on data displayed in a particular column. FIG. 10.4 Here's Explorer's list view control set to large icons. FIG. 10.5 Here's Explorer's list view control set to small icons. Common will also sport a list view control, although not as fancy as Explorer's. You will add a list view and some buttons to switch between the small-icon, large-icon, list, and report views. Creating the List View How does all this happen? Well, it does require more work than the progress bar, trackbar, or up-down controls (it could hardly take less). You will write the rest of CreateListView(), which performs the following tasks: 1. Creates and fills the image list controls 2. Creates the list view control itself 3. Associates the image lists with the list view 4. Creates the columns 5. Sets up the columns 6. Creates the items 7. Sets up the items 8. Creates the buttons After creating the image lists, CreateListView() goes on to create the list view control by calling the class's Create() member function, as usual. Add these lines to CreateListView(): // Create the List View control. m_listView.Create(WS_VISIBLE | WS_CHILD | WS_BORDER | LVS_REPORT | LVS_NOSORTHEADER | LVS_EDITLABELS, CRect(160, 120, 394, 220), this, IDC_LISTVIEW); The CListCtrl class, of which m_listView is an object, defines special styles to be used with list view controls. Table 10.3 lists these special styles and their descriptions. http://www.pbs.mcp.com/ebooks/0789715392/ch10/ch10.htm (11 of 26) [7/29/1999 3:47:58 PM]