CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 15 of 33

Thread: ListCtrl in MFC

Threaded View

  1. #31
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: ListCtrl in MFC

    I've updated the project to VS2019 (sorry I don't have VS2015 installed, and the 2019 community edition is free, so why not use the latest?).

    For something that was written 16 years ago, upgrading it to 2019 was painless, I only had to change the WINVER from 0x0500 to 0x0501.

    This was originally an x86 ANSI character set VC 7.1 app, but when it converted to VC2019, it build and ran as UNICODE app. Ordinarily, this would have caused a lot of upgrade headaches, but there were no issues because I used the _T("") macros for string literals throughout (had I simply used "my string" literals, I would have had work to do getting it to compile).

    To compile this, you'll need the v142 build tools and MFC v142 libraries.
    1) Open the Visual Studio 2019 Installer
    2) Select 'Modify'
    3) Click on the Individual Components tab
    4) Under Compilers, build tools and runtimes, select MSVC v142 - VS 2019 C++ x64/x86 build tools
    5) Under SDKs, libraries, and frameworks, select C++ v14.2x MFC for v142 build tools (x86 & x64)

    Note: there are multiple versions for v14.2x for step 4 and 5 in each category. I don't know which one is being used and am too lazy to track it down, so I just selected them all.

    This sample looks dated and it uses images to display a checkbox rather than using the images built into the list control (which may or may not been available 16 years ago). That was around the XP timeframe and they looked okay back then with the standard Windows theme, but they sure are ugly now.

    There is a lot going on in this sample:
    1) Uses a virtual list control
    a) Uses a callback (via an LVN_GETDISPINFO handler) to retrieve the row data from a list
    b) Unlike a regular list control, it doesn't initially get populated by copying row data into the control
    c) Virtual list controls can handle large data sets (especially when used with a list that is a memory mapped file).
    d) Virtual list controls are very responsive. Try scrolling a virtual list control with 10K items, vs. a regular list control with 10K items - the regular list control will be dog slow
    2) Uses a background thread to populate the list control
    a) The secondary thread doesn't block the UI thread while filling the list
    b) The UI remains responsive while the background operations are performed.
    3) While this sample does not show this, the background thread can change the list data, and the virtual list control will pick the changes up without needing to do anything (kind of an early form of control binding).
    4) Shows list control row 'hit testing'. Because images are used, we are using ON_NOTIFY, NM_CLICK to check if the user has clicked on the icon that represents the check box. If the 'check box' icon has been clicked on we toggle the check state in the underlying list item, and tell the control to update the item (which causes the LVN_GETDISPINFO callback to be called).
    Attached Files Attached Files

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured