Sign in to follow this  
Followers 0
picea892

combobox with icons from exe files

5 posts in this topic

Hi there

I have seen combo boxes populated with icons from DLLs all across the forum and can successfully do that myself. I'm not finding a way to populate the combo box with icons from an exe. Is it possible? The below script demonstrates populating with a DLL. I have commented out the line below which I believe should work for an exe. Why doesn't that line work in the same way?

Thanks in advance for the help.

Picea

#include <GuiComboBoxEx.au3>
#include <GuiImageList.au3>
#include <GUIConstants.au3>
#include <GuiConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GuiComboBox.au3>
#include <Misc.au3>

_Main()

Func _Main()
    Local $msg, $hGUI, $hImage, $combobox, $button, $sText
    
   ; Create GUI
    $hGUI = GUICreate("ComboBoxEx Get Text with Icon", 400, 300)
    $combobox = _GUICtrlComboBoxEx_Create($hGUI, "", 2, 2, 394, 100)
    GUISetState()

    $button = GUICtrlCreateButton("Get text", 50, 150, 100, 20)

    $hImage = _GUIImageList_Create(16, 16, 5, 3)
For $i = 1 To 4
     _GUICtrlComboBoxEx_AddString($combobox, "testing"&$i, 1, 1)
 Next

    For $x = 1 To 4
        _AddIcon($hImage, @SystemDir & "\shell32.dll", 5)
    ;_AddIcon($hImage, "C:\Windows\explorer.exe", -1)
    Next
      _GUICtrlComboBoxEx_SetImageList($combobox, $hImage)
    While 1
        $msg = GUIGetMsg()
        Switch $msg
            Case $GUI_EVENT_CLOSE
                ExitLoop
            Case $button
                _GUICtrlComboBoxEx_GetItemText($combobox, _GUICtrlComboBoxEx_GetCurSel($combobox), $sText)
                MsgBox(4160, "Information", "Edit Text: " & $sText)
        EndSwitch
    WEnd
EndFunc  ;==>_Main

Func _AddIcon($hWnd, $sFile, $iIndex = 0)
    Local $pIcon, $tIcon, $iResult, $hIcon
    $tIcon = DllStructCreate("int Icon")
    $pIcon = DllStructGetPtr($tIcon)
    $iResult = _WinAPI_ExtractIconEx ($sFile, $iIndex, $pIcon, 0, 1)
    $hIcon = DllStructGetData($tIcon, "Icon")
    $iResult = _GUIImageList_ReplaceIcon ($hWnd, -1, $hIcon)
 ;  _WinAPI_DestroyIcon($hIcon)
EndFunc

Share this post


Link to post
Share on other sites



#AutoIt3Wrapper_au3check_parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6
#include <GuiConstantsEx.au3>
#include <GuiListView.au3>
#include <GuiImageList.au3>
#include <WindowsConstants.au3>

Opt('MustDeclareVars', 1)

_Main()

Func _Main()
    Local $listview, $hImage
    Local $exStyles = BitOR($LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT, $LVS_EX_SUBITEMIMAGES)

    GUICreate("ImageList AddIcon", 400, 300)
    $listview = GUICtrlCreateListView("", 2, 2, 394, 268, BitOR($LVS_SHOWSELALWAYS, $LVS_NOSORTHEADER, $LVS_REPORT))
    _GUICtrlListView_SetExtendedListViewStyle($listview, $exStyles)
    GUISetState()

    ; Load images
    $hImage = _GUIImageList_Create(16, 16, 5, 3)
    _GUIImageList_AddIcon($hImage, @WindowsDir & "\explorer.exe", 1)
    _GUIImageList_AddIcon($hImage, @WindowsDir & "\explorer.exe", 2)
    _GUIImageList_AddIcon($hImage, @WindowsDir & "\explorer.exe", 3)
    _GUIImageList_AddIcon($hImage, @WindowsDir & "\explorer.exe", 4)
    _GUIImageList_AddIcon($hImage, @WindowsDir & "\explorer.exe", 5)
    _GUIImageList_AddIcon($hImage, @WindowsDir & "\explorer.exe", 6)
    _GUICtrlListView_SetImageList($listview, $hImage, 1)

    ; Add columns
    _GUICtrlListView_AddColumn($listview, "Column 1", 120)
    _GUICtrlListView_AddColumn($listview, "Column 2", 100)
    _GUICtrlListView_AddColumn($listview, "Column 3", 100)

    ; Add items
    _GUICtrlListView_AddItem($listview, "Row 1: Col 1", 0)
    _GUICtrlListView_AddSubItem($listview, 0, "Row 1: Col 2", 1, 1)
    _GUICtrlListView_AddSubItem($listview, 0, "Row 1: Col 3", 2, 2)
    _GUICtrlListView_AddItem($listview, "Row 2: Col 1", 1)
    _GUICtrlListView_AddSubItem($listview, 1, "Row 2: Col 2", 1, 2)
    _GUICtrlListView_AddItem($listview, "Row 3: Col 1", 2)
    _GUICtrlListView_AddItem($listview, "Row 4: Col 1", 3)
    _GUICtrlListView_AddItem($listview, "Row 5: Col 1", 4)
    _GUICtrlListView_AddSubItem($listview, 4, "Row 5: Col 2", 1, 3)
    _GUICtrlListView_AddItem($listview, "Row 6: Col 1", 5)
    _GUICtrlListView_AddSubItem($listview, 5, "Row 6: Col 2", 1, 4)
    _GUICtrlListView_AddSubItem($listview, 5, "Row 6: Col 3", 2, 3)

    ; Loop until user exits
    Do
    Until GUIGetMsg() = $GUI_EVENT_CLOSE
    GUIDelete()
