Thread: image in a list?

  1. #1
    * Death to Visual Basic * Devil Panther's Avatar
    Join Date
    Aug 2001
    Posts
    768

    Question image in a list?

    How can I insert images(bitmaps) and icons into a list control?




    thank you.
    "I don't suffer from insanity but enjoy every minute of it" - Edgar Allen Poe

    http://www.Bloodware.net - Developing free software for the community.

  2. #2
    Yes, my avatar is stolen anonytmouse's Avatar
    Join Date
    Dec 2002
    Posts
    2,544

  3. #3
    Registered User
    Join Date
    Nov 2001
    Posts
    1,348
    Check out CodeProject code section for examples.

    http://www.codeproject.com/listctrl/

    Kuphryn

  4. #4
    * Death to Visual Basic * Devil Panther's Avatar
    Join Date
    Aug 2001
    Posts
    768
    Using the msdn link above i've managed to write this... it doesn't work, instead it changes the app's icon. why???

    Code:
                    lvc.mask = LVCF_FMT | LVCF_IMAGE | LVCF_SUBITEM | LVCF_WIDTH;
                    lvc.iSubItem = 2;
                    lvc.pszText = "Status";
                    lvc.cx = 58;
                    SendMessage(hLookupList, LVM_INSERTCOLUMN, 2, (LPARAM)&lvc);
    
                    hIconList = ImageList_Create(GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON), ILC_MASK, 1, 1);
                    hIconItem = LoadIcon(ghInstance, MAKEINTRESOURCE(ID_ICON_STATUSOK));
                    ImageList_AddIcon(hIconList, hIconItem);
                    DestroyIcon(hIconItem);
                    ListView_SetImageList(hLookupList, hIconList, LVSIL_SMALL);
    
    
                    lvi.iItem = 0; //row
                    lvi.iSubItem = 2;
                    lvi.iImage = 0;
                    if (lvi.iSubItem)
                       SendMessage(hLookupList, LVM_SETITEM, NULL, (LPARAM)&lvi);
                    else
                       SendMessage(hLookupList, LVM_INSERTITEM, NULL, (LPARAM)&lvi);


    Can someone please give me an example without classes...

    thanks
    "I don't suffer from insanity but enjoy every minute of it" - Edgar Allen Poe

    http://www.Bloodware.net - Developing free software for the community.

  5. #5
    Yes, my avatar is stolen anonytmouse's Avatar
    Join Date
    Dec 2002
    Posts
    2,544
    >> instead it changes the app's icon. why??? <<

    Windows uses the first icon in the resource file as the application icon.

    >> Can someone please give me an example without classes... <<

    Try the listview sample here:
    http://www.john.findlay1.btinternet....rl/comctrl.htm

  6. #6
    * Death to Visual Basic * Devil Panther's Avatar
    Join Date
    Aug 2001
    Posts
    768

    Question

    thank you for the example it really helped me, but i have one last problem with the subitems...

    The image only works when the subitem is zero... so all I see in the subitems is text:

    Code:
    lvc.mask = LVCF_FMT | LVCF_TEXT | LVCF_WIDTH;
    lvc.fmt = LVCFMT_LEFT;
    lvc.iSubItem = 0;
    lvc.cx = 168;
    lvc.pszText = "one";
    SendMessage(hLookupList, LVM_INSERTCOLUMN, 0, (LPARAM)&lvc);
    
    lvc.mask = LVCF_FMT | LVCF_TEXT | LVCF_SUBITEM | LVCF_WIDTH;
    lvc.iSubItem = 1;
    lvc.pszText = "two";
    lvc.cx = 68;
    SendMessage(hLookupList, LVM_INSERTCOLUMN, 1, (LPARAM)&lvc);
    
    lvc.mask = LVCF_FMT | LVCF_TEXT | LVCF_SUBITEM | LVCF_WIDTH;
    lvc.iSubItem = 2;
    lvc.pszText = "three";
    lvc.cx = 58;
    SendMessage(hLookupList, LVM_INSERTCOLUMN, 2, (LPARAM)&lvc);
    
    
    . . .
    
    
    lvi.mask = LVIF_IMAGE | LVIF_TEXT;
    lvi.pszText = "OK";
    
    /* the image works here */
    lvi.iImage = 0;
    lvi.iItem = 0;
    lvi.iSubItem = 0;
    ListView_InsertItem(hLookupList, &lvi);
    
    /* the image doesn't work here */
    lvi.iSubItem = 1;
    lvi.iItem = 0;
    
    ListView_SetItem(hLookupList, &lvi);
    Last edited by Devil Panther; 04-05-2004 at 09:54 AM.
    "I don't suffer from insanity but enjoy every minute of it" - Edgar Allen Poe

    http://www.Bloodware.net - Developing free software for the community.

  7. #7
    * Death to Visual Basic * Devil Panther's Avatar
    Join Date
    Aug 2001
    Posts
    768
    nm... I got it...


    All it takes is:
    Code:
    ListView_SetExtendedListViewStyle(hLookupList, LVS_EX_SUBITEMIMAGES);


    thanks everyone
    "I don't suffer from insanity but enjoy every minute of it" - Edgar Allen Poe

    http://www.Bloodware.net - Developing free software for the community.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 26
    Last Post: 07-05-2010, 10:43 AM
  2. Following CTools
    By EstateMatt in forum C Programming
    Replies: 5
    Last Post: 06-26-2008, 10:10 AM
  3. Adding directory/file names to a linked list
    By thoseion in forum C Programming
    Replies: 13
    Last Post: 12-08-2006, 01:13 PM
  4. problem with structures and linked list
    By Gkitty in forum C Programming
    Replies: 6
    Last Post: 12-12-2002, 06:40 PM