RE: Changing icon in ListView

new topic     » topic index » view thread      » older message » newer message

Thank you, Derek. Now it works!

I had also tried the procedure setLVItem(...) described in Win32Lib help 
but with no success.

Now I see that it differs from what you post now in the following:

Win32lib help: setLVItem(..., image, ...)

Your present post: setLVItem(..., image - 1, ...)

Should the first be substituted with the second one in help pages or is 
it valid for other purposes?


Julio C. Galaret Viera



Derek Parnell wrote:
> 
> 
> >Hi all,
> >
> >Searching how to change an icon at runtime in a listview, I found code 
> >posted long ago by Derek Parnell:
> >
> >procedure setLVImage(integer id, integer image, integer item)
> >    atom LVITEM
> >    LVITEM = struct_LVITEM( LVIF_IMAGE, item - 1, 0, 0, 0, 0, image, 0)
> >    RC = sendMessage(id, LVM_SETITEM, 0, LVITEM)
> >    release_mem(LVITEM)
> >end procedure 
> >
> >
> >Though I have tried everything, including comparing this code with MS 
> >help for ListView controls (and everything seems to be fine), I haven't 
> >been able to make it work.
> >
> >Say, for instance, this simple code:
> >
> >150, 130, 80, 25, 0, 0)
> >
> >integer xIcon1, xIcon2, idx
> >
> >xIcon1 = addIcon(extractIcon("icon01.ico"))
> >xIcon2 = addIcon(extractIcon("icon02.ico"))
> >
> >idx = addLVItem(MyList, xIcon1, "Hello")
> >
> >procedure setLVImage(integer id, integer image, integer item)
> >    atom LVITEM
> >    object RC
> >    LVITEM = struct_LVITEM( LVIF_IMAGE, item - 1, 0, 0, 0, 0, image, 0)
> >    RC = sendMessage(id, LVM_SETITEM, 0, LVITEM)
> >    release_mem(LVITEM)
> >end procedure 
> >
> >procedure onClick_MyButton(integer self, integer event, sequence parms)
> >    setLVImage(MyList, xIcon2, idx)
> >end procedure
> >setHandler (MyButton, w32HClick, routine_id("onClick_MyButton"))
> >
> >WinMain(Main, Normal)
> >
> >It simply fails to work. What am I doing wrong?
> 
> You are using my untested code blink
> 
> Try this instead.
> 
> ---------------
> without warning
> include win32lib.ew
> 
> 
> atom xIcon1, xIcon2, idx
> xIcon1 = addIcon(extractIcon("icon01.ico"))
> xIcon2 = addIcon(extractIcon("icon02.ico"))
> 
> idx = addLVItem(MyList, xIcon1, "Hello")
> 
> procedure onClick_MyButton(integer self, integer event, sequence parms) 
>     setLVItem(MyList, LVIF_IMAGE, idx , 0, 0, 0,  0,         xIcon2-1, 0)    
>     
>     setLVItem(MyList, LVIF_TEXT,  idx , 0, 0, 0,  "Goodbye", 0,        0)    
>     
> end procedure
> setHandler (MyButton, w32HClick, routine_id("onClick_MyButton"))
> 
> WinMain(Main, Normal)
> ------------------------
> 
> Which means that the setLVImage routine should really be ...
> 
> procedure setLVImage(integer id, integer image, integer item)
>     atom LVITEM
>     object RC
>     LVITEM = struct_LVITEM( LVIF_IMAGE, item , 0, 0, 0, 0, image-1, 0)
>     RC = sendMessage(id, LVM_SETITEM, 0, LVITEM)
>     release_mem(LVITEM)
> end procedure 
> 
> -- 
> Derek
> 
>

new topic     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu