Owner drawn control


Desktop-as-a-Service Designed for Any Cloud ? Nutanix Frame

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".


  • Full row select for CListCtrl

    Posted by Legacy on 08/15/2003 07:00am

    Originally posted by: Jim Revett

    To show full row selection just set the style as follows:

    Where m_ctrllcSwitchLIst is the CListCtrl variable.

    // Sets full row select
    m_ctrllcSwitchList.SetExtendedStyle(m_ctrllcSwitchList.GetExtendedStyle()| LVS_EX_FULLROWSELECT);

  • How to display a resource image that is bigger than an icon in a listview???!!!

    Posted by Legacy on 12/29/2002 08:00am

    Originally posted by: alien

    I'm realy in a big trouble here...If someone could help me i'd realy appriciate any hint, or code...

    I have a recource that is an image 75x100 pixels, and 32bit color depth!!!
    I want to display this image as an 'icon' for every element.
    I'd initialized a the imageList with the picture, with a correct image...'till now is O.K.!
    Now when i want to display the elements it doesn't apear, but when i select an item the selection is set to the coresponding size (70x100).

    I was wandering why the pciture doesn't apear?!
    The imagelist is loaded, the picture is set! Why the f... ?!
    I've no idea why?!

    Thanks for anyone for the help they can give me!!!

    With repsect Balint 'alien' Attila :)

  • How to make ActiveX control background transparent

    Posted by Legacy on 06/21/2002 07:00am

    Originally posted by: Ujjal

    Do you have a clue how to make activeX control background transparent?

  • Help Me!!!

    Posted by Legacy on 04/24/2002 07:00am

    Originally posted by: andy

    I success Transparent textbkcolor.
    lplvcd->clrTextBk = CLR_NONE;
    But there's another problem.
    If i select one row, that's textbkcolor become black.
    And i select another row, black row don't become transparent.
    Just black textbkcolor.
    How can i transparent bkcolor after lost focus?
    Help me!

    void CMyListCtrl::OnCustomDraw(NMHDR* pNMHDR, LRESULT* pResult)
    *pResult = 0;


    int nItem = static_cast( lplvcd->nmcd.dwItemSpec );
    lplvcd->clrTextBk = CLR_NONE;


  • how to change the list control header

    Posted by Legacy on 04/05/2002 08:00am

    Originally posted by: cjy

    please tell me how to add a image to list control header
    very thanks

  • List View Control

    Posted by Legacy on 12/01/2001 08:00am

    Originally posted by: Agus Budiman

    It seems that the virtual function DrawItem() is only called when the ownerdraw list view control is in REPORT view. Can anyone show me how to cause the DrawItem() to be invoked in other views (large view, small icon view, and list view)


  • Rotating painted view 90 degrees?

    Posted by Legacy on 11/26/2001 08:00am

    Originally posted by: Joachim Wickman


    Does someone have an example on how to rotate the view 90 degrees? My program that runs on a PDA have one big listview with many columns, so I always have to scroll the view. Would be better if the control could be rotated 90 degrees.

    Joachim Wickman

  • StatusbarCtrl on the top of the ListView list control !!

    Posted by Legacy on 05/25/2000 07:00am

    Originally posted by: Thanigai Murugan K.

    How do I add a StatusBarCtrl on the top of the ListView-ListCtrl?.. (Like in Visual Source Safe 6.0..

    Any Idea?...

    Thanks i advance,
    Thanigai Murugan K.

  • Where is the demo code?

    Posted by Legacy on 10/26/1999 07:00am

    Originally posted by: Jack2001

    Where is the demo code doing ownerdraw listview. For example, if I need to fill every cell on the second colume with different colors how do I do it?

  • Displaying icons in each column

    Posted by Legacy on 10/05/1999 07:00am

    Originally posted by: David Champagne

    Could you show me how to display icons in any column?

    Thanks a lot,

  • Loading, Please Wait ...

  • You must have javascript enabled in order to post comments.

Leave a Comment
  • Your email address will not be published. All fields are required.

Most Popular Programming Stories

More for Developers

RSS Feeds

Thanks for your registration, follow us on our social networks to keep up-to-date