Click here to Skip to main content
Licence CPOL
First Posted 25 Jun 2003
Views 134,146
Bookmarked 32 times

Hide scrollbars from a CListCtrl

By | 1 Jul 2003 | Article
Removes the scrollbars from a CListCtrl without loosing the ability to scroll

Sample Image - ListCtrlSBHide.jpg

Introduction

When you create a CListCtrl with the "NO SCROLL" option it completely stop scrolling. If the data is out of the screen you do not see anything. So you always had to use the scrollbars - until now!

Background

I used this on many kiosk software solutions, and it gives you complete control of the CListCtrl. 

Using the Code

The CListCtrlHiddenSB is derived from CListCtrl.

It has one function to hide the scrollbars: HideScrollBars(int Type, int Which)

The type variable has two const: LCSB_CLIENTDATA and LCSB_NCOVERRIDE

The Which variable tells which scrollbar that will be hidden, here we use the default: SB_BOTH, SB_HORZ and SB_VERT.

Clientdatatype of hiding scrollbars must be called BEFORE any data is entered, because this will change the clientrect of the ctrl to be smaller.

In the demo project I override the normal constructor, like this:

//(...)
class CCListCtrlExampleDlg : public CDialog
{
// Construction
public:
    CCListCtrlExampleDlg(CWnd* pParent = NULL);    // standard constructor

    //These are the defs for each type of how we hide the scrollbars
// Dialog Data
    //{{AFX_DATA(CCListCtrlExampleDlg)
    enum { IDD = IDD_CLISTCTRLEXAMPLE_DIALOG };
    CListCtrlHiddenSB    m_list4;
    CListCtrlHiddenSB    m_list3;
    CListCtrlHiddenSB    m_list2;
    CListCtrlHiddenSB    m_list1;
    //}}AFX_DATA

    // ClassWizard generated virtual function overrides
    //{{AFX_VIRTUAL(CCListCtrlExampleDlg)
    protected:
    virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
    //}}AFX_VIRTUAL
//(...)

Just before the listctrl's are filled with data we hide the scrollbars:

m_list1.HideScrollBars(LCSB_CLIENTDATA, SB_VERT);
m_list2.HideScrollBars(LCSB_CLIENTDATA);
m_list3.HideScrollBars(LCSB_NCOVERRIDE);
m_list4.HideScrollBars(LCSB_NCOVERRIDE);

Known Issues

If you have an listctrl that will just get a horiz-scrollbar, and you choose to hide both of the scrollbars. The function will also remove the vert-scrollbar, but since it is not there some of the gfx will be cut off.

In other words, the clientarena should only be used when you KNOW how many of the scrollbars that will be shown.

Personally I prefer using the NcCalcSize. It removes the scrollbars pretty smooth. It's not dependent on whether or not the listctrl shows all scrollbars or not.

History

First release - Version 1.0. It will be updated when more solutions are found...

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

Lars [Large] Werner

Engineer

Norway Norway

Member

Thnx for viewing my article...
 
Check out some of my projects:
 
http://lars.werner.no/sizeme/ - Ultimate tool for maximize your output on CD/DVDs!
 
http://lars.werner.no/unpacker/ - Auto extract of multiple archives (RAR/ZIP) with queue support and cleanup options!
 
Visit http://lars.werner.no/ for more info!


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
QuestionGood One PinmemberMANISH RASTOGI19:26 19 Jul '11  
Generala problem about CListCtrlHiddenSB Pinmemberfollowait0:41 7 Jul '08  
GeneralThanx PinmemberDenis Lazarev8:06 23 Jun '07  
GeneralIt does work for NT Systems but not for CE PinsussNataraj S.19:43 15 Mar '04  
GeneralRe: It does work for NT Systems but not for CE PinmemberGDavy3:10 11 May '04  
GeneralRe: It does work for NT Systems but not for CE PinmemberSummer June21:26 23 May '05  
QuestionHow to Remove Scrollbar Controls form CFormView PinsussSudhakar_Chavali1:31 8 Jan '04  
AnswerRe: How to Remove Scrollbar Controls form CFormView PinmemberLars [Large] Werner1:36 8 Jan '04  
GeneralRe: How to Remove Scrollbar Controls form CFormView PinmemberKoundinya1:55 8 Jan '04  
GeneralRe: How to Remove Scrollbar Controls form CFormView PinmemberKoundinya2:00 8 Jan '04  
AnswerRe: How to Remove Scrollbar Controls form CFormView Pinmembermjw115:16 28 Jul '04  
GeneralRe: How to Remove Scrollbar Controls form CFormView PinmemberLars [Large] Werner17:50 28 Jul '04  
GeneralRe: How to Remove Scrollbar Controls form CFormView Pinmemberccsilence2:05 6 Jan '10  
GeneralVery nice. PinmemberNeal.Liu19:38 3 Jan '04  
GeneralRe: Very nice. PinmemberLars [Large] Werner19:41 3 Jan '04  
GeneralHeight is not correct PinmemberNguyen Tuan Quang16:31 14 Dec '03  
GeneralRe: Height is not correct PinmemberLars [Large] Werner19:24 14 Dec '03  
GeneralRe: Height is not correct PinmemberIgorn12:22 2 Mar '04  
GeneralRe: Height is not correct Pinmembernthroot17:52 18 May '06  
GeneralAdditionnal explanations PinmemberStlan22:27 5 Oct '03  
GeneralRe: Additionnal explanations PinmemberLars [Large] Werner9:44 6 Oct '03  
GeneralScrollbar of CListCtrl PinsussAnonymous3:57 10 Sep '03  
GeneralRe: Scrollbar of CListCtrl PinmemberLars [Large] Werner8:13 10 Sep '03  
Generalanother way to hide scroll bars Pinmemberglip20:39 1 Jul '03  
GeneralRe: another way to hide scroll bars PinmemberLars [Large] Werner22:30 1 Jul '03  

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
Web01 | 2.5.120517.1 | Last Updated 2 Jul 2003
Article Copyright 2003 by Lars [Large] Werner
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid