none
Change the color of Header in listview in mfc RRS feed

  • Question

  • Hi

    How to change the color of header in listview using vc++ dialog based mfc application?

    please do reply with some lines of sample codes

    Wednesday, March 9, 2011 9:27 AM

Answers

  • 1. Create class inherited from CHeaderCtrl.

    2. Add NM_CUSTOMDRAW handler to it.

    3. Then something like this:

    CMyHeaderCtrl m_MyHeaderCtrl;
    ...
    m_MyHeaderCtrl.SubclassWindow(m_MyListView.GetHeaderCtrl() -> m_hWnd) 

     


    Nikita Leontiev
    Thursday, March 10, 2011 4:32 PM
  •  

    Hi prashanth_a_s,

     

    I don't have Visual Studio 2003 on my machine, but I think the way to add a subclass CHeaderCtrl is the same as to add it in Visual Studio 2008.

     

    1. Click View->Class View, and right click your project->Add->Class.
    1. Select Visual C++->MFC->MFC Class, click Add.
    1. Type your class name, select CHeaderCtrl in Base class, click Finish

    To use this handler in your code, you can new a your class which is based CHeaderCtrl, then use its point.

     

    I hope my suggestions can help you to solve this problem.

     

    Best regards,

    Jesse


    Jesse Jiang [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Friday, March 18, 2011 8:15 AM
    Moderator

All replies

  • You need to subclass listview header control and handle NM_CUSTOMDRAW message. Then draw header in the colors you want.

    The Three Steps to Implementing Custom Draw


    Nikita Leontiev
    Wednesday, March 9, 2011 9:57 AM
  • Hi

    Thank you for the reply, by adding NM_CUSTOMDRAW to the list-view is not affecting, it remains as before. I want to only change the header back color of the list-view.

    Thursday, March 10, 2011 6:43 AM
  • Subclass listview header and add NM_CUSTOMDRAW handler to it.
    Nikita Leontiev
    Thursday, March 10, 2011 8:41 AM
  • I follwed the same steps by adding a NM_CUSTOMDRAW to the list-view but when i keep a break point inside that it is not triggering.
    Thursday, March 10, 2011 4:16 PM
  • 1. Create class inherited from CHeaderCtrl.

    2. Add NM_CUSTOMDRAW handler to it.

    3. Then something like this:

    CMyHeaderCtrl m_MyHeaderCtrl;
    ...
    m_MyHeaderCtrl.SubclassWindow(m_MyListView.GetHeaderCtrl() -> m_hWnd) 

     


    Nikita Leontiev
    Thursday, March 10, 2011 4:32 PM
  • Hi

    Thank you very much for the reply, I am using visual studio 2003 as IDE. i don't know how to create a subclass CHeaderCtrl and how to add handler to it, can i get some more detail so that i can understand.

    Friday, March 11, 2011 6:32 AM
  •  

    Hi prashanth_a_s,

     

    I don't have Visual Studio 2003 on my machine, but I think the way to add a subclass CHeaderCtrl is the same as to add it in Visual Studio 2008.

     

    1. Click View->Class View, and right click your project->Add->Class.
    1. Select Visual C++->MFC->MFC Class, click Add.
    1. Type your class name, select CHeaderCtrl in Base class, click Finish

    To use this handler in your code, you can new a your class which is based CHeaderCtrl, then use its point.

     

    I hope my suggestions can help you to solve this problem.

     

    Best regards,

    Jesse


    Jesse Jiang [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Friday, March 18, 2011 8:15 AM
    Moderator