flat assembler
Message board for the users of flat assembler.

Index > Windows > Adding Images to Listview

Author
Thread Post new topic Reply to topic
pal



Joined: 26 Aug 2008
Posts: 227
pal 19 Oct 2008, 16:47
Well I'm having problems adding icons to a listview. The text is added and the buffer area for the icon is created, but I cant get the actual icon to appear. This is the area of code which I'm talking about, everything works fine but the icons aren't added.

Code:
    proc    DrivesToListview
        pushad
        push    strDrives
        push    80
        call    [GetLogicalDriveStrings]
        cmp     eax,0
        je      errGetError
        ; Create an image list
        push    64
        push    0
        push    ILC_COLOR16
        push    16
        push    16
        call    [ImageList_Create]
        cmp     eax,0
        je      errGetError
        mov     [hImageList],eax
        ; Set the listviews image list
        push    [hImageList]
        push    LVSIL_SMALL
        push    LVM_SETIMAGELIST
        push    [lvwhWnd]
        call    [SendMessage]
        lea     eax,[strDrives]
        mov     [lvwItem.iItem],-1
        drivesLoop:
            inc     eax
            cmp     byte [eax],0x3A
            jne     endAddDrives
            dec     eax
            push    eax
            mov     [lvwItem.pszText],eax
            mov     [lvwItem.mask],LVIF_TEXT or LVIF_PARAM or LVIF_IMAGE
            mov     [lvwItem.iSubItem],0
            inc     [lvwItem.iItem]
            ; Get the icon of the drive
            push    0x1110 ; SHGFI_ICON or SHGFI_ICONLOCATION or SHGFI_USEFILEATTRIBUTES
            push    351
            push    shFileInfo
            push    0
            push    eax
            call    [SHGetFileInfo]
            mov     [shFileInfo.hIcon],eax
            
            push    [shFileInfo.hIcon]
            push    [hImageList]
            call    [ImageList_AddIcon]
            mov     [lvwItem.iImage],eax

            push    [shFileInfo.hIcon]
            call    [DestroyIcon]
            
            lea     ebx,[lvwItem]
            push    ebx
            push    0
            push    LVM_INSERTITEM
            push    [lvwhWnd]
            call    [SendMessage]
            
            inc     [lvwItem.iSubItem]
            mov     [lvwItem.mask],LVIF_TEXT
            push    [lvwItem.pszText]
            call    DriveTypeToString
            mov     [lvwItem.pszText],eax
            lea     ebx,[lvwItem]
            push    ebx
            push    0
            push    LVM_SETITEM
            push    [lvwhWnd]
            call    [SendMessage]
            pop     eax
            add     eax,4
            jmp     drivesLoop
        endAddDrives:
        push    [hImageList]
        call    [ImageList_Destroy]
        popad
        ret
    endp
    


There are already two columns created by the way. ImageList_AddIcon returns -1 (error) with the error "Invalid Cursor Handle", so I am assuming SHGetFileInfo isn't working as I want it too. SHGetFileInfo returns 1 but GetLastError for it says "User Stopped Resource Enumeration".

I'm probably missing something obvious, just need another set of eyes to look at it. Also should I be using enter and leave in my proc's or not?

Cheers for any help, Unknown.
Post 19 Oct 2008, 16:47
View user's profile Send private message Reply with quote
ghst



Joined: 09 Feb 2007
Posts: 8
Location: Lusitania
ghst 20 Oct 2008, 14:22
Well, I've spoted two mistakes on your source:


1st one:
Code:
            call    [SHGetFileInfo] 
            mov     [shFileInfo.hIcon],eax   ;  <--- eliminate this line, SHGetFileInfo returns TRUE or FALSE!!
             
            push    [shFileInfo.hIcon] 
            push    [hImageList] 
    


2nd:
Code:
        push    [hImageList] 
        call    [ImageList_Destroy]   ; <---- destroy the list only when you don't need it
    


Description: I've modified and attached MINIPAD example to use your code! :)
Download
Filename: MINIPAD.ASM
Filesize: 8.89 KB
Downloaded: 187 Time(s)

Post 20 Oct 2008, 14:22
View user's profile Send private message Reply with quote
pal



Joined: 26 Aug 2008
Posts: 227
pal 20 Oct 2008, 17:12
Ahh cheers, it works now. The documentation says SHGetFileInfo returns a dword_ptr, forgot why I was trying to move it into the structure Embarassed Cheers again mate.
Post 20 Oct 2008, 17:12
View user's profile Send private message Reply with quote
ghst



Joined: 09 Feb 2007
Posts: 8
Location: Lusitania
ghst 21 Oct 2008, 13:30
hum, you are right!

from Win32 Developer's References about SHGetFileInfo func:


Quote:

Return Values

·Returns a value whose meaning depends on the uFlags parameter. If uFlags specifies the SHGFI_EXETYPE value, the return value indicates the type of the executable file. For more information, see the comments below.

·If uFlags includes the SHGFI_ICON or SHGFI_SYSICONINDEX value, the return value is the handle of the system image list that contains the large icon images. If the SHGFI_SMALLICON value is also included, the return value is the handle of the image list that contains the small icon images.

·If uFlags does not include SHGFI_EXETYPE, SHGFI_ICON, SHGFI_SYSICONINDEX, or SHGFI_SMALLICON, the return value is nonzero the function succeeds, or zero otherwise.


but on msdn


Quote:

Return Value

Returns a value whose meaning depends on the uFlags parameter.

If uFlags does not contain SHGFI_EXETYPE or SHGFI_SYSICONINDEX, the return value is nonzero if successful, or zero otherwise.

If uFlags contains the SHGFI_EXETYPE flag, the return value specifies the type of the executable file. It will be one of the following values.


Always worth to check msdn humm? Smile Very Happy
Post 21 Oct 2008, 13:30
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.