locked
Problem implementing ListView with viewing mode set to LV_VIEW_ICON RRS feed

  • Question

  • I need to create a list view, giving the user a choice to switch between LV_VIEW_DETAILS and LV_VIEW_ICON. I need to implement ICONS view, with 128x128 sized icons and a two-line label text placed below this icon. I have the following code to add a row:

    AddRow(void *userData)

    {

    LVITEM item = { 0 };

    item.mask = LVIF_TEXT | LVIF_IMAGE | LVIF_PARAM | LVIF_NORECOMPUTE;
    item.iItem = ASMAXInt32;
    item.lParam = (LPARAM)userData;
    item.pszText = LPSTR_TEXTCALLBACK;
    item.iImage = I_IMAGECALLBACK;

    int index = ListView_InsertItem(mHWND, &item);
    if (index >= 0)
    {
    UINT columns[] = {1, 2, 3, 4};
    LVTILEINFO tileInfo = {sizeof(LVTILEINFO), index, elementsofex(columns), static_cast<PUINT>(columns)};
    ListView_SetTileInfo(mHWND, &tileInfo);

    LVTILEVIEWINFO tileViewInfo = {sizeof(LVTILEVIEWINFO), 0, };
    tileViewInfo.dwMask = LVTVIM_COLUMNS | LVTVIM_TILESIZE;
    tileViewInfo.cLines = elementsofex(columns);
    ListView_SetTileViewInfo(mHWND, &tileViewInfo);
    }

    }

    Here I have used API ListView_SetTileViewInfo to set the tiles view info, but I could not find any similar API to set the view info for ICONS viewing mode. Is there any such API ? 

    To retrieve the corresponding icons, I have the following code;

    // Get the icon index using SHGetFileInfo
    SHFILEINFOW fileInfo = {0};
    ::SHGetFileInfoW(lastDot, 0, &fileInfo, sizeof(fileInfo), SHGFI_USEFILEATTRIBUTES | SHGFI_SYSICONINDEX);

    // Retrieve the system image list.
    HIMAGELIST *imageList;
    HRESULT hres = ::SHGetImageList(SHIL_JUMBO, IID_IImageList, (void **)&imageList);

    if (hres == S_OK)
    {

    HICON hico;

    hres = ((IImageList*)imageList)->GetIcon(fileInfo.iIcon, ILD_SCALE | ILD_TRANSPARENT, &hico);

    HICON icon = ImageList_GetIcon(*imageList, fileInfo.iIcon, ILD_NORMAL);
    }

    But the icons that I get using this, are drawn only on a 32x32 area and are not rendered in full. Instead just the upper left corner of the icons could be seen. How do I resolve this?


    Parul Gupta

    Monday, November 10, 2014 5:40 PM