ListView Control displays blank images

Using VS 2005, I have a ListView control in an ATL dialog. I am creating a image list and trying to use it for both header images and item images in the ListView control. I am doing this in the InitDialog function. When the dialog is displayed I see spaces where the images are suppose to be but they are all blank. If I use the image list to draw a icon I do see the expected image.

The code in brief to set an image in the header (from my Init Dialog) follows.

Any idea what I am doing wrong

Alicia

************* Code Outline *************

INITCOMMONCONTROLSEX iccex; // Carries data that is used to load

// control classes for the rebar

// Initialize the INITCOMMONCONTROLSEX structure.

iccex.dwSize = sizeof (INITCOMMONCONTROLSEX);

// Load rebar and toolbar control classes.

iccex.dwICC = ICC_LISTVIEW_CLASSES;

// Register rebar and toolbar control classes from the DLL for the

// common control.

InitCommonControlsEx (&iccex);

int iIconX = 16;

int iIconY = 16;

m_himagelist = ImageList_Create(iIconX, iIconY,ILC_COLOR, 4, 4);

ATLASSERT(m_himagelist != NULL);

//

// load our standard icons

//

HICON hiconItem = (HICON) LoadImage(_Module.m_hInst, MAKEINTRESOURCE(IDI_BLANK),IMAGE_ICON,iIconX, iIconY,0);

iReturn = ImageList_AddIcon(m_himagelist, hiconItem);

ATLASSERT(iReturn == BLANK_ICON);

DestroyIcon(hiconItem);

//

hiconItem = (HICON) LoadImage(_Module.m_hInst, MAKEINTRESOURCE(IDI_TEXT),IMAGE_ICON,iIconX, iIconY,0);

iReturn = ImageList_AddIcon(m_himagelist, hiconItem);

ATLASSERT(iReturn == TEXT_ICON);

DestroyIcon(hiconItem);

//

// set extended style

//

ListView_SetExtendedListViewStyle(m_hwndListView,LVS_EX_SUBITEMIMAGES | LVS_EX_FULLROWSELECT);

//

// connect our image list

//

ATLASSERT(m_himagelist != NULL);

if (m_himagelist == NULL)

return FALSE;

ListView_SetImageList(m_hwndListView, m_himagelist, LVSIL_SMALL);

i = ImageList_GetImageCount(m_himagelist);

ATLASSERT(i > 0);

//

// 1st, clear out any entries from the previous dialog

//

bReturn = ListView_DeleteAllItems(m_hwndListView);

ATLASSERT(bReturn);

//

// add our columns, main item first

//

lvcolumn.mask = LVCF_TEXT | LVCF_WIDTH | LVCF_IMAGE | LVCF_FMT;

//

lvcolumn.fmt = LVCFMT_LEFT | LVCFMT_BITMAP_ON_RIGHT;

lvcolumn.cx = 100;

lvcolumn.pszText = _T("Name");

lvcolumn.cchTextMax = 4;

lvcolumn.iSubItem = 0;

lvcolumn.iOrder = 1;

lvcolumn.iImage = UP_ICON;

iReturn = ListView_InsertColumn(m_hwndListView,NAME_COLUMN,&lvcolumn);

ATLASSERT(iReturn == NAME_COLUMN);



Answer this question

ListView Control displays blank images

  • Jemmy Wang

    I trippled checked this. The image handle from LoadImage is not null.
  • Adrian Raine

    I see no validation code that check is LoadImage succeeded!

    Maybe you have problems to load the resource!



  • Genesis_B

    Is that still an issue

    Thanks,
    Ayman Shoukry
    VC++ Team


  • innes

    It seems that we have the same problem too.

    Could you please post the workaround.

    Would be very helpful.

    Thanks



  • mnsh

    Thanks a Alicia, could you post the workaround in case somebody else runs through the same issue.

    Thanks,
    Ayman Shoukry
    VC++ Team


  • Clement Edwin

    I know the image was loaded because I am drawing one of the icons in the WM_PAINT handler and it is working correctly.
  • Richard Sloggett

    I contacted technical support. This was verified to be a bug and I was given a work around.
  • MSD

    I did some more testing today and found that the list control works correctly in a Win32 test container. If you try and use the same COM dll that contains a ListView control in a ATL dialog in a C# test container the image is missing.

    I have a test app if anyone is interested.


  • ListView Control displays blank images