Page 1 of 2

SetGadgetItemIcon()

Posted: Fri Sep 01, 2006 8:54 pm
by Trond
Wished for: SetGadgetItemIcon(). The name is self explanatory.

Posted: Sun Sep 10, 2006 3:18 am
by Tranquil
I have problems understanding this command. Where do you want to place these icons? In ButtonGadgets?

In this case its not possible due to a windows limitation. You habe to draw you buttons as images if you need it.

Posted: Sun Sep 10, 2006 8:00 am
by thamarok
As far as I know, you can put icons in items of a ComboBoxGadget, but this needs pretty much Win32 API code and I am not an expert in this. (Mainly interested in Linux applications :P )

Posted: Sun Sep 10, 2006 8:03 am
by Trond
It's for ListIconGadgets.

Posted: Sun Sep 10, 2006 10:50 pm
by Tranquil
thamarok wrote:As far as I know, you can put icons in items of a ComboBoxGadget, but this needs pretty much Win32 API code and I am not an expert in this. (Mainly interested in Linux applications :P )
You can, thats right, but then you need to ownerdraw this controls. this will cause curruptions if the user uses skins.

Posted: Mon Sep 11, 2006 12:59 pm
by thamarok
Tranquil wrote:
thamarok wrote:As far as I know, you can put icons in items of a ComboBoxGadget, but this needs pretty much Win32 API code and I am not an expert in this. (Mainly interested in Linux applications :P )
You can, thats right, but then you need to ownerdraw this controls. this will cause curruptions if the user uses skins.
Made a quick search on Google with "combobox item icon" and ended up with a site from MSDN. The site said that you can use a ComboBoxEx control to avoid ownerdrawing the ComboBox to have icons. According to this, you need to use ComboBoxEx controls to make your application work with people who use skinning applications such as WindowBlinds.

Posted: Mon Sep 11, 2006 1:39 pm
by Fangbeast
Trond wrote:It's for ListIconGadgets.
Until the command is implemented, did you find alternate code in the forum to do this (Like I did) or do you want some?

Posted: Wed Sep 20, 2006 5:59 am
by Anden
Nope, didn't find anything, but definitely want something :-)

Share your secret, where is it?

Her you go. From my original query

Posted: Wed Sep 20, 2006 7:01 am
by Fangbeast
See if this thread helps. I can refine it further if not.

http://www.purebasic.fr/english/viewtop ... changeicon

Posted: Fri Sep 22, 2006 10:09 am
by Anden
Thanks so far, added the #LVM_SETEXTENDEDLISTVIEWSTYLE to my code (which was somehow missing before :-))

Trying to change the icon in column 0 (the one that PB is able to set initially), so could you refine, please?

Posted: Fri Sep 22, 2006 10:41 am
by Fangbeast
Anden wrote:Thanks so far, added the #LVM_SETEXTENDEDLISTVIEWSTYLE to my code (which was somehow missing before :-))

Trying to change the icon in column 0 (the one that PB is able to set initially), so could you refine, please?

First, lets add the image constants for the icons we want to use in any collumn of the ListIconGadget. These are the ones I use for my appointment manager.


Enumeration
#Image_appointment_date
#Image_appointment_time
#Image_appointment_category
#Image_appointment_notes
EndEnumeration


Grab the images that you want to use from the data section to memory for use with the ChangeIcon command


