Click here to Skip to main content
12,501,486 members (60,165 online)
Click here to Skip to main content
Add your own
alternative version

Stats

290.8K views
5.1K downloads
73 bookmarked
Posted

A Multiline Header Control Inside a CListCtrl

, 16 May 2000
Rate this:
Please Sign up or sign in to vote.
How to make the CListCtrl's header Multiline
<!-- Link to source file download -->
  • Download source files - 18.8 Kb <!-- Link to demo file download -->
  • Download demo project - 8 Kb <!-- Article image -->

    Sample Image - HeaderCtrlEx.jpg

    <!-- Add the rest of your HTML here -->

    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

    Share

    About the Author

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

    You may also be interested in...

    Pro
    Pro

    Comments and Discussions

     
    Questionhow about in FormView? Pin
    田原 from Xidian3-Jul-11 23:34
    member田原 from Xidian3-Jul-11 23:34 
    GeneralI want both multiline and dynamical update on header. [modified] Pin
    necoyam7-Jul-09 15:38
    membernecoyam7-Jul-09 15:38 
    GeneralDT_VCENTER not working Pin
    Erakis17-Jul-08 4:03
    memberErakis17-Jul-08 4:03 
    Generalmanifest problem Pin
    marsiancba4-Apr-07 3:41
    membermarsiancba4-Apr-07 3:41 
    GeneralWindows XP theme Pin
    Farid Zidan13-Dec-06 14:17
    memberFarid Zidan13-Dec-06 14:17 
    GeneralRe: Windows XP theme Pin
    byung chul cho12-Jun-08 20:32
    memberbyung chul cho12-Jun-08 20:32 
    Generalleft aligning Pin
    pedroo28-Oct-06 22:32
    memberpedroo28-Oct-06 22:32 
    QuestionCode in VB.NET Pin
    Rudis_DC25-Aug-06 0:41
    memberRudis_DC25-Aug-06 0:41 
    AnswerRe: Code in VB.NET Pin
    Alberto Bar-Noy26-Aug-06 23:27
    memberAlberto Bar-Noy26-Aug-06 23:27 
    GeneralRe: Code in VB.NET Pin
    Rudis_DC17-Oct-06 1:20
    memberRudis_DC17-Oct-06 1:20 
    GeneralRe: Code in VB.NET Pin
    Alberto Bar-Noy17-Oct-06 1:37
    memberAlberto Bar-Noy17-Oct-06 1:37 
    GeneralRe: Code in VB.NET Pin
    Rudis_DC17-Oct-06 1:43
    memberRudis_DC17-Oct-06 1:43 
    Generalit is possible to have multiline column in row not header using win32 api Pin
    kcselvaraj17-Jul-06 4:31
    memberkcselvaraj17-Jul-06 4:31 
    GeneralRe: it is possible to have multiline column in row not header using win32 api Pin
    PurnimaKC9-Aug-06 20:16
    memberPurnimaKC9-Aug-06 20:16 
    Generalproblem with delete Pin
    cpicass30-Sep-05 4:45
    membercpicass30-Sep-05 4:45 
    GeneralSeem does not work with SDI application Pin
    x-algo30-Apr-04 3:37
    memberx-algo30-Apr-04 3:37 
    GeneralRe: Seem does not work with SDI application Pin
    stephane.boeuf8-Jul-04 4:55
    memberstephane.boeuf8-Jul-04 4:55 
    GeneralRe: Seem does not work with SDI application Pin
    Rod Stone25-Jan-05 23:57
    memberRod Stone25-Jan-05 23:57 
    GeneralThank you! Pin
    Jörgen Sigvardsson27-Feb-06 4:00
    memberJörgen Sigvardsson27-Feb-06 4:00 
    QuestionCan be done in plain C ? Pin
    ednilsom16-Feb-04 3:07
    sussednilsom16-Feb-04 3:07 
    QuestionIt doesn't work in a dialog? Pin
    wjlcqjy24-Jul-03 15:54
    memberwjlcqjy24-Jul-03 15:54 
    AnswerRe: It doesn't work in a dialog? Pin
    Jian Ruan29-Aug-03 15:41
    memberJian Ruan29-Aug-03 15:41 
    GeneralRe: It doesn't work in a dialog? Pin
    Anonymous15-Oct-03 11:32
    sussAnonymous15-Oct-03 11:32 
    GeneralRe: It doesn't work in a dialog? Pin
    llllskywalker20-Oct-05 10:50
    memberllllskywalker20-Oct-05 10:50 
    AnswerRe: It doesn't work in a dialog? Pin
    llllskywalker20-Oct-05 13:09
    memberllllskywalker20-Oct-05 13:09 
    GeneralRe: It doesn't work in a dialog? Pin
    llllskywalker7-Mar-11 6:20
    memberllllskywalker7-Mar-11 6:20 
    GeneralGetting Assertion when used in my Framework Pin
    S Ganapathi Raman4-Jul-03 22:59
    memberS Ganapathi Raman4-Jul-03 22:59 
    GeneralRe: Getting Assertion when used in my Framework Pin
    Alberto Gattegno6-Jul-03 1:41
    memberAlberto Gattegno6-Jul-03 1:41 
    Question:) That's really a good idea,but could u draw the two line text with two different fonts? Pin
    skygg3-Jun-03 16:16
    memberskygg3-Jun-03 16:16 
    AnswerRe: :) That's really a good idea,but could u draw the two line text with two different fonts? Pin
    Alberto Gattegno4-Jun-03 1:23
    memberAlberto Gattegno4-Jun-03 1:23 
    Questionhi,i just can not understand how can this piece of code make the Header Control Multiline? Pin
    skygg2-Jun-03 20:15
    memberskygg2-Jun-03 20:15 
    AnswerRe: hi,i just can not understand how can this piece of code make the Header Control Multiline? Pin
    Alberto Gattegno2-Jun-03 21:27
    memberAlberto Gattegno2-Jun-03 21:27 
    Questioncan u make it looks like msn friend lists? Pin
    skygg19-May-03 23:23
    memberskygg19-May-03 23:23 
    AnswerRe: can u make it looks like msn friend lists? Pin
    Alberto Gattegno19-May-03 23:36
    memberAlberto Gattegno19-May-03 23:36 
    GeneralRe: can u make it looks like msn friend lists? Pin
    skygg1-Jun-03 23:38
    memberskygg1-Jun-03 23:38 
    GeneralRe: can u make it looks like msn friend lists? Pin
    AntonDel12-Aug-03 9:45
    memberAntonDel12-Aug-03 9:45 
    QuestionHelp:How to handle it in dialog based project? Pin
    sages7-Mar-03 13:56
    susssages7-Mar-03 13:56 
    AnswerRe: Help:How to handle it in dialog based project? Pin
    8-Mar-03 21:31
    memberAlberto Gattegno8-Mar-03 21:31 
    GeneralRe: Help:How to handle it in dialog based project? Pin
    sages9-Mar-03 15:21
    susssages9-Mar-03 15:21 
    GeneralRe: Help:How to handle it in dialog based project? Pin
    10-Mar-03 6:26
    memberAlberto Gattegno10-Mar-03 6:26 
    GeneralHow to change the height of header? Pin
    sages10-Mar-03 20:45
    susssages10-Mar-03 20:45 
    Generalfix for MFC ver 7 Pin
    mijoh19-Jan-03 5:54
    membermijoh19-Jan-03 5:54 
    GeneralYou are not as silly as you look! Pin
    Nice Life24-Feb-04 23:56
    memberNice Life24-Feb-04 23:56 
    GeneralColumn labels without '\n' characters Pin
    vladob5-Dec-02 1:38
    membervladob5-Dec-02 1:38 
    GeneralJust using listctrl... one way to do it... Pin
    Adam Bialowas26-Oct-02 10:18
    sussAdam Bialowas26-Oct-02 10:18 
    Questionhow can I paint CListCtrl with custom color Pin
    fyl_jf25-Jul-02 22:10
    memberfyl_jf25-Jul-02 22:10 
    AnswerRe: how can I paint CListCtrl with custom color Pin
    19-Oct-02 21:36
    memberAlberto Gattegno19-Oct-02 21:36 
    GeneralMulti lines in the columns of the Control Pin
    Udayini5-Oct-01 18:19
    memberUdayini5-Oct-01 18:19 
    GeneralRe: Multi lines in the columns of the Control Pin
    6-Oct-01 21:52
    memberAlberto Gattegno6-Oct-01 21:52 
    Questionxp visuals...? Pin
    Safai28-Sep-01 6:20
    memberSafai28-Sep-01 6:20 

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

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

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