EndFunc   ;==>_Main


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

Okay, perhaps I`m over thinking this a bit. But I still can`t convert it to a combobox. Here is your version simplified and changed to a combobox. The icon shows blank?

#include <GuiComboBoxEx.au3>
#include <GuiImageList.au3>
#include <GUIConstants.au3>

Opt('MustDeclareVars', 1)

_Main()

Func _Main()
    Local $msg, $hGUI, $hImage, $combobox, $button, $sText
    
   ; Create GUI
    $hGUI = GUICreate("ComboBoxEx Get Text with Icon", 400, 300)
    $combobox = _GUICtrlComboBoxEx_Create($hGUI, "", 2, 2, 394, 100)
    GUISetState()

    $button = GUICtrlCreateButton("Get text", 50, 150, 100, 20)

    $hImage = _GUIImageList_Create(16, 16, 5, 3)

    _GUIImageList_AddIcon($hImage, @WindowsDir & "\explorer.exe", 1)
    _GUICtrlComboBoxEx_SetImageList($combobox, $hImage)
    _GUICtrlComboBoxEx_AddString($combobox, StringFormat("%03d : Random string", Random(1, 200, 1)), 1, 1)
    
    While 1
        $msg = GUIGetMsg()
        Switch $msg
            Case $GUI_EVENT_CLOSE
                ExitLoop
            Case $button
                _GUICtrlComboBoxEx_GetItemText($combobox, _GUICtrlComboBoxEx_GetCurSel($combobox), $sText)
                MsgBox(4160, "Information", "Edit Text: " & $sText)
        EndSwitch
    WEnd
EndFunc  ;==>_Main

Share this post


Link to post
Share on other sites

Read again the functions remarks, _GUICtrlComboBoxEx_AddString() expects a zero-based index of the icon in the image-list:

#include <GuiComboBoxEx.au3>
#include <GuiImageList.au3>
#include <GUIConstants.au3>

Opt('MustDeclareVars', 1)

_Main()

Func _Main()
    Local $msg, $hGUI, $hImage, $combobox, $button, $sText
    
   ; Create GUI
    $hGUI = GUICreate("ComboBoxEx Get Text with Icon", 400, 300)
    $combobox = _GUICtrlComboBoxEx_Create($hGUI, "", 2, 2, 394, 100)
    GUISetState()

    $button = GUICtrlCreateButton("Get text", 50, 150, 100, 20)

    $hImage = _GUIImageList_Create(16, 16, 5, 3)

    _GUIImageList_AddIcon($hImage, @WindowsDir & "\explorer.exe", 1)
    _GUICtrlComboBoxEx_SetImageList($combobox, $hImage)
    _GUICtrlComboBoxEx_AddString($combobox, StringFormat("%03d : Random string", Random(1, 200, 1)), 0, 0)
    
    While 1
        $msg = GUIGetMsg()
        Switch $msg
            Case $GUI_EVENT_CLOSE
                ExitLoop
            Case $button
                _GUICtrlComboBoxEx_GetItemText($combobox, _GUICtrlComboBoxEx_GetCurSel($combobox), $sText)
                MsgBox(4160, "Information", "Edit Text: " & $sText)
        EndSwitch
    WEnd
EndFunc  ;==>_Main

Share this post


Link to post
Share on other sites

Oh...thanks Gary and Authenticity for the help.

Sorry for the basic question

Picea

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