SetGadgetItemIcon()
SetGadgetItemIcon()
Wished for: SetGadgetItemIcon(). The name is self explanatory.
You can, thats right, but then you need to ownerdraw this controls. this will cause curruptions if the user uses skins.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)
Tranquil
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.Tranquil wrote:You can, thats right, but then you need to ownerdraw this controls. this will cause curruptions if the user uses skins.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)
- Fangbeast
- PureBasic Protozoa
- Posts: 4789
- Joined: Fri Apr 25, 2003 3:08 pm
- Location: Not Sydney!!! (Bad water, no goats)
Her you go. From my original query
See if this thread helps. I can refine it further if not.
http://www.purebasic.fr/english/viewtop ... changeicon
http://www.purebasic.fr/english/viewtop ... changeicon
- Fangbeast
- PureBasic Protozoa
- Posts: 4789
- Joined: Fri Apr 25, 2003 3:08 pm
- Location: Not Sydney!!! (Bad water, no goats)
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.
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 ...
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 ...
- Fangbeast
- PureBasic Protozoa
- Posts: 4789
- Joined: Fri Apr 25, 2003 3:08 pm
- Location: Not Sydney!!! (Bad water, no goats)
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:):)
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:):)
- Fangbeast
- PureBasic Protozoa
- Posts: 4789
- Joined: Fri Apr 25, 2003 3:08 pm
- Location: Not Sydney!!! (Bad water, no goats)
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).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")
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