Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8004967
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T17:04:48+00:00 2026-06-04T17:04:48+00:00

I want to create an HIMAGELIST for the list view. It actually needs to

  • 0

I want to create an HIMAGELIST for the list view. It actually needs to consist of file icons.

Here’s the code I have:

HIMAGELIST imageList = ImageList_Create(GetSystemMetrics(SM_CXSMICON),
                                          GetSystemMetrics(SM_CYSMICON),
                                          ILC_MASK, 1, 1);

HICON ico = reinterpret_cast<HICON>(LoadImage(0,IDI_APPLICATION,
                                                IMAGE_ICON,0,0,LR_SHARED));
ImageList_AddIcon(imageList, ico);

ListView_SetImageList(listView, imageList, LVSIL_SMALL);

The list view with three elements now has three application items.

However when I try to add another icon (IDI_HAND in this case), I still get the same 3 icons.

Another problem I have is that I can’t fetch the actual file icons I need:

SHFILEINFO sfi;
SHGetFileInfo (L"C:\\test.txt", NULL, &sfi, sizeof (sfi), SHGFI_SYSICONINDEX | SHGFI_SMALLICON);
ImageList_AddIcon(imageList, sfi.hIcon);

This results in empty icons, not the txt icons I want.

I’ve been struggling with this for ever, and I greatly appreciate your help here.

UPDATE

I’m using sample code I found on the Internet to fill the list view (obviously that’s not what I want):

UINT columnMask = LVCF_TEXT|LVCF_FMT|LVCF_SUBITEM|LVCF_WIDTH;
LVCOLUMN lc[] = {
{ columnMask, 0, 150, L"Text...",0, 0,0,0 },
{ columnMask, LVCFMT_CENTER, 70, L"Number",0, 1,0,0 },
{ columnMask, 0, 100, L"Whatever",0, 2,0,0 },
};

ListView_InsertColumn(listView, 0, &lc[0]);
ListView_InsertColumn(listView, 1, &lc[1]);
ListView_InsertColumn(listView, 2, &lc[2]);

UINT itemMask = LVIF_TEXT;
LVITEM li[] = {
   { itemMask, 0,0, 0,0, L"...for the first item!",0, 0,0,0,0,0,0 },
   { itemMask, 0,1, 0,0, L"1",0, 0,0,0,0,0,0 },
   { itemMask, 0,2, 0,0, L"14 bucks",0, 0,0,0,0,0,0 },
   { itemMask, 1,0, 0,0, L"...for the second item!",0, 0,0,0,0,0,0 },
   { itemMask, 1,1, 0,0, L"24",0, 0,0,0,0,0,0 },
   { itemMask, 1,2, 0,0, L"2 suns",0, 0,0,0,0,0,0 },
   { itemMask, 2,0, 0,0, L"...for the second item!",0, 0,0,0,0,0,0 },
   { itemMask, 2,1, 0,0, L"24",0, 0,0,0,0,0,0 },
   { itemMask, 2,2, 0,0, L"2 suns",0, 0,0,0,0,0,0 },
   { itemMask, 3,0, 0,0, L"...for the second item!",0, 0,0,0,0,0,0 },
   { itemMask, 3,1, 0,0, L"24",0, 0,0,0,0,0,0 },
   { itemMask, 3,2, 0,0, L"2 suns",0, 0,0,0,0,0,0 },
};

// setting an icon like this doesn't work
li[0].iImage = sfi.iIcon;

ListView_InsertItem(listView, &li[0]);
ListView_SetItem(listView, &li[1]);
ListView_SetItem(listView, &li[2]);

ListView_InsertItem(listView, &li[3]);
ListView_SetItem(listView, &li[4]);
ListView_SetItem(listView, &li[5]);

ListView_InsertItem(listView, &li[6]);
ListView_SetItem(listView, &li[7]);
ListView_SetItem(listView, &li[8]);
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T17:04:50+00:00Added an answer on June 4, 2026 at 5:04 pm

    The iImage member of LVICON is the index of the icon in the imagelist you passed to ListView_SetImageList. You are passing the index of the icon in the system imagelist, but the imagelist you passed to ListView_SetImageList is your private imagelist. Either

    1. Use ListView_SetImageList to associate the imagelist with your private imagelist, and set the iImage to the index in your private imagelist (the return value from ImageList_AddIcon)
    2. Use ListView_SetImageList to associate the imagelist with the system imagelist, and set the iImage to the index in the system imagelist.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i want create XML file here is my following code String fileName = jasstech.xml;
In C# code, I want create a log file for each each method in
I want create a html5 audio in dynamic and play it,here is the code:
i want create image animation , i have 50 images with png format now
I want create module which update list of usb devices automatically (not only mass
I want to create a file in the current directory (where the executable is
I want create some view, and add dynamically to it text and images Somebody
I want create a tarball that when extracted the file(s) will be placed at
I want create a function that verify if the numbers of a list fall
I want create a DataSet class which is basically a list of samples. But

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.