Jump to content

How to insert images in combobox


halbum2040
 Share

Recommended Posts

I would like to know how to insert image jpg or png format into combobox. 

The code below is how to extract an icon from a dll and insert a colored icon, 

but I want to know how to put a large sized image into a combobox.

 

#include <GuiComboBoxEx.au3>
#include <GUIConstantsEx.au3>
#include <GuiImageList.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)

    $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))
    ;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

 

Link to comment
Share on other sites

Hi,

 

first setup image size in

_GUIImageList_Create()

Then load your png file with 

Local $hPng = _GDIPlus_ImageLoadFromFile("YourImg.png")

Then create a bitmap handle for your image

Local $hBmp = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hPng)

Then add the bitmap to your image list

_GUIImageList_Add($hImage, $hBmp)

For GDIPlus functions you need to include the UDF

#include <GDIPlus.au3>

 

 

 

Hope this helps!

 

BR funkey

Programming today is a race between software engineers striving to
build bigger and better idiot-proof programs, and the Universe
trying to produce bigger and better idiots.
So far, the Universe is winning.

Link to comment
Share on other sites

@funkey Thank you very much. 

As You told me, I implemented it as a function, but the image does not enter the combo box. 

I am curious what part is wrong.

 

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Res_Fileversion=0.0.0.1
#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

 

Edited by halbum2040
Link to comment
Share on other sites

Did you make it work? It may very well be the case that it's necessary to use an ownerdrawn ComboBox as demonstrated in this example.

Link to comment
Share on other sites

Yes sorry, i forgot to mention that _GDIPlus_Startup() is needed.

Programming today is a race between software engineers striving to
build bigger and better idiot-proof programs, and the Universe
trying to produce bigger and better idiots.
So far, the Universe is winning.

Link to comment
Share on other sites

@funkey Thanks for the advice. 

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

I don't know what was wrong.

 

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Res_Fileversion=0.0.0.12
#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)

    _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")

    ;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) ;콤보박스에 이미지를 추가하는 함수

    ;_GUIImageList_Create() 실행이 선행되어야 한다.

    Local $hPng = _GDIPlus_ImageLoadFromFile($iFilename)

    Local $hBmp = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hPng)

    _GUIImageList_Add($hImage, $hBmp)

EndFunc

 

Link to comment
Share on other sites

I don't know how big your picture is, but you made a list with only 16x16 pixels. Here a working example:

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Res_Fileversion=0.0.0.12
#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", 1000, 800)
    $hCombo = _GUICtrlComboBoxEx_Create($hGUI, "", 2, 2, 994, 500)
    $g_idMemo = GUICtrlCreateEdit("", 2, 332, 396, 266, 0)
    GUICtrlSetFont($g_idMemo, 9, 400, 0, "Courier New")
    GUISetState(@SW_SHOW)

    _GDIPlus_Startup()


    InetGet("https://upload.wikimedia.org/wikipedia/commons/thumb/e/e8/World_blank_map_countries.PNG/320px-World_blank_map_countries.PNG", "World.png")

    $hImage = _GUIImageList_Create(320, 140, 5, 3, 1)

    SetComboImage($hImage, @ScriptDir & "\World.png")
    SetComboImage($hImage, @ScriptDir & "\World.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 1
        _GUICtrlComboBoxEx_AddString($hCombo, StringFormat("%03d : Picture", $x + 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($hImage, $iFilename)
    Local $hPng = _GDIPlus_ImageLoadFromFile($iFilename)
;~  ConsoleWrite($hPng & @CRLF)
    Local $hBmp = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hPng)
;~  ConsoleWrite($hBmp & @CRLF)
    ConsoleWrite(_GUIImageList_Add($hImage, $hBmp) & @CRLF)
EndFunc

Programming today is a race between software engineers striving to
build bigger and better idiot-proof programs, and the Universe
trying to produce bigger and better idiots.
So far, the Universe is winning.

Link to comment
Share on other sites

I thought you wanted to put large images into combobox? You never said something about resizing, but this can be done also.

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Res_Fileversion=0.0.0.12
#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", 1000, 800)
    $hCombo = _GUICtrlComboBoxEx_Create($hGUI, "", 2, 2, 994, 500)
    $g_idMemo = GUICtrlCreateEdit("", 2, 332, 396, 266, 0)
    GUICtrlSetFont($g_idMemo, 9, 400, 0, "Courier New")
    GUISetState(@SW_SHOW)

    _GDIPlus_Startup()


    InetGet("https://upload.wikimedia.org/wikipedia/commons/thumb/e/e8/World_blank_map_countries.PNG/320px-World_blank_map_countries.PNG", "World.png")

    $hImage = _GUIImageList_Create(100, 50, 5, 3, 1)

    SetComboImage($hImage, @ScriptDir & "\World.png")
    SetComboImage($hImage, @ScriptDir & "\World.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 1
        _GUICtrlComboBoxEx_AddString($hCombo, StringFormat("%03d : Picture", $x + 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($hImage, $iFilename)
    Local $hPng = _GDIPlus_ImageLoadFromFile($iFilename)
    Local $hBmp = _GDIPlus_ImageResize($hPng, 100, 50)
;~  ConsoleWrite($hPng & @CRLF)
    $hBmp = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hBmp)
    _WinAPI_DeleteObject($hPng) ;release GDI bitmap resource because not needed anymore
;~  ConsoleWrite($hBmp & @CRLF)
    ConsoleWrite(_GUIImageList_Add($hImage, $hBmp) & @CRLF)
EndFunc   ;==>SetComboImage

 

Programming today is a race between software engineers striving to
build bigger and better idiot-proof programs, and the Universe
trying to produce bigger and better idiots.
So far, the Universe is winning.

Link to comment
Share on other sites

Something like this:

Global $Country = "Austria"
ShellExecute("https://www.google.at/search?q="& $Country)

 

Programming today is a race between software engineers striving to
build bigger and better idiot-proof programs, and the Universe
trying to produce bigger and better idiots.
So far, the Universe is winning.

Link to comment
Share on other sites

@funkey Thanks. 

I applied the search method you gave me to the code. 

However, I wrote the code so that the index number is saved when the combo box is clicked, 

but it does not work well. I need help.

The basic operation routine thought you could know, so I wrote the variable name in Korean.

 

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

Global $g_idMemo
Global $Country
Global $iCombo 

Example()

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

    ; Create GUI
    $hGUI = GUICreate("ComboBoxEx Set Image List", 1000, 800)
    $hCombo = _GUICtrlComboBoxEx_Create($hGUI, "", 2, 2, 700, 500)
    $btnCountrySite = GUICtrlCreateButton("국가 검색", 710, 2, 100, 55)
    $g_idMemo = GUICtrlCreateEdit("", 2, 332, 396, 266, 0)
    GUICtrlSetFont($g_idMemo, 9, 400, 0, "Courier New")
    GUISetState(@SW_SHOW)

    _GDIPlus_Startup()

    ;InetGet("https://upload.wikimedia.org/wikipedia/commons/thumb/e/e8/World_blank_map_countries.PNG/320px-World_blank_map_countries.PNG", "World.png")

    ;$hImage = _GUIImageList_Create(320, 140, 5, 3, 1)
    $hImage = _GUIImageList_Create(100, 50, 5, 3, 1)

    SetComboImage($hImage, @ScriptDir & "\Country\01_노르웨이.png")
    SetComboImage($hImage, @ScriptDir & "\Country\02_덴마크.png")
    SetComboImage($hImage, @ScriptDir & "\Country\03_핀란드.png")
    ;SetComboImage($hImage, @ScriptDir & "\World.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 1
    ;    _GUICtrlComboBoxEx_AddString($hCombo, StringFormat("%03d : Picture", $x + 1), $x, $x)
    ;Next

    _GUICtrlComboBoxEx_AddString($hCombo, StringFormat("%03d : 노르웨이", 1), 0, 0)
    _GUICtrlComboBoxEx_AddString($hCombo, StringFormat("%03d : 덴마크", 2), 1, 1)
    _GUICtrlComboBoxEx_AddString($hCombo, StringFormat("%03d : 핀란드", 3), 2, 2)
    ;Get Image List
    MemoWrite("ImageList Handle: " & _GUICtrlComboBoxEx_GetImageList($hCombo))

    ;Do
    ;Until GUIGetMsg() = $GUI_EVENT_CLOSE

     While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
                ExitLoop

            Case $hCombo ;국가명 콤보박스를 클릭한 경우

                 $iCombo = _GUICtrlComboBoxEx_GetCurSel(GUICtrlGetHandle($hCombo))
                 MsgBox(4096, "", $iCombo)

            Case $btnCountrySite ;국가 검색 버튼을 눌렀을 경우

                ;$iCombo = _GUICtrlComboBoxEx_GetCurSel(GUICtrlGetHandle($hCombo))

                _GUICtrlComboBoxEx_GetItemText($hCombo,$iCombo,$Country) ;GUICtrlRead($hCombo) ; 국가 콤보 박스에서 국가명을 읽어온다.

                 ShellExecute("https://www.google.at/search?q="& $Country)


            EndSwitch
    WEnd

EndFunc   ;==>Example

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


Func SetComboImage($hImage, $iFilename)
    Local $hPng = _GDIPlus_ImageLoadFromFile($iFilename)
    Local $hBmp = _GDIPlus_ImageResize($hPng, 100, 50)
;~  ConsoleWrite($hPng & @CRLF)
    $hBmp = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hBmp)
    _WinAPI_DeleteObject($hPng) ;release GDI bitmap resource because not needed anymore
;~  ConsoleWrite($hBmp & @CRLF)
    ConsoleWrite(_GUIImageList_Add($hImage, $hBmp) & @CRLF)
EndFunc   ;==>SetComboImage

 

Link to comment
Share on other sites

You don't need GuiCtrlGetHandle($hCombo) because $hCombo is already a handle.

Programming today is a race between software engineers striving to
build bigger and better idiot-proof programs, and the Universe
trying to produce bigger and better idiots.
So far, the Universe is winning.

Link to comment
Share on other sites

@funkey I edited the source code as you told me and it works fine. 

Really thankful. 

However, the part that clicks the combo box does not work. 

This is the part.

Case $hCombo

                 $iCombo = _GUICtrlComboBoxEx_GetCurSel($hCombo)
                 MsgBox($MB_SYSTEMMODAL, "", $iCombo)

 

Link to comment
Share on other sites

You don't need this. Handle selected item in Button event.

This is because $hCombo is a real handle and GuiGetMsg handles only control IDs.

Programming today is a race between software engineers striving to
build bigger and better idiot-proof programs, and the Universe
trying to produce bigger and better idiots.
So far, the Universe is winning.

Link to comment
Share on other sites

@funkey Understand what was pointed out. 

However, my intention is that it would be nice if the combo box was clicked without pressing a button, 

and the text would be displayed immediately. 

For example, when you click a country in the combo box, the capital of that country is displayed immediately. 

Is there no way to implement it?

 

Link to comment
Share on other sites

OK, next try🙄

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

Global $Country
Global $iCombo
Global $hCombo

Example()

Func Example()
    Local $hGUI, $hImage

    ; Create GUI
    $hGUI = GUICreate("ComboBoxEx Set Image List", 1000, 800)
    $hCombo = _GUICtrlComboBoxEx_Create($hGUI, "", 2, 2, 700, 500)
    $btnCountrySite = GUICtrlCreateButton("국가 검색", 710, 2, 100, 55)

    GUISetState(@SW_SHOW)

    GUIRegisterMsg($WM_COMMAND, "WM_COMMAND")

    _GDIPlus_Startup()

    InetGet("https://upload.wikimedia.org/wikipedia/commons/thumb/e/e8/World_blank_map_countries.PNG/320px-World_blank_map_countries.PNG", "World.png")

    $hImage = _GUIImageList_Create(100, 50, 5, 3, 1)

;~     SetComboImage($hImage, @ScriptDir & "\Country\01_노르웨이.png")
;~     SetComboImage($hImage, @ScriptDir & "\Country\02_덴마크.png")
;~     SetComboImage($hImage, @ScriptDir & "\Country\03_핀란드.png")
    SetComboImage($hImage, @ScriptDir & "\World.png")
    SetComboImage($hImage, @ScriptDir & "\World.png")
    SetComboImage($hImage, @ScriptDir & "\World.png")

    ;Set Image List
    Local $hPrevlist = _GUICtrlComboBoxEx_SetImageList($hCombo, $hImage)

    _GUICtrlComboBoxEx_AddString($hCombo, StringFormat("%03d : 노르웨이", 1), 0, 0)
    _GUICtrlComboBoxEx_AddString($hCombo, StringFormat("%03d : 덴마크", 2), 1, 1)
    _GUICtrlComboBoxEx_AddString($hCombo, StringFormat("%03d : 핀란드", 3), 2, 2)


    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
                ExitLoop

            Case $btnCountrySite ;국가 검색 버튼을 눌렀을 경우

                $iCombo = _GUICtrlComboBoxEx_GetCurSel($hCombo)
                _GUICtrlComboBoxEx_GetItemText($hCombo, $iCombo, $Country)

                ShellExecute("https://www.google.at/search?q=" & StringTrimLeft($Country, 6))

        EndSwitch
    WEnd

EndFunc   ;==>Example

Func SetComboImage($hImage, $iFilename)
    Local $hPng = _GDIPlus_ImageLoadFromFile($iFilename)
    Local $hBmp = _GDIPlus_ImageResize($hPng, 100, 50)
    $hBmp = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hBmp)
    _WinAPI_DeleteObject($hPng) ;release GDI bitmap resource because not needed anymore
    ConsoleWrite(_GUIImageList_Add($hImage, $hBmp) & @CRLF)
EndFunc   ;==>SetComboImage

Func WM_COMMAND($hWnd, $iMsg, $wParam, $lParam)
    Local $nNotifyCode = _WinAPI_HiWord($wParam)
    Local $iId = _WinAPI_LoWord($wParam)
    Local $hCtrl = $lParam

    If $hCtrl = $hCombo And $nNotifyCode = $CBN_SELCHANGE Then ;
        $iCombo = _GUICtrlComboBoxEx_GetCurSel($hCombo)
        _GUICtrlComboBoxEx_GetItemText($hCombo, $iCombo, $Country)

        ShellExecute("https://www.google.at/search?q=" & StringTrimLeft($Country, 6))
        Return 0
    EndIf

    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_COMMAND

 

Could you please at least try to find out how things work? Google and the AutoIt documentation will always help you.

Programming today is a race between software engineers striving to
build bigger and better idiot-proof programs, and the Universe
trying to produce bigger and better idiots.
So far, the Universe is winning.

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...