How to add image to combo box from .res?

The place for threads about TimoSoft ComboListBoxControls
Post Reply
ufo973
Lieutenant
Posts: 12
Joined: 09 Aug 2012, 22:45

How to add image to combo box from .res?

Post by ufo973 »

How can i add an image to combo box from resource file? please provide an example code.
Thanks alot.
User avatar
TiKu
Administrator
Administrator
Posts: 832
Joined: 28 Sep 2004, 21:10
Location: München
Contact:

Re: How to add image to combo box from .res?

Post by TiKu »

You need to load the image into an image list and then assign this image list to the control. The Events sample demonstrates how to assign an image list to the control.
Crunching for Fab36_Folding-Division at Folding@Home. Join Fab36/Fab30! - Folding@Home and BOINC
Boycott DRM! Boycott HDCP!
ufo973
Lieutenant
Posts: 12
Joined: 09 Aug 2012, 22:45

Re: How to add image to combo box from .res?

Post by ufo973 »

TiKu wrote:You need to load the image into an image list and then assign this image list to the control. The Events sample demonstrates how to assign an image list to the control.
The Events sample demonstrates how to load images from a directory to the image list.

Code: Select all

hImgLst = ImageList_Create(16, 16, IIf(bComctl32Version600OrNewer, ILC_COLOR32, ILC_COLOR24) Or ILC_MASK, 14, 0)
  If Right$(App.Path, 3) = "bin" Then
    iconsDir = App.Path & "\..\res\"
  Else
    iconsDir = App.Path & "\res\"
  End If
  iconsDir = iconsDir & "16x16" & IIf(bComctl32Version600OrNewer, "x32bpp\", "x8bpp\")
  iconPath = Dir$(iconsDir & "*.ico")
  While iconPath <> ""
    hIcon = LoadImage(0, StrPtr(iconsDir & iconPath), IMAGE_ICON, 16, 16, LR_LOADFROMFILE Or LR_DEFAULTSIZE)
    If hIcon Then
      ImageList_AddIcon hImgLst, hIcon
      DestroyIcon hIcon
    End If
    iconPath = Dir$
  Wend
but i want to know how to load images from a resource file (ex: icons.res) to an image list.
Can you please provide me the code to do so.
User avatar
TiKu
Administrator
Administrator
Posts: 832
Joined: 28 Sep 2004, 21:10
Location: München
Contact:

Re: How to add image to combo box from .res?

Post by TiKu »

I wrote that it demonstrates how to assign an image list to the control.

Loading images from resources into an image list is a common task and you'll find code for it on www.planetsourcecode.com. Actually it doesn't matter that you want to load the images into an image list. Have a look at the documentation of the LoadImage function. It can be used to load images from resources instead of files. If the resources contain one bitmap with all the icons in it, you can also use ImageList_LoadImage.
Crunching for Fab36_Folding-Division at Folding@Home. Join Fab36/Fab30! - Folding@Home and BOINC
Boycott DRM! Boycott HDCP!
Post Reply