In the previous example, we used only the ListView, a detailed view. This article we have used in the previous article to expand the example, the example source can be downloaded to my resource area.
We add an icon to the data displayed in the ListView and allow the user to choose which view to display, such as large icons, small icons, details, and so on.
Because the code is still relatively long, I do not want to put all the code out, after writing this article, I will upload the source to the resources. Of course, I can not say that every line of code is explained again, that is not realistic, and, this is not good, I can not subjectively doubt the reader's ability to comprehend.
First, prepare the icon
Now that you want to use the icon, in order to be simple and convenient, using the VS Resource Editor casually draw a few of the icon, we have to prepare two icons, why? The first icon is for the EXE file, and the second icon is used in ListView. Because the icon in the generated. exe file is the icon that we first added to the resource, the icon for the. exe file is not the same as the one we used in the ListView (this is not easy to see), so we still have two icons to be better.
There are two dimensions in the icon is enough--16*16 and 32*32, if possible with 24-bit image, so you can use more colors.
Second, how to switch views
Change the view of ListView, you can use Listview_setview macros, send lvm_setview messages, but it is more convenient to use macros. Its first parameter specifies the handle to the LV control, and the second argument is which view is set.
lv_view_details--Detailed View.
lv_view_icon--Large Icon list.
lv_view_list--List view.
lv_view_smallicon--small icon.
lv_view_tile--Tile, if I remember correctly, this view was introduced in XP.
Three, ComboBox control use
To allow the user to select a view, nature to provide the corresponding operating interface, which is a more selective way, with radio buttons and the Drop-down table box can be, however, the radio button to occupy more places and processing more information, relatively troublesome, so, or ComboBox better.
You can add items to the ComboBox using the Combobox_addstring macro, such as this example.
Initializes the ComboBox to select the
view
HCBB = GetDlgItem (hdlg, idc_cbview);
Combobox_addstring (HCBB, L "large Icon");
Combobox_addstring (HCBB, L "small Icon");
Combobox_addstring (HCBB, L "list");
Combobox_addstring (HCBB, L "detailed");