Owner drawn control | CodeGuru

Owner drawn control

One of the styles that the listview control can have is the LVS_OWNERDRAWFIXED style. The implication of this style is that the responsibility of drawing the content of the control is on the application. That is, you have to write all the code for drawing and displaying text in the control. Another aspect of the […]

Written By
CodeGuru Staff
CodeGuru Staff
Aug 6, 1998
2 minute read
CodeGuru content and product recommendations are editorially independent. We may make money when you click on links to our partners. Learn More


One of the styles that the listview control can have is the LVS_OWNERDRAWFIXED style. The implication of this style is that the responsibility of drawing the content of the control is on the application. That is, you have to write all the code for drawing and displaying text in the control. Another aspect of the LVS_OWNERDRAWFIXED style is that all the rows should have the same height. The height of a row is set when the parent window responds to the WM_MEASUREITEM message when the control is created. If this height is not satisfactory, you can change it by using the technique discussed in the topic


Changing row height in owner drawn control

.

The virtual function DrawItem() is called for each row that needs to be painted. This function is responsible for drawing the entire row including the state image, the item image, the item label and the sub-labels. The default implementation of this function simply asserts. This means that there is not short cut for implementing this function. Besides drawing the images and the texts, you also have to set the hightlight color if the row is selected and the focus rectangle if the row has focus. All this makes the implementation of the DrawItem() function somewhat tedious but allows a great deal of customization.

Here are few things we can do with an owner drawn list view control. We can implement full row selection where the full row is highlighted rather than just the first column of the row. We can use different background colors and text colors for different rows, columns and even different cells. We can also display icons in any column. The owner drawn control can also be used to show a background image.

For code to implement owner drawn CListCtrl see the topic “Selection highlighting of entire row“.

CodeGuru Logo

CodeGuru covers topics related to Microsoft-related software development, mobile development, database management, and web application programming. In addition to tutorials and how-tos that teach programmers how to code in Microsoft-related languages and frameworks like C# and .Net, we also publish articles on software development tools, the latest in developer news, and advice for project managers. Cloud services such as Microsoft Azure and database options including SQL Server and MSSQL are also frequently covered.

Property of TechnologyAdvice. © 2026 TechnologyAdvice. All Rights Reserved

Advertiser Disclosure: Some of the products that appear on this site are from companies from which TechnologyAdvice receives compensation. This compensation may impact how and where products appear on this site including, for example, the order in which they appear. TechnologyAdvice does not include all companies or all types of products available in the marketplace.