Jump to content

How to insert images in combobox


halbum2040
 Share

Recommended Posts

I wrote the code below to put an image png or jpg file in Combox. 

It doesn't work what part is wrong. 

I need help.

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Res_Fileversion=0.0.0.4
#AutoIt3Wrapper_Res_Fileversion_AutoIncrement=y
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
#include <GuiComboBoxEx.au3>
#include <GUIConstantsEx.au3>
#include <GuiImageList.au3>
#include <GDIPlus.au3>

Global $g_idMemo

Example()

Func Example()
    Local $hGUI, $hImage, $hCombo

    ; Create GUI
    $hGUI = GUICreate("ComboBoxEx Set Image List", 400, 300)
    $hCombo = _GUICtrlComboBoxEx_Create($hGUI, "", 2, 2, 394, 100)
    $g_idMemo = GUICtrlCreateEdit("", 2, 32, 396, 266, 0)
    GUICtrlSetFont($g_idMemo, 9, 400, 0, "Courier New")
    GUISetState(@SW_SHOW)

    Global $hImage = _GUIImageList_Create(16, 16, 5, 3)
    ;_GUIImageList_AddIcon($hImage, @SystemDir & "\shell32.dll", 110)
    ;_GUIImageList_AddIcon($hImage, @SystemDir & "\shell32.dll", 131)
    ;_GUIImageList_AddIcon($hImage, @SystemDir & "\shell32.dll", 165)
    ;_GUIImageList_AddIcon($hImage, @SystemDir & "\shell32.dll", 168)
    ;_GUIImageList_AddIcon($hImage, @SystemDir & "\shell32.dll", 137)
    ;_GUIImageList_AddIcon($hImage, @SystemDir & "\shell32.dll", 146)
    ;_GUIImageList_Add($hImage, _GUICtrlComboBoxEx_CreateSolidBitMap($hCombo, 0xFF0000, 16, 16))
    ;_GUIImageList_Add($hImage, _GUICtrlComboBoxEx_CreateSolidBitMap($hCombo, 0x00FF00, 16, 16))
    ;_GUIImageList_Add($hImage, _GUICtrlComboBoxEx_CreateSolidBitMap($hCombo, 0x0000FF, 16, 16))

    SetComboImage(@ScriptDir & "\Country\01.png")

    ;Set Image List
    Local $hPrevlist = _GUICtrlComboBoxEx_SetImageList($hCombo, $hImage)
    MemoWrite("Previous ImageList Handle: " & $hPrevlist & _
            " IsPtr = " & IsPtr($hPrevlist) & " IsHWnd = " & IsHWnd($hPrevlist))

    For $x = 0 To 8
        _GUICtrlComboBoxEx_AddString($hCombo, StringFormat("%03d : string", Random(1, 100, 1)), $x, $x)
    Next

    ;Get Image List
    MemoWrite("ImageList Handle: " & _GUICtrlComboBoxEx_GetImageList($hCombo))

    Do
    Until GUIGetMsg() = $GUI_EVENT_CLOSE

EndFunc   ;==>Example

; Write a line to the memo control
Func MemoWrite($sMessage)
    GUICtrlSetData($g_idMemo, $sMessage & @CRLF, 1)
EndFunc   ;==>MemoWrite

Func SetComboImage($iFilename) 

    
    Local $hPng = _GDIPlus_ImageLoadFromFile($iFilename)

    Local $hBmp = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hPng)

    _GUIImageList_Add($hImage, $hBmp)

EndFunc

 

Link to comment
Share on other sites

@dmob Thanks for the advice. 

By the way

I initialized GDI, but the image still does not enter the combobox. 

I don't know what was wrong.

 

; Create GUI
    $hGUI = GUICreate("ComboBoxEx Set Image List", 400, 300)
    $hCombo = _GUICtrlComboBoxEx_Create($hGUI, "", 2, 2, 394, 100)
    $g_idMemo = GUICtrlCreateEdit("", 2, 32, 396, 266, 0)
    GUICtrlSetFont($g_idMemo, 9, 400, 0, "Courier New")
    GUISetState(@SW_SHOW)

    _GDIPlus_Startup()

    Global $hImage = _GUIImageList_Create(16, 16, 5, 3)
    ;_GUIImageList_AddIcon($hImage, @SystemDir & "\shell32.dll", 110)
    ;_GUIImageList_AddIcon($hImage, @SystemDir & "\shell32.dll", 131)
    ;_GUIImageList_AddIcon($hImage, @SystemDir & "\shell32.dll", 165)
    ;_GUIImageList_AddIcon($hImage, @SystemDir & "\shell32.dll", 168)
    ;_GUIImageList_AddIcon($hImage, @SystemDir & "\shell32.dll", 137)
    ;_GUIImageList_AddIcon($hImage, @SystemDir & "\shell32.dll", 146)
    ;_GUIImageList_Add($hImage, _GUICtrlComboBoxEx_CreateSolidBitMap($hCombo, 0xFF0000, 16, 16))
    ;_GUIImageList_Add($hImage, _GUICtrlComboBoxEx_CreateSolidBitMap($hCombo, 0x00FF00, 16, 16))
    ;_GUIImageList_Add($hImage, _GUICtrlComboBoxEx_CreateSolidBitMap($hCombo, 0x0000FF, 16, 16))


    SetComboImage(@ScriptDir & "\Country\01.png")

 

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...