Sign in to follow this  
Followers 0
koiron

Combo items with icons?

5 posts in this topic

I'm trying to make a combo drop down with icons for each item like that of the attached image. Is this possible with autoit?

1.bmp


-Koiron

Share this post


Link to post
Share on other sites



I'm trying to make a combo drop down with icons for each item like that of the attached image. Is this possible with autoit?

Currently I don't think it does

That would be something for Holger to look at.


SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Here we are (was just a test for my PENetwork-project for language settings), modified it a litte bit:

Only "ANSI"-version here...

#include <GUIConstants.au3>
Global Const $WM_SETFONT                        = 0x0030

Global Const $CBEM_INSERTITEMA                  = $WM_USER + 1
Global Const $CBEM_SETIMAGELIST                 = $WM_USER + 2
Global Const $CBEM_GETITEMA                     = $WM_USER + 4
Global Const $CBEM_SETITEMA                     = $WM_USER + 5
Global Const $CBEIF_TEXT                        = 0x00000001
Global Const $CBEIF_IMAGE                       = 0x00000002
Global Const $CBEIF_SELECTEDIMAGE               = 0x00000004
                                                                                            
Global Const $sCOMBOBOXEXITEM                   = "uint;" & _ ; Mask
                                                    "int;" & _ ; Item index (0 based)
                                                    "ptr;" & _ ; Item text
                                                    "int;" & _ ; Text length
                                                    "int;" & _ ; Image index in image list
                                                    "int;" & _ ; Selected image index
                                                    "int;" & _ ; Overlay image index
                                                    "int;" & _ ; Indent spaces
                                                    "dword" ; lParam

Global Const $ILC_MASK              = 0x0001
Global Const $ILC_COLOR32           = 0x0020

                                                    
Dim $hGlobalFont    = 0

$hMainGUI = GUICreate("Test")

$hComboLang = MyGUICtrlCreateComboEx(5, 5, 120, 120, $hMainGUI, $CBS_DROPDOWNLIST)
$hImageList = ImageList_Create(16, 16, BitOr($ILC_MASK, $ILC_COLOR32), 0, 1)
$res = DllCall("user32.dll", "int", "SendMessage", "hwnd", $hComboLang, "int", $CBEM_SETIMAGELIST, "int", 0, "hwnd", $hImageList)

$stIcon = DllStructCreate("dword")

For $i = 0 To 50
    ExtractIconEx("shell32.dll", $i, 0, DllStructGetPtr($stIcon), 1)
    
    $nImage = ImageList_AddIcon($hImageList, DllStructGetData($stIcon, 1))
    
    MyGUICtrlCreateComboExItem($i, $hComboLang, -1, $nImage)
Next

GUISetState()

While 1
    $Msg = GUIGetMsg()
    If $Msg = $GUI_EVENT_CLOSE Then ExitLoop
WEnd

ImageList_Destroy($hImageList)

Exit


Func MyGUICtrlCreateComboEx($nX, $nY, $nW, $nH, $hParent, $nStyle = 0, $nExStyle = 0)
    Local $nID = GUICtrlCreateDummy()
    
    $hCtrl = CreateWindowEx($nExStyle, "ComboBoxEx32", "", BitOr($nStyle, $WS_VISIBLE, $WS_CHILD), $nX, $nY, $nW, $nH, $hParent, $nID, 0, 0)
    
    SetFont($hCtrl)                                     
    
    Return $hCtrl
EndFunc


Func MyGUICtrlCreateComboExItem($sItemText, $hComboEx, $nIndex = -1, $nImage = 0)
    Local $stCBItem = DllStructCreate($sCOMBOBOXEXITEM)
    DllStructSetData($stCBItem, 1, BitOr($CBEIF_TEXT, $CBEIF_IMAGE, $CBEIF_SELECTEDIMAGE))
    DllStructSetData($stCBItem, 2, $nIndex)
    
    Local $stString = DllStructCreate("char[" & StringLen($sItemText) + 1 & "]")
    DllStructSetData($stString, 1, $sItemText)
    
    DllStructSetData($stCBItem, 3, DllStructGetPtr($stString))
    DllStructSetData($stCBItem, 5, $nImage)
    DllStructSetData($stCBItem, 6, $nImage)
    
    Local $nNewIndex = SendMessage($hComboEx, $CBEM_INSERTITEMA, 0, DllStructGetPtr($stCBItem))

    Return $nNewIndex
