Author Topic: ImageCombo in VBA  (Read 4223 times)

0 Members and 1 Guest are viewing this topic.

Keith™

  • Villiage Idiot
  • Seagull
  • Posts: 16899
  • Superior Stupidity at its best
ImageCombo in VBA
« on: August 31, 2007, 09:48:02 PM »
Has anyone had any luck using an ImageCombo to display a color swatch on each successive line? I would like to duplicate the behavior of the "current color" combo box. If I wanted to create millions of swatches and load them into an imagelist, I could do that, but I want to write the color images dynamically.
Proud provider of opinion and arrogance since November 22, 2003 at 09:35:31 am
CadJockey Militia Field Marshal

Find me on https://parler.com @kblackie

hendie

  • Guest
Re: ImageCombo in VBA
« Reply #1 on: September 03, 2007, 05:22:09 AM »
Does it have to be an Image Combo ?
If you use a ListView instead you can set the colour of each line of text and end up with this instead...
RED
BLUE
GREEN
etc etc

Keith™

  • Villiage Idiot
  • Seagull
  • Posts: 16899
  • Superior Stupidity at its best
Re: ImageCombo in VBA
« Reply #2 on: September 03, 2007, 09:50:24 AM »
Does it have to be an Image Combo ?
If you use a ListView instead you can set the colour of each line of text and end up with this instead...
RED
BLUE
GREEN
etc etc

It doesn't necessarily have to be, but I was hoping to duplicate the default AutoCAD behavior.
Proud provider of opinion and arrogance since November 22, 2003 at 09:35:31 am
CadJockey Militia Field Marshal

Find me on https://parler.com @kblackie

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: ImageCombo in VBA
« Reply #3 on: September 03, 2007, 10:06:06 AM »
I'm not a VB'r , but ..
Does the cell have a background color
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

Keith™

  • Villiage Idiot
  • Seagull
  • Posts: 16899
  • Superior Stupidity at its best
Re: ImageCombo in VBA
« Reply #4 on: September 03, 2007, 10:21:55 AM »
The ImageCombo so far as I can tell, does not support multiple columns, if it did, I could use API calls to change the color of the cell.

For now, I have created swatches of all the basic AutoCAD colors and included them in an imagelist.

If I could find a way to create an image on the fly, then load it into the imagelist, that would be the ideal solution.
Proud provider of opinion and arrogance since November 22, 2003 at 09:35:31 am
CadJockey Militia Field Marshal

Find me on https://parler.com @kblackie

Keith™

  • Villiage Idiot
  • Seagull
  • Posts: 16899
  • Superior Stupidity at its best
Re: ImageCombo in VBA
« Reply #5 on: September 04, 2007, 08:50:10 AM »
I have figured out how to dynamically add an image to the ImageList and then to the ImageCombo, I have also figured out how to create a bitmap image dynamically, by filling a form with a specific color and then copying it into a bitmap structure. I still havn't managed to fill the image structure with a specific color without having a control already visible.

Anyway, I think the resolution would be to fill a bitmap structure held in memory with a specific color.
Proud provider of opinion and arrogance since November 22, 2003 at 09:35:31 am
CadJockey Militia Field Marshal

Find me on https://parler.com @kblackie

Dave R

  • Guest
Re: ImageCombo in VBA
« Reply #6 on: September 06, 2007, 08:12:39 AM »
Did a quick search on the Xtreme VB Talk web site. Maybe something like this?

Code: [Select]
Type GUID
  Data1 As Long
  Data2 As Integer
  Data3 As Integer
  Data4(7) As Byte
End Type

Private Declare Function CreateStreamOnHGlobal Lib "ole32.dll" (ByRef hGlobal As Any, ByVal fDeleteOnResume As Long, ByRef ppstr As Any) As Long
Private Declare Function OleLoadPicture Lib "olepro32.dll" (ByVal lpStream As IUnknown, ByVal lSize As Long, ByVal fRunMode As Long, ByRef riid As GUID, ByRef lplpObj As Any) As Long
Private Declare Function CLSIDFromString Lib "ole32.dll" (ByVal lpsz As Long, ByRef pclsid As GUID) As Long

' HKEY_CLASSES_ROOT\Interface\{7BF80980-BF32-101A-8BBB-00AA00300CAB} = IPicture
Private Const SIPICTURE As String = "{7BF80980-BF32-101A-8BBB-00AA00300CAB}"

' convert a byte array to IPicture
Public Function PictureFromRes(ByRef b() As Byte) As IPicture
  On Error GoTo errorhandler
 
  Dim istrm As IUnknown
  Dim tGuid As GUID
 
  If Not CreateStreamOnHGlobal(b(LBound(b)), False, istrm) Then
    CLSIDFromString StrPtr(SIPICTURE), tGuid
    OleLoadPicture istrm, UBound(b) - LBound(b) + 1, False, tGuid, PictureFromRes
  End If
 
  Set istrm = Nothing
  Exit Function
errorhandler:
  Debug.Print "Could not convert to IPicture!"
End Function

Keith™

  • Villiage Idiot
  • Seagull
  • Posts: 16899
  • Superior Stupidity at its best
Re: ImageCombo in VBA
« Reply #7 on: September 06, 2007, 08:23:14 AM »
I'll have to look at that a little closer ... quite interesting ...
Proud provider of opinion and arrogance since November 22, 2003 at 09:35:31 am
CadJockey Militia Field Marshal

Find me on https://parler.com @kblackie