Page 1 of 1

How to add image to combo box from .res?

Posted: 09 Sep 2012, 16:14
by ufo973
How can i add an image to combo box from resource file? please provide an example code.
Thanks alot.

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

Posted: 09 Sep 2012, 18:39
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.

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

Posted: 09 Sep 2012, 23:37
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.

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

Posted: 10 Sep 2012, 05:29
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.