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



Comments

  • Full row select for CListCtrl

    Posted by Legacy on 08/15/2003 12: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);

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

    Posted by Legacy on 12/29/2002 12: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 :)

    Reply
  • How to make ActiveX control background transparent

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

    Originally posted by: Ujjal

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

    Reply
  • Help Me!!!

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

    Originally posted by: andy

    Hi,
    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;

    LPNMLVCUSTOMDRAW lplvcd = (LPNMLVCUSTOMDRAW)pNMHDR;

    switch(lplvcd->nmcd.dwDrawStage)
    {
    case CDDS_PREPAINT:
    {
    *pResult = CDRF_NOTIFYITEMDRAW;
    return;
    }
    case CDDS_ITEMPREPAINT:
    {
    int nItem = static_cast( lplvcd->nmcd.dwItemSpec );
    lplvcd->clrTextBk = CLR_NONE;

    *pResult = CDRF_NOTIFYPOSTPAINT;
    return;
    }
    }
    }

    Reply
  • how to change the list control header

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

    Originally posted by: cjy

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

    Reply
  • List View Control

    Posted by Legacy on 12/01/2001 12: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)

    Thanks

    Reply
  • Rotating painted view 90 degrees?

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

    Originally posted by: Joachim Wickman

    Hi
    
    

    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.

    Friendly,
    Joachim Wickman

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

    Posted by Legacy on 05/25/2000 12: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.

    Reply
  • Where is the demo code?

    Posted by Legacy on 10/26/1999 12: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?

    Reply
  • Displaying icons in each column

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

    Originally posted by: David Champagne

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

    Thanks a lot,
    David

    Reply
  • Loading, Please Wait ...

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

Top White Papers and Webcasts

  • Live Event Date: April 22, 2014 @ 1:00 p.m. ET / 10:00 a.m. PT Database professionals — whether developers or DBAs — can often save valuable time by learning to get the most from their new or existing productivity tools. Whether you're responsible for managing database projects, performing database health checks and reporting, analyzing code, or measuring software engineering metrics, it's likely you're not taking advantage of some of the lesser-known features of Toad from Dell. Attend this live …

  • When it comes to desktops – physical or virtual – it's all about the applications. Cloud-hosted virtual desktops are growing fast because you get local data center-class security and 24x7 access with the complete personalization and flexibility of your own desktop. Organizations make five common mistakes when it comes to planning and implementing their application management strategy. This eBook tells you what they are and how to avoid them, and offers real-life case studies on customers who didn't …

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds