Owner
Overview :
The program should now be modified further so that the list control tasks are specified by exact code . This allows the programmer to decide exactly what the list control may see. (The list control is owner drawn).
Advantages of this are that more than one image may be displayed, tick boxes may be used and the focus may be spread along the full width of the row.
As this is reasonably complicated this task is split into three sections. (1) Displaying the image and names, (2) Highlighting the selected item and (3) Shortening the string length.
Task 1 :
The image and names should be displayed within the owner drawn list control. The diagram below shows that in this example no item is highlighted and the first column has been shortened and the string has been cut off. These problems are corrected in tasks 2 and 3.
Instructions 1 :
- Add the LVS_OWNERDRAWFIXED style to the ListCtrl.
- Add the virtual function DrawItem() to the ListCtrl.
- Edit the code to allow the images and names to be displayed.
Task 2 :
Task two is to add the highlighting feature.
Instructions 2 :
- A section of code which should be added to the DrawItem() function. The majority of this can be found in the the help below.
Task 3 :
Task three is to trim the strings which can't fit into the column spacing.
Instructions 3 :
- A new function should be written which takes the column width, the string and the offset and then trims the string accordingly.
Help :
"Essential Visual C++ 4" - Mickey Williams - pp 441-452.
Click here for a worked example
Click here for the source code
Click here to return to menu