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

Hide scrollbars from a CListCtrl

, 1 Jul 2003 CPOL
Rate this:
Please Sign up or sign in to vote.
Removes the scrollbars from a CListCtrl without loosing the ability to scroll
<!-- Article image -->

Sample Image - ListCtrlSBHide.jpg

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

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)

Share

About the Author

Lars [Large] Werner
Engineer
Norway Norway
I'm looking for new opportunities in Norway, contact me on email, twitter or Facebook
Not able to travel (a lot) so either home office or in Telemark area, Norway.
 
----------------------------------
Visit http://lars.werner.no/ for my techno-blog!
----------------------------------
 
Projects
* Adito - Simple Windows installer for Adito/OpenVPN ALS!
* Unpacker - Auto extract of multiple archives (RAR/ZIP) with queue support and cleanup options!
* SizeMe - Ultimate tool for maximize your output on CD/DVDs!
Follow on   Twitter   Google+

Comments and Discussions

 
QuestionGood One PinmemberMANISH RASTOGI19-Jul-11 20:26 
Generala problem about CListCtrlHiddenSB Pinmemberfollowait7-Jul-08 1:41 
GeneralThanx PinmemberDenis Lazarev23-Jun-07 9:06 
GeneralIt does work for NT Systems but not for CE PinsussNataraj S.15-Mar-04 20:43 
GeneralRe: It does work for NT Systems but not for CE PinmemberGDavy11-May-04 4:10 
GeneralRe: It does work for NT Systems but not for CE PinmemberSummer June23-May-05 22:26 
QuestionHow to Remove Scrollbar Controls form CFormView PinsussSudhakar_Chavali8-Jan-04 2:31 
AnswerRe: How to Remove Scrollbar Controls form CFormView PinmemberLars [Large] Werner8-Jan-04 2:36 
GeneralRe: How to Remove Scrollbar Controls form CFormView PinmemberKoundinya8-Jan-04 2:55 
GeneralRe: How to Remove Scrollbar Controls form CFormView PinmemberKoundinya8-Jan-04 3:00 
AnswerRe: How to Remove Scrollbar Controls form CFormView Pinmembermjw128-Jul-04 16:16 
GeneralRe: How to Remove Scrollbar Controls form CFormView PinmemberLars [Large] Werner28-Jul-04 18:50 
GeneralRe: How to Remove Scrollbar Controls form CFormView Pinmemberccsilence6-Jan-10 3:05 
GeneralVery nice. PinmemberNeal.Liu3-Jan-04 20:38 
GeneralRe: Very nice. PinmemberLars [Large] Werner3-Jan-04 20:41 
GeneralHeight is not correct PinmemberNguyen Tuan Quang14-Dec-03 17:31 
GeneralRe: Height is not correct PinmemberLars [Large] Werner14-Dec-03 20:24 
GeneralRe: Height is not correct PinmemberIgorn2-Mar-04 13:22 
GeneralRe: Height is not correct Pinmembernthroot18-May-06 18:52 
GeneralAdditionnal explanations PinmemberStlan5-Oct-03 23:27 
GeneralRe: Additionnal explanations PinmemberLars [Large] Werner6-Oct-03 10:44 
GeneralScrollbar of CListCtrl PinsussAnonymous10-Sep-03 4:57 
GeneralRe: Scrollbar of CListCtrl PinmemberLars [Large] Werner10-Sep-03 9:13 
Generalanother way to hide scroll bars Pinmemberglip1-Jul-03 21:39 
GeneralRe: another way to hide scroll bars PinmemberLars [Large] Werner1-Jul-03 23:30 

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.

| Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.1411028.1 | Last Updated 2 Jul 2003
Article Copyright 2003 by Lars [Large] Werner
Everything else Copyright © CodeProject, 1999-2014
Layout: fixed | fluid