Click here to Skip to main content
Licence 
First Posted 7 May 2000
Views 243,486
Bookmarked 59 times

A Multiline Header Control Inside a CListCtrl

By | 16 May 2000 | Article
How to make the CListCtrl's header Multiline
  • 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



    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

     
    You must Sign In to use this message board. (secure sign-in)
     
    Search this forum  
     FAQ
        Noise  Layout  Per page   
      Refresh
    Questionhow about in FormView? Pinmember田原 from Xidian23:34 3 Jul '11  
    GeneralI want both multiline and dynamical update on header. [modified] Pinmembernecoyam15:38 7 Jul '09  
    GeneralDT_VCENTER not working PinmemberErakis4:03 17 Jul '08  
    Generalmanifest problem Pinmembermarsiancba3:41 4 Apr '07  
    GeneralWindows XP theme PinmemberFarid Zidan14:17 13 Dec '06  
    GeneralRe: Windows XP theme Pinmemberbyung chul cho20:32 12 Jun '08  
    Generalleft aligning Pinmemberpedroo22:32 28 Oct '06  
    QuestionCode in VB.NET PinmemberRudis_DC0:41 25 Aug '06  
    AnswerRe: Code in VB.NET PinmemberAlberto Bar-Noy23:27 26 Aug '06  
    GeneralRe: Code in VB.NET PinmemberRudis_DC1:20 17 Oct '06  
    GeneralRe: Code in VB.NET PinmemberAlberto Bar-Noy1:37 17 Oct '06  
    GeneralRe: Code in VB.NET PinmemberRudis_DC1:43 17 Oct '06  
    Generalit is possible to have multiline column in row not header using win32 api Pinmemberkcselvaraj4:31 17 Jul '06  
    GeneralRe: it is possible to have multiline column in row not header using win32 api PinmemberPurnimaKC20:16 9 Aug '06  
    Generalproblem with delete Pinmembercpicass4:45 30 Sep '05  
    GeneralSeem does not work with SDI application Pinmemberx-algo3:37 30 Apr '04  
    GeneralRe: Seem does not work with SDI application Pinmemberstephane.boeuf4:55 8 Jul '04  
    GeneralRe: Seem does not work with SDI application PinmemberRod Stone23:57 25 Jan '05  
    GeneralThank you! PinmemberJörgen Sigvardsson4:00 27 Feb '06  
    QuestionCan be done in plain C ? Pinsussednilsom3:07 16 Feb '04  
    QuestionIt doesn't work in a dialog? Pinmemberwjlcqjy15:54 24 Jul '03  
    AnswerRe: It doesn't work in a dialog? PinmemberJian Ruan15:41 29 Aug '03  
    GeneralRe: It doesn't work in a dialog? PinsussAnonymous11:32 15 Oct '03  
    GeneralRe: It doesn't work in a dialog? Pinmemberllllskywalker10:50 20 Oct '05  
    AnswerRe: It doesn't work in a dialog? Pinmemberllllskywalker13:09 20 Oct '05  

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

    Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

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