CatchImage(#Image_appointment_date, ?_PTK_appointment_date)
CatchImage(#Image_appointment_time, ?_PTK_appointment_time)
CatchImage(#Image_appointment_category, ?_PTK_appointment_category)
CatchImage(#Image_appointment_notes, ?_PTK_appointment_notes)


I include all the icons in the datasection, stored in the executable so I don't have to have many loose files hanging around.


DataSection
_PTK_appointment_date : IncludeBinary "Images\date.ico"
_PTK_appointment_time : IncludeBinary "Images\time.ico"
_PTK_appointment_category : IncludeBinary "Images\category.ico"
_PTK_appointment_notes : IncludeBinary "Images\notes.ico"
EndDataSection


When you open your program window, you must create a new image list to replace the standard one that's in your ListIconGadget by default.


hImgList.l = ImageList_Create_(16, 16, #ILC_MASK | #ILC_COLOR32, 0, 4)


hImgList.l = the handle to your image list.


The last number; 4; is the number of icons that you are going to be using with the ListIconGadget


dateicon.l = ImageList_ReplaceIcon_(hImgList, -1, UseImage(#Image_appointment_date))
timeicon.l = ImageList_ReplaceIcon_(hImgList, -1, UseImage(#Image_appointment_time))
categoryicon.l = ImageList_ReplaceIcon_(hImgList, -1, UseImage(#Image_appointment_category))
notesicon.l = ImageList_ReplaceIcon_(hImgList, -1, UseImage(#Image_appointment_notes))


Assign your image constants to easy to remember variables. -1 means that you are adding to the image list in no particular order.


SendMessage_(GadgetID(#Gadget_appointment_appointments), #LVM_SETIMAGELIST,#LVSIL_SMALL, hImgList)


Now set your new image list to the ListIconGadget that you want to use it on,


ImageList_SetBkColor_(hImgList, #CLR_NONE)


Set the backgropund colour of the imagelist to be see through (transparent) so icons don't show black borders.


SendMessage_(GadgetID(#Gadget_appointment_appointments), #LVM_SETEXTENDEDLISTVIEWSTYLE, #LVS_EX_SUBITEMIMAGES, #LVS_EX_SUBITEMIMAGES)


Now turn on extended listview style to actually allow changing icons in any collumn.


Procedure ChangeIcon(mygadget.l, myrow.l, mycolumn.l, myicon.l)
LVG.lv_item
LVG\mask = #LVIF_IMAGE | #LVIF_TEXT
LVG\iItem = myrow
LVG\iSubItem = mycolumn
changetext.s = GetGadgetItemText(mygadget, myrow, mycolumn)
LVG\pszText = @changetext.s
LVG\iImage = myicon
SendMessage_(GadgetID(mygadget), #LVM_SETITEM, 0, @LVG)
EndProcedure


This is the procedure to use to actually change the icon in any collumn. You are going to pass your gadget name, The row you are changing the icon on, the collumn you are changing the icon on and the icon name you declared before.


In my case it was:


ChangeIcon(#Gadget_appointment_appointments, 5, 1, dateicon.l)

You can declare image lists for any number of ListIcongadgets.

In your case it would be:


ChangeIcon(#My_ListIconGadget, 1, 0, dateicon.l)


Hope this helps. Hope I wasn't too simplistic but I'm not assuming anything on your behalf.

Posted: Fri Sep 22, 2006 7:01 pm
by Anden
Well thanks, there is no such thing like "too much information".

Had all that put together by myself (except the extended listview style as i already mentioned) which was quite a show-stopper of course.

This is my "simplified" ChangeIcon sub:

Procedure ChangeIcon(myicon.l, myrow.l)
LVG.lv_item
LVG\mask = #LVIF_IMAGE
LVG\iItem = myrow
LVG\iSubItem = 0
LVG\iImage = myicon
SendMessage_(mygadget_id, #LVM_SETITEM, 0, @LVG)
EndProcedure

Problem: It only shows the initial icon if set to that index, all other icons
are not "visible".

Maybe i've just messed up the indexing of the lv rows. Have to check that when i return from the weekend ...

Posted: Sat Sep 23, 2006 8:34 am
by Fangbeast
I had "Procedure ChangeIcon(mygadget.l, myrow.l, mycolumn.l, myicon.l)" because I often use 3 listicongadgets in my program and change icons on all of them.

And as for the index problem, same here. I kept an index counter when I filled a display and used changeicon after I incrememnted the counter and as a result, her icons wouldn't show.

I keep forgetting that listicongadgets are 0 based:):)

Posted: Wed Sep 27, 2006 5:48 am
by Anden
Did you try it with PB4 too?

It seems that the lv imagelist is somehow "locked" in V4:

SendMessage_(li_users_hnd, #LVM_SETIMAGELIST, #LVSIL_SMALL, lvil_hnd)

always returns 0 (SDK: Zero (Null) means "not successful")

Posted: Wed Sep 27, 2006 5:56 am
by Fangbeast
Anden wrote:Did you try it with PB4 too?

It seems that the lv imagelist is somehow "locked" in V4:

SendMessage_(li_users_hnd, #LVM_SETIMAGELIST, #LVSIL_SMALL, lvil_hnd)

always returns 0 (SDK: Zero (Null) means "not successful")
All my code is written in pb4 and works fine once I figured out what the heck I was doing wrong (and I do a lot wrong).

Download my library manager code from "Tips and Tricks" and have a play if you feel inclined to as it works fine here and I am changing icon lists in 2 listicongadgets