Thread: ListView image & columns

  1. #1
    Registered User
    Join Date
    May 2009
    Location
    Prague, CZ
    Posts
    4

    Thumbs down ListView image & columns

    Hi,
    I need some help with WinAPI.

    I've created a listview control with 5 columns (using LVM_INSERTCOLUMN message) and prepared the ImageList:

    Code:
    SHFILEINFO shfi;
    HIMAGELIST imglist;
    
    if (SHGetFileInfo(L"C:\\Windows\\System32\\AdapterTroubleshooter.exe", 0, &shfi, sizeof(SHFILEINFO), SHGFI_ICON | SHGFI_SMALLICON) == 0){
    		MessageBox(hWnd, L"Error getting file info.", L"ERROR", MB_ICONERROR);
    }
    imglist = ImageList_Create(GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON), ILC_COLOR32, 1, 1);
    ImageList_AddIcon(imglist, shfi.hIcon);
    ListView_SetImageList(listbox, imglist, LVSIL_SMALL);
    (listbox is actually HWND handle for ListView)

    Then I add items:

    Code:
    SendMessage(listbox, LVM_INSERTITEM, 0, (LPARAM) &omfg);
    
    omfg.iSubItem = 0;
    omfg.pszText = buffer1;
    SendMessage(listbox, LVM_SETITEM, 0, (LPARAM) &omfg);
    
    omfg.iSubItem = 1;
    omfg.pszText = buffer2;
    SendMessage(listbox, LVM_SETITEM, 0, (LPARAM) &omfg);
    (omfg is a LVITEM structure)

    And here comes the problem: as it turns out, there's no way to specify in which column (iSubItem) the image should be placed. No matter what I do, the image is always displayed in the first column. Since I needed to place the image in the last (fifth) column, I've tried putting -1 to the iImage member of LVITEM structure, and then changing it to 0 before sending message for iSubItem = 4, but this had no effect: the image was still in the first column.
    By commenting out lines of code, I've figured out that the image has already been placed in the first column after LVM_INSERTITEM message has been sent.

    So the question is: how do I place the image in the fifth column of the listview?

  2. #2
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,868
    You can't put an image in any but the first column.

    You could try to owner draw the entire listview but this is difficullt and time consuming (so you would have to decide if the functionality gained is worth the time invested).
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problem reading tiff image files?
    By compz in forum C++ Programming
    Replies: 9
    Last Post: 10-30-2009, 04:17 AM
  2. Sorting ListView columns
    By Scarvenger in forum Windows Programming
    Replies: 6
    Last Post: 09-11-2006, 10:10 AM
  3. Reading color tiff images?
    By compz in forum Game Programming
    Replies: 1
    Last Post: 11-21-2003, 12:48 AM
  4. Replies: 4
    Last Post: 03-02-2003, 09:12 AM