Horizontal Scrolling List Box in an MFC Class

ID: Q146437


The information in this article applies to:
  • The Microsoft Foundation Classes (MFC), used with:
    • Microsoft Visual C++, 32-bit Editions, version 4.0


SUMMARY

The HLISTBOX sample contained in HLISTBOX.EXE illustrates how to implement horizontal scrolling in a CListBox-derived class.

The following files are available for download from the Microsoft Download Center. Click the file names below to download the files:


Hlistbox.exe

For more information about how to download files from the Microsoft Download Center, please visit the Download Center at the following Web address

http://www.microsoft.com/downloads/search.asp
and then click How to use the Microsoft Download Center.

NOTE: Use the -d option when running HLISTBOX.EXE to decompress the file and recreate the proper directory structure.


MORE INFORMATION

HLISTBOX implements a new class called CHorzListBox that is derived from CListBox. This new class automatically updates the horizontal extent of a list box to that of the longest string included in the list box. It works well with list boxes that have or don't have the LBS_USETABSTOPS style. An ordinary Windows list box does not attempt to implement horizontal scrolling of this nature.

Basically, the CHorzListBox intercepts all messages that would affect the horizontal extent based on the string lengths. It tracks the extent of all strings in the list box through an array. Examine the source code for details.


Sample Files    Descriptions
------------------------------------------------------------------------

HLB.CPP         Implementation of the CHorzListBox class.

HLISTBOX.CPP    Application, mostly AppWizard generated dialog-based
                application.

HLISTDLG.CPP    Implementation of the test dialog. Also the
                application's main window. 
NOTE: The "Lock/Unlock" button on the main dialog locks and unlocks the automatic updating of horizontal extent for the list box.

Additional query words: 4.00 scroll bar scrollbar listbox

Keywords : kbfile kbsample kbMFC KbUIDesign kbVC
Version : winnt:4.0
Platform : winnt
Issue type :


Last Reviewed: December 11, 1999
© 2000 Microsoft Corporation. All rights reserved. Terms of Use.