Click here to Skip to main content
Click here to Skip to main content

A Multiline Header Control Inside a CListCtrl

By , 16 May 2000
 
  • Download source files - 18.8 Kb
  • Download demo project - 8 Kb

    Sample Image - HeaderCtrlEx.jpg

    First of all I have to mention that Alon Peleg helped me find the solution to the problem so I feel it is only fair that his name will be mentioned as an author.

    On a recent project I did I had to make the header control of a CListCtrl multiline. This small project show how to do it by subclassing the CHeaderCtrl of the CListCtrl.

    If you want to use this code just the HeaderCtrlExt.h and HeaderCtrlExt.cpp files into your source code.

    In addition on your CListView or CListCtrl derived class, add a member variable of type CHeaderCtrlEx and a member variable of type CFont.

    If you are using a CListCtrl without a view then put the following code in the end of the OnCreate handler of the CListCtrl:

    ///////////////////////SET UP THE MULTILINE HEADER CONTROL
    
    //m_NewHeaderFont is of type CFont
    m_NewHeaderFont.CreatePointFont(190,"MS Serif"); 
    
    CHeaderCtrl* pHeader = NULL;
    pHeader=GetHeaderCtrl();
    
    if(pHeader==NULL)
    	return;
    	
    VERIFY(m_HeaderCtrl.SubclassWindow(pHeader->m_hWnd));	
    
    //A BIGGER FONT MAKES THE CONTROL BIGGER
    m_HeaderCtrl.SetFont(&m_NewHeaderFont);
    
    HDITEM hdItem;
    
    hdItem.mask = HDI_FORMAT;
    
    for(i=0; i < m_HeaderCtrl.GetItemCount(); i++)
    {
    	m_HeaderCtrl.GetItem(i,&hdItem);
    
    	hdItem.fmt|= HDF_OWNERDRAW;
    		
    	m_HeaderCtrl.SetItem(i,&hdItem);
    }

    If you are using a CListView or any class derived by it then add the following code in the OnInitialUpdate override of the CListView:

    ///////////////////////SET UP THE MULTILINE HEADER CONTROL
    //m_NewHeaderFont is of type CFont
    m_NewHeaderFont.CreatePointFont(190,"MS Serif"); 
    
    CListCtrl& ListCtrl = GetListCtrl();
    
    CHeaderCtrl* pHeader = NULL;
    pHeader=ListCtrl.GetHeaderCtrl();
    
    if(pHeader==NULL)
    	return;
    	
    VERIFY(m_HeaderCtrl.SubclassWindow(pHeader->m_hWnd));	
    
    //A BIGGER FONT MAKES THE CONTROL BIGGER
    m_HeaderCtrl.SetFont(&m_NewHeaderFont);
    
    HDITEM hdItem;
    
    hdItem.mask = HDI_FORMAT;
    
    for(i=0; i < m_HeaderCtrl.GetItemCount(); i++)
    {
    	m_HeaderCtrl.GetItem(i,&hdItem);
    	hdItem.fmt|= HDF_OWNERDRAW;
    		
    	m_HeaderCtrl.SetItem(i,&hdItem);
    }
    

    The only difference between the two parts of code is way we get a pointer to the Header control.

    Thats it. Enjoy!

  • License

    This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

    A list of licenses authors might use can be found here

    About the Author

    Alberto Bar-Noy
    Team Leader www.unitronics.com
    Israel Israel
    Member
    No Biography provided

    Sign Up to vote   Poor Excellent
    Add a reason or comment to your vote: x
    Votes of 3 or less require a comment

    Comments and Discussions

     
    Hint: For improved responsiveness ensure Javascript is enabled and choose 'Normal' from the Layout dropdown and hit 'Update'.
    You must Sign In to use this message board.
    Search this forum  
        Spacing  Noise  Layout  Per page   
    Questionhow about in FormView?member田原 from Xidian3 Jul '11 - 23:34 
    GeneralI want both multiline and dynamical update on header. [modified]membernecoyam7 Jul '09 - 15:38 
    GeneralDT_VCENTER not workingmemberErakis17 Jul '08 - 4:03 
    Generalmanifest problemmembermarsiancba4 Apr '07 - 3:41 
    GeneralWindows XP themememberFarid Zidan13 Dec '06 - 14:17 
    GeneralRe: Windows XP themememberbyung chul cho12 Jun '08 - 20:32 
    Generalleft aligningmemberpedroo28 Oct '06 - 22:32 
    QuestionCode in VB.NETmemberRudis_DC25 Aug '06 - 0:41 
    AnswerRe: Code in VB.NETmemberAlberto Bar-Noy26 Aug '06 - 23:27 
    GeneralRe: Code in VB.NETmemberRudis_DC17 Oct '06 - 1:20 
    GeneralRe: Code in VB.NETmemberAlberto Bar-Noy17 Oct '06 - 1:37 
    GeneralRe: Code in VB.NETmemberRudis_DC17 Oct '06 - 1:43 
    Generalit is possible to have multiline column in row not header using win32 apimemberkcselvaraj17 Jul '06 - 4:31 
    GeneralRe: it is possible to have multiline column in row not header using win32 apimemberPurnimaKC9 Aug '06 - 20:16 
    Generalproblem with deletemembercpicass30 Sep '05 - 4:45 
    GeneralSeem does not work with SDI applicationmemberx-algo30 Apr '04 - 3:37 
    GeneralRe: Seem does not work with SDI applicationmemberstephane.boeuf8 Jul '04 - 4:55 
    GeneralRe: Seem does not work with SDI applicationmemberRod Stone25 Jan '05 - 23:57 
    GeneralThank you!memberJörgen Sigvardsson27 Feb '06 - 4:00 
    QuestionCan be done in plain C ?sussednilsom16 Feb '04 - 3:07 
    QuestionIt doesn't work in a dialog?memberwjlcqjy24 Jul '03 - 15:54 
    AnswerRe: It doesn't work in a dialog?memberJian Ruan29 Aug '03 - 15:41 
    GeneralRe: It doesn't work in a dialog?sussAnonymous15 Oct '03 - 11:32 
    GeneralRe: It doesn't work in a dialog?memberllllskywalker20 Oct '05 - 10:50 
    AnswerRe: It doesn't work in a dialog?memberllllskywalker20 Oct '05 - 13:09 

    General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

    Permalink | Advertise | Privacy | Mobile
    Web01 | 2.6.130516.1 | Last Updated 17 May 2000
    Article Copyright 2000 by Alberto Bar-Noy
    Everything else Copyright © CodeProject, 1999-2013
    Terms of Use
    Layout: fixed | fluid