The new vbAccelerator Site - more VB and .NET Code and Controls
Source Code
2 Common Controls Library &nbsp

vbAccelerator Image List Control and Class v1.4

Use COMCTL32.DLL directly to create an ImageList and take full control of icons at all colour depths and sizes.



NOTE: this code has been superceded by the version at the new site.




Image List Control Property Page

Download Code
VB5 code VB5 Control Binary (33kb) VB6 code VB6 Control Binary (33kb)
VB5 code VB5 Demonstration Project (56kb) VB6 code VB6 Demonstration Project (56kb)
VB5 code VB5 Full Source Code (113kb) VB6 code VB6 Full Source Code (113kb)
VB5 code ImageList Class Example, VB5 or VB6 (55kb)

UpdatedUpdated! v1.4 21 March 2000
&nbsp Posted VB6 version. &nbsp
&nbsp Fixed bugs in Images Property Page: when two images were swapped, the keys did not move with them and sometimes the key was not saved for images. Also put the images into their own control so you can navigate them with the cursor keys. &nbsp
&nbsp Fixed control bug - attempt to refer to the first item in the ImageList by key caused a subscript out of range error. &nbsp
UpdatedUpdated! v1.2 21 March 1999
&nbsp When loading an icon, the control now chooses the icon resource with the size most closely matching the image list size. Previously, the control always picked the resource at the default system icon size if that existed - causing the stretching problem the control was supposed to solve! &nbsp
&nbsp Multiple files can now be selected together when adding images. A stupid omission from the last version! &nbsp
&nbsp Image Keys can now be set up in the property page and are persisted in the control's PropertyBag. The control's property page also has a toggle to allow keys to be automatically generated based on the filenames being added - very useful! &nbsp
&nbsp Allow load of .GIF, .CUR and .ANI files as well as .BMP and .ICO. For animated cursors, you can choose whether to load just the first frame or import all frames. &nbsp
&nbsp When adding a bitmap, the control can now automatically determine the transparent colour from the top-left hand pixel of the image. However, you can still set it manually, although now there is the assistance of a colour picker Common Dialog to do it rather than having to remember the RGB values yourself! &nbsp
&nbsp Bugs causing the control to crash when buttons pressed in the property page at an unexpected point and also to place the images in the wrong order in the control have all been removed. &nbsp
&nbsp Resource leak when adding icons fixed. (Call DestroyIcon or DestroyCursor as appropriate rather than calling DeleteObject) &nbsp
&nbsp Source Code Note &nbsp
&nbsp This OCX is a binary compatible component which works with all other samples. If you compile your own copy of this OCX yourself please make sure you change the name. See disclaimer and license for more details. &nbsp

Overview
As a number of my controls require image list support (Rebar and Toolbar control, Tab Control, S-Grid, Icon Menu Control, ActiveX Popup Menu DLL, Owner Drawn ComboEx Control and the Owner Drawn Combo and List box Control), it was about time I provided an Image List control to support them, so you don't have to distribute 590kb of COMCTL32.OCX just to get images in your app.
Well here it is. I completed the control, and it has a full design-time interface (see above) with a number of new features which you will probably find very useful if you're used to the MS version. But, having done it I was alarmed to discover than my OCX was 131kb! The problem is with this control is you need nice serialisation code and property page support otherwise it isn't any use. But the penalty of this is that you are bound to end up with something heavier than if you go the code-only route.
Another option if you are interested in lean, serious code is to get all the functionality from a class, which will add just 30kb of code to your project. There's no subclassing or hooky API calls, so there's no danger of making your project unstable in the IDE by adding it. You can load all the icons in one go from a picture strip containing all the images in series (stored as a file or a resource bitmap). The control version lets you create a picture strip and save it and then you ditch the control and use the class instead. A bit of an expensive use of a control, but anyway...
Note that this control isn't a direct replacement for the Common Controls version. You can't directly attach it to a TreeView or ListView etc and get that to work. It does, however, directly attach to all the vbAccelerator controls that require an ImageList (note that they also support the MS ImageList). Just pass the return value of the hIml property to the relevant ImageList method.

Features
The features of this image list control are:
  • Add all images at the same time from a picture containing a strip of images. Also, the image list has a method which creates a picture strip from icons added in. Images can be loaded easily from files, resources, bitmap handles or VB Picture objects.
  • No icon size/colour depth restriction. If you have icons that are 24x24 in millions of colours, the ImageList will load them, unlike the VB/COM StdPicture object which first stretches them to 32x32, reduces the colour depth to 16 colours and then squashes them back to 24x24!
    Updated! the previous version could fail to pick the correct icon size from multi-resource icons, leading to stretching or squashing. The closest size match is now used.
  • Specify the colour depth the ImageList should run in. Lower colour depths mean less resource usage, higher depths mean better icons!
  • At design time, you can clear the images, or change their order without having to add/ remove each one separately.
  • Image draw method supports drawing icons in normal, selected, dithered with specified colour and disabled modes.
  • Swap or make copies of images in the image list.
  • Get a real API hIcon from any image in the image list, regardless of what format it was originally added in. This function will make for a great icon editor! Just remember to call DestroyIcon on the hIcon returned when you've finished with it...
  • New! Add .CUR (cursor) and .ANI (animated cursor) files to the Image List. If you import an animated cursor, you get the option of importing all frames or just the first one.
  • New! A much better user interface for the control version.
    1. Set up keys at design time - optionally you can have the key automatically set based on the filename of the image you are adding, which can be a great time saver.
    2. Add multiple files from the File Open dialog.
    3. Choose whether the control automatically determines the transparent colour of bitmaps you are adding, or choose the transparent colour using a Colour Picker dialog (rather than having to remember the correct RGB value..)
To get a feel for the methods and use of the image list, download one of the sample files and check it out.

Documentation
Documentation for the Image List control is available in RTF format. This documentation was created with the Active X Documenter, which is also available for download.
Click here to download/view the Image List control method documentation



TopBack to top

Source Code - What We're About!Back to Source Code

&nbsp

AboutContributeSend FeedbackPrivacy

Copyright 1998-2000, Steve McMahon ( steve@vbaccelerator.com). All Rights Reserved.
Last updated: 18 February 1999