Virtual Developer Workshop: Containerized Development with Docker

Environment: Visual C++ 6, IE 5

This example program and code show you one of the ways to use the new, mostly undocumented, FilterBar feature of the ListView control that is available with IE5.0 (or greater). While the example application works, it is by no means an optimal example of how to use this new feature(!).

The Example Application will most likely better explain how to use the FilterBar feature, as the important code is, IMHO, very well commented. Please look it over first if you have any questions. (Tip: Set your Tab size to 4!) FilterBar Example 1 FilterBar Example 2

With IE5.0 comes a new feature for the ListView Control: the FilterBar. An example of how to use this new feature is in the example application (see above). For more information browse through your CommCtrl.h file. (Actually, this is a very smart thing to do each time you install a new version of the SDK! You might be suprised what you can find! This FilterBar stuff is one example, there is also a new Rebar style! Check it out for yourself!)

Using this new feature is simple. First, apply the HDS_FILTERBAR style to the ListView control's Header control. This tells the ListView's Header control to show the FilterBar (filter controls):

m_lcList.GetHeaderCtrl() -> ModifyStyle( 0, HDS_FILTERBAR );			// Add The FilterBar Style
Then, specify the Filter Types for the Columns. In the following example code, I set the Filter Type to HDFT_ISSTRING, which is the String filter type:

HDITEM	hdItem;
hdItem.mask = ( HDI_FILTER );							// Set Mask For Filter Type Information
hdItem.type = HDFT_ISSTRING;							// Set String Filter Type
pHeader -> SetItem( 0, &hdItem );						// Set Item Information
pHeader -> SetItem( 1, &hdItem );						// Set Item Information
pHeader -> SetItem( 2, &hdItem );						// Set Item Information
Now, use the HDM_SETFILTERCHANGETIMEOUT message to set the Timeout value for Filter Change notifications. This allows the user to type in a value without the application constantly processing Filter Change notifications. On the other hand, if you want to get a notification for each character, you could try setting the Timeout value to a very small number. This is useful for incremental filtering.

m_lcList.GetHeaderCtrl() -> SendMessage( HDM_SETFILTERCHANGETIMEOUT, 0, 1000 );	// Set One Second Timeout (Milliseconds)
All that is left to do is to process the notification messages sent by the FilterBar. These notification messages are:

HDN_FILTERCHANGE                Sent to notify you of changes to the Filter 
HDN_FILTERBTNCLICK              Sent to notify you of the FilterBar button being pressed
See the CommCtrl.h file for more information on the above notification messages, and the structures they use.

To get filter information from the control, you use the HDITEM structure, which now has two additional data members, type and pvFilter. Set the mask member of the HDITEM structure with the HDI_FILTER value to manipulate the FilterBar specific members. The type member is used to specify the Filter type, and can accept the following values:

HDFT_ISSTRING                   Filter type is String 
HDFT_ISNUMBER                   Filter type is Number (int) 
HDFT_HASNOVALUE                 Filter is Empty (Setting this value will clear the existing Filter)
The pvFilter member is used to obtain the value in the filter. If type is set to HDFT_ISNUMBER, pvFilter should point to an int. If type is set to HDFT_ISSTRING, pvFilter is a pointer to an HDTEXTFILTER structure, which itself contains a pointer to a buffer, and the (character) length of the buffer. (Note that I could not get the Number type to work correctly.)

After calling CHeaderCtrl::GetItem(...), the pvFilter (int or HDTEXTFILTER structure pointer) should be populated with the Filter data. What you do with this data is up to you.

In the Example Application, this filter data is used to perform incremental filtering of the set of data, and then the resulting data set, if any, is displayed.

While I am no expert with the FilterBar stuff, I would be more than happy to try to answer any questions about it. Have fun!


Download demo application - 40 Kb
Download demo project - 8 Kb
Download source - 16 Kb


  • sample code

    Posted by Eugene Carman on 08/22/2018 10:56pm

    Much of the sample code, while it does run, is truly horrific. (saving vector iterators like end() for later use????????? Sorry if I am too harsh on the code's author, but...

  • filter bar won't accept text

    Posted by Eugene Carman on 08/22/2018 10:50pm

    After too many hours of work, I got the filter bar to appear and respond to mouse events, but it will not accept keyboard input!!!

  • HDM_GETITEMW leaks memory with HDI_FILTER

    Posted by itsomne on 04/13/2009 10:46am

    My code seems to be leaking memory. when i use HDM_GETITEMW, any thoughts?
    HDITEM			hdItem;
    TCHAR			cFilter[1024];
    hdItem.mask = ( HDI_FILTER );						// Set Mask
    ZeroMemory( cFilter, sizeof( cFilter ) );			// Init Buffer For Filter
    hdTFilter.pszText = cFilter;						// Set Buffer For Filter
    hdTFilter.cchTextMax = sizeof( cFilter );			// Set Size Of Buffer
    hdItem.type = HDFT_ISSTRING;						// Set String Filter Type
    hdItem.pvFilter = &hdTFilter			
    ::SendMessage(pHeader -> m_hWnd, HDM_GETITEMW,iColNo, (LPARAM)&hdItem);	// Get Item Filter Data

  • It is not working on my system

    Posted by bharatsingh on 03/16/2005 08:26am

    i downloaded this demo project, it is working on my system very well, but when i wrote my own code like this then there are so many errors like HDS_FILTERBAR , HDI_FILTER and hdItem.type = HDFT_ISSTRING not define. there are many other errors like this please helpe my email id is bharat.singh@sisl.co.in

    • Missing SDK...

      Posted by jtwine on 02/03/2006 09:40pm

      You need to have the updated SDK installed correctly to have those values available. -=- James

  • Filter edit don't get input more that 4 chars if text set programetically?

    Posted by Legacy on 08/09/2002 07:00am

    Originally posted by: Sajid Majid

    Hi All,
    On button click I am creating ListBox & then selecting value to filter. The selected value is set in filter using SetItem(...). This is ok, I can delete some chars from set value but can't enter if more than 4 char in edit. I have found this problem when I have set value for column from list, otherwise u can edit with keyboard without any problem.
    Hope any one have any solution?.


  • Access Violation in Comctl32.dll

    Posted by Legacy on 02/19/2002 08:00am

    Originally posted by: Kyle Sluder

    When my program calls pHeader->SetItem() I get an Access Violation in Comctl32.dll... is something going on with SetItem? I'm running VC++ 6 Standard, Win98 SE, IE6, and Office 2000 Pro.

    Also, how do I filter the list? In your demo app (which works without an access violation) I enter a filter into the FilterBar (example: Car) and click on the filter icon, but it doesn't want to work... I still get all the Bucket items, for example.

  • Better way...

    Posted by Legacy on 12/06/2001 08:00am

    Originally posted by: Stephan Roth

    To overwrite the virtual method OnNotify() I do not hold for a particularly elegant solution.
    The better way (IMHO) is to add ON_NOTIFY message handlers for HDN_FILTERCHANGE and/or HDN_FILTERBTNCLICK:

    In the header file add:

    afx_msg void OnFilterChanged(NMHDR* pNMHDR, LRESULT* pResult);
    afx_msg void OnFilterBtnClicked(NMHDR* pNMHDR, LRESULT* pResult);

    In the .cpp file add the following entries to the message map, but outside(!) of the special comments for the MFC ClassWizard:

    BEGIN_MESSAGE_MAP(MyClass, SuperClass)
    // .....



    The functions:

    void MyClass::OnFilterChanged(NMHDR* pNMHDR, LRESULT* pResult)
    LPNMHEADER pNMHeader = reinterpret_cast<LPNMHEADER>(pNMHDR);

    // ..........

    *pResult = 0;

    void MyClass::OnFilterBtnClicked(NMHDR* pNMHDR, LRESULT* pResult)

    // ........

    *pResult = 0;

    Just my two pence,
    Stephan Roth, Germany

  • RE:The program can not compile!

    Posted by Legacy on 11/28/2001 08:00am

    Originally posted by: XingJun Zhang

    Thanks Mr James for this free code program.But downloaded the program and cannot get it to compile: 26 errors.

    1 - FBListCtrl.cpp(28) : error C2065: 'HDN_FILTERCHANGE' : undeclared identifier
    2 - FBListCtrl.cpp(29) : error C2065: 'HDN_FILTERBTNCLICK' : undeclared identifier

    I have downloaded the latesd SDK and installed it, also I have added the include and lib directory of SDK into the IDE of VC6.


  • Any way to tab b/w filters?

    Posted by Legacy on 06/29/2001 07:00am

    Originally posted by: Keri

    Has anybody discovered a way to allow the user to move b/w filter edits w/o using the mouse? I'd love to get the TAB key to do the trick...

  • Code does not compile

    Posted by Legacy on 05/03/2001 07:00am

    Originally posted by: Bill Roach

    Down loaded your source code and cannot get it to compile: 25 errors.
    1 - FBListCtrl.cpp(28) : error C2065: 'HDN_FILTERCHANGE' : undeclared identifier
    2 - FBListCtrl.cpp(29) : error C2065: 'HDN_FILTERBTNCLICK' : undeclared identifier

    I have Version 5.81 of Comctl32.dll.


  • Loading, Please Wait ...

  • You must have javascript enabled in order to post comments.

Leave a Comment
  • Your email address will not be published. All fields are required.

Most Popular Programming Stories

More for Developers

RSS Feeds

Thanks for your registration, follow us on our social networks to keep up-to-date