Common controls, with a manifested project, can actually display alpha bitmaps.
The attached sample includes a project that can be compiled and tested. However, if your IDE is manifested for common controls v6, then you can test it within the IDE.
There are some limitations:
1. This is a hack. The result is an API imagelist created and attached to a VB common controls ImageList with a simple CopyMemory call. Should the location for the CopyMemory statement ever change, the hack won't work obviously and is likely to crash. But location isn't likely to change if it hasn't changed in 20 years.
2. The imagelist Width,Height properties must be square. If not, some odd scaling occurs. The test project shows that.
3. The bitmaps assigned to the imagelist must be prescaled to the same dimensions of the imagelist. If not, that same crappy scaling occurs.
4. Any bitmap added to the imagelist must NOT be PARGB format (premultiplied pixels).
Oh, this works for both v5 & v6 of the ImageList control
Things we discover when we get bored and ask ourselves, "What if?"
edited: If you are actually considering using this hack, there is one cleanup scenario that needs to be addressed. If the API imagelist is attached but you have not added any images to it yet, VB won't destroy it. Only destroys it if images are added. In that scenario, destroy it manually. Here's an updated routine for the test project + new API. The best logic is to create the 32bpp imagelist just before you add the first image; don't create it just to have it around without a need to immediately add images.
Code:
Private Declare Function ImageList_Destroy Lib "comctl32.dll" (ByVal himl As Long) As Long
Private Sub Attach32bitImageList(ImageListObject As Control, _
ByVal Width As Long, ByVal Height As Long, _
Optional ByVal Flags As Long = 0)
' Optional hack to force ImageList to use 32bpp. If you opt for this, then
' 1. Passed ImageList must not have images already assigned
' 2. The passed Width,Height should be the same else really bad scaling occurs
' 3. Any images you add later must NOT be in PARGB format
' 4. Any images should be pre-scaled to ImageList Width,Height else bad scaling
' 32bpp ImageList accepts high quality icons and bitmaps with ARGB alpha channels
If ImageListObject Is Nothing Then Exit Sub
If TypeName(ImageListObject) <> "ImageList" Then Exit Sub
Dim hImageList As Long
Const OFFSET_HIMGLST = 24&
With ImageListObject
If .ListImages.Count = 0 Then
If .hImageList <> 0 Then ImageList_Destroy .hImageList
If Width > 0 And Height > 0 Then
.ImageWidth = Width: .ImageHeight = Height
hImageList = ImageList_Create(Width, Height, Flags Or &H20, 0, 0)
End If
CopyMemory ByVal ((ObjPtr(.object) Xor &H80000000) + OFFSET_HIMGLST) Xor &H80000000, hImageList, 4
End If
End With
End Sub
Last edited by LaVolpe; Feb 2nd, 2020 at 10:59 AM.
Insomnia is just a byproduct of, "It can't be done"