EndFunc


Func CreateWindowEx($nExStyle, $sClassName, $sWndName, $nStyle, $nX, $nY, $nW, $nH, $hWndParent, $hMenu, $hInstance, $pParam)
    Local $nResult = DllCall("user32.dll", "hwnd", "CreateWindowEx", _
                                                    "int", $nExStyle, _
                                                    "str", $sClassName, _
                                                    "str", $sWndName, _
                                                    "int", $nStyle, _
                                                    "int", $nX, _
                                                    "int", $nY, _
                                                    "int", $nW, _
                                                    "int", $nH, _
                                                    "hwnd", $hWndParent, _
                                                    "hwnd", $hMenu, _
                                                    "hwnd", $hInstance, _
                                                    "ptr", $pParam)                                                 
    Return $nResult[0]
EndFunc


Func SendMessage($hWnd, $Msg, $wParam = 0, $lParam = 0)
    Local $nResult = DllCall("user32.dll", "int", "SendMessage", _
                                                 "hwnd", $hWnd, _
                                                 "int", $Msg, _
                                                 "int", $wParam, _
                                                 "int", $lParam)
    Return $nResult[0]
EndFunc


Func SetFont($hWnd)
    If $hGlobalFont = 0 Then 
        $hGlobalFont = DllCall("gdi32.dll", "hwnd", "GetStockObject", "int", 17); Get "DEFAULT_GUI_FONT"
        ;
        ;    -> font numbers can be :
        ;    OEM_FIXED_FONT      10
        ;    ANSI_FIXED_FONT     11
        ;    ANSI_VAR_FONT       12
        ;    SYSTEM_FONT         13
        ;    DEVICE_DEFAULT_FONT 14
        ;    DEFAULT_PALETTE     15
        ;    SYSTEM_FIXED_FONT   16
        ;    DEFAULT_GUI_FONT    17
        ;
        ;
    
        $hGlobalFont = $hGlobalFont[0]
    EndIf
    
    SendMessage($hWnd, $WM_SETFONT, $hGlobalFont, 1)
EndFunc


Func ImageList_Create($nImageWidth, $nImageHeight, $nFlags, $nInitial, $nGrow)
    Local $hImageList = DllCall('comctl32.dll', 'hwnd', 'ImageList_Create', _
                                                        'int', $nImageWidth, _
                                                        'int', $nImageHeight, _
                                                        'int', $nFlags, _
                                                        'int', $nInitial, _
                                                        'int', $nGrow)
    Return $hImageList[0]
EndFunc


Func ImageList_AddIcon($hIml, $hIcon)
    Local $nIndex = DllCall('comctl32.dll', 'int', 'ImageList_AddIcon', _
                                                    'hwnd', $hIml, _
                                                    'hwnd', $hIcon)
    Return $nIndex[0]
EndFunc


Func ImageList_Destroy($hIml)
    Local $bResult = DllCall('comctl32.dll', 'int', 'ImageList_Destroy', _
                                                    'hwnd', $hIml)
    Return $bResult[0]
EndFunc


Func ExtractIconEx($sIconFile, $nIconID, $ptrIconLarge, $ptrIconSmall, $nIcons)
    Local $nCount = DllCall('shell32.dll', 'int', 'ExtractIconEx', _
                                                'str', $sIconFile, _
                                                'int', $nIconID, _
                                                'ptr', $ptrIconLarge, _
                                                'ptr', $ptrIconSmall, _
                                                'int', $nIcons)
    Return $nCount[0]
EndFunc

Greets

Holger

Edited by Holger

Share this post


Link to post
Share on other sites

Here we are (was just a test for my PENetwork-project for language settings), modified it a litte bit:

Only "ANSI"-version here...

Greets

Holger

Hey man that's fantasctic!

Nice example for image lists.

Share this post


Link to post
Share on other sites
:) So based on your awesome example, Holger, dll's are needed to add icons to combo items. I'm gonna go stare at the help file for a few hours to understand this hah :) Thanks for your help!

-Koiron

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0