ListVew with icons, NULL return on LVM_SETIMAGELIST

This is a discussion on ListVew with icons, NULL return on LVM_SETIMAGELIST within the Windows Programming forums, part of the Platform Specific Boards category; Hello, I have a problem setting up a listview dialog. All the functions work well except the 'LVM_SETIMAGELIST' message to ...

  1. #1
    Registered User
    Join Date
    Mar 2005
    Location
    Juneda
    Posts
    287

    ListVew with icons, NULL return on LVM_SETIMAGELIST

    Hello, I have a problem setting up a listview dialog. All the functions work well except the 'LVM_SETIMAGELIST' message to the dialog window. That's the list creation code:
    Code:
    llistaImatgesG=ImageList_Create(GetSystemMetrics(SM_CXICON),GetSystemMetrics(SM_CYICON),ILC_COLOR32|ILC_MASK,1,1);
    llistaImatgesP=ImageList_Create(GetSystemMetrics(SM_CXSMICON),GetSystemMetrics(SM_CYSMICON),ILC_COLOR32|ILC_MASK,1,1);
    hIcona=LoadIcon(NULL,MAKEINTRESOURCE(IDI_QUESTION));
    ImageList_AddIcon(llistaImatgesG,hIcona);
    ImageList_AddIcon(llistaImatgesP,hIcona);
    I have used a static global vars for the image lists, like:
    Code:
    HICON hIcona;
    static HIMAGELIST llistaImatgesG;
    static HIMAGELIST llistaImatgesP;
    now the listview creation is
    Code:
    CreateWindowEx(WS_EX_CLIENTEDGE,WC_LISTVIEW,"",WS_CHILD|WS_TABSTOP|WS_VISIBLE|LVS_SHOWSELALWAYS|LVS_NOSORTHEADER|LVS_ICON|LVS_SHAREIMAGELISTS,100,100,200,200,hwnd,(HMENU)LLISTA,hInstance,NULL);
    vsm=SendMessage(GetDlgItem(hwnd,LLISTA),LVM_SETIMAGELIST,(WPARAM)llistaImatgesG,(LPARAM)LVSIL_NORMAL);
    if(vsm==(LPARAM)NULL)
                {
                MessageBox(hwnd,"Error on SETIMAGELIST","",MB_OK);
                }
            vsm=SendMessage(GetDlgItem(hwnd,LLISTA),LVM_SETIMAGELIST,(WPARAM)llistaImatgesP,(LPARAM)LVSIL_SMALL);
    if(vsm==(LPARAM)NULL)
                {
                MessageBox(hwnd,"Error on SETIMAGELIST","",MB_OK);
                }
    is there on the 'SETIMAGELIST' message where I get a NULL return on both cases, but I'm sure that the image list is right because I can paint it on the WM_PAINT message with:
    Code:
    case WM_PAINT:
            {
            RECT area;
            GetClientRect(hwnd,&area);
            hdc=BeginPaint(hwnd,&ps);
            ImageList_Draw(llistaImatgesG,0,hdc,0,0,ILD_NORMAL);
            ImageList_Draw(llistaImatgesP,0,hdc,100,0,ILD_NORMAL);
            EndPaint(hwnd,&ps);
            }
        break;
    so I think that the only problem is on the 'appending' the image list to the listview.
    How can I solve that? Or, what I'm doing wrong?

    Thank's in advance
    Niara

  2. #2
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    It seems you have the WPARAM and LPARAM of LVM_SETIMAGELIST the wrong way round, try:
    Code:
    vsm=SendMessage(GetDlgItem(hwnd,LLISTA),
                    LVM_SETIMAGELIST,
                    LVSIL_NORMAL,
                    (LPARAM)llistaImatgesG);
    CProgramming FAQ
    Caution: this person may be a carrier of the misinformation virus.

  3. #3
    Registered User
    Join Date
    Mar 2005
    Location
    Juneda
    Posts
    287
    Hello Ken Fitlike, it works right in the way you post. But take a look at the description on the win32 api reference manual about 'LVM_SETIMAGELIST':
    Code:
    The LVM_SETIMAGELIST message assigns an image list to a list view control. You can send this message 
    explicitly or by using the ListView_SetImageList macro.
    
    LVM_SETIMAGELIST  
    wParam = (WPARAM) (int) iImageList; 
    lParam = (LPARAM) (HIMAGELIST) himl; 
     
    Parameters
    
    himl: Handle to the image list to assign.
    
    iImageList: Type of image list. This parameter can be one of the following values:
    
    LVSIL_NORMAL	Image list with large icons
    LVSIL_SMALL	Image list with small icons
    LVSIL_STATE	Image list with state images
     
    Return Values: Returns the handle of the image list previously associated with the control if successful; NULL 
    otherwise.
    (I have omitted some text, but is still the same explanations). As I understand it should be working in the way I post... but as like in lots of ms features there's some magic to use to make it work

    But for now I can continue with my work; thank's Ken for your time and help.
    Niara

  4. #4
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    >>As I understand it should be working in the way I post<<

    Both the msdn page and the help file you've quoted say the same thing - the WPARAM is a flag designating the type of image list and the LPARAM is the image list handle.
    CProgramming FAQ
    Caution: this person may be a carrier of the misinformation virus.

  5. #5
    Registered User
    Join Date
    Mar 2005
    Location
    Juneda
    Posts
    287
    Yeah, what a mistake. Sorry and more thanks for the correction.
    Niara

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. "Virtual Printer" or "Moving Printjobs"
    By extasic in forum Windows Programming
    Replies: 12
    Last Post: 06-30-2011, 09:33 AM
  2. Syntax Error??
    By Kennedy in forum C Programming
    Replies: 8
    Last Post: 09-06-2006, 12:04 PM
  3. Button handler
    By Nephiroth in forum Windows Programming
    Replies: 8
    Last Post: 03-12-2006, 06:23 AM
  4. Wierd Segmentation Faults on Global Variable
    By cbranje in forum C Programming
    Replies: 6
    Last Post: 02-19-2005, 12:25 PM
  5. simulate Grep command in Unix using C
    By laxmi in forum C Programming
    Replies: 6
    Last Post: 05-10-2002, 05:10 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21