Jump to content

How to insert images in combobox


Recommended Posts

Hello everyone ,

Text translated from Portuguese by google - please apologize for any errors


Once again I need a light from the gurus of this wonderful website
I am fanatic by combobox for its usability but I am not able to uncertain images within lists ...
I know uncertain icons, and cursors but I am not able to insert gif or jpg images.
1) How to solve this ...
2) will the path is to convert gif into bmp and then uncertain ... how to do that?

#include <GUIConstantsEx.au3>
#include <GuiImageList.au3>
#include <GuiListView.au3>
#include <WinAPI.au3>
#include <WindowsConstants.au3>
;dados de mouse
#include <WinAPIRes.au3>
;COMBO
#include <GuiComboBoxEx.au3>
;Fonts
#include <FontConstants.au3>
;obter imagem de arquivo
#include <GDIPlus.au3>
#include <WinAPIGdi.au3>

Example()

Func Example()
    Local $hGUI, $hImage, $hCombo, $hFont
    Local $idListview, $hImage
    Local $sWow64 = ""
    Local $Pasta = "C:\WINDOWS\Cursors\3dgarro.cur"
    Local $PastaROMs = @MyDocumentsDir & "\Stella\ROMs\" ;com barra no final
    $hGUI = GUICreate("ImageList", 500, 310)

    GUISetFont(14, 400, 0, "Arial") ;<<<<<<<<<<this does not work for _GUICtrlComboBoxEx_Create

    $hCombo = _GUICtrlComboBoxEx_Create($hGUI, "", 2, 2, 494, 200)
    ;GUICtrlSetFont($hCombo, 14, 400, 0, "Arial");<<<<<<<<<<It does not work
    ;
    ;Create a handle to a font object
    $hFont = _WinAPI_CreateFont(30, 0, 0, 0, 400, False, False, False, $DEFAULT_CHARSET, $OUT_DEFAULT_PRECIS, $CLIP_DEFAULT_PRECIS, $DEFAULT_QUALITY, 0, 'Arial')
    ;Pass the handle to _WinAPI_SetFont
    _WinAPI_SetFont($hCombo, $hFont)

    $idListview = GUICtrlCreateListView("", 2, 50, 494, 250, BitOR($LVS_SHOWSELALWAYS, $LVS_NOSORTHEADER, $LVS_REPORT))
    _GUICtrlListView_SetExtendedListViewStyle($idListview, BitOR($LVS_EX_FULLROWSELECT, $LVS_EX_GRIDLINES, $LVS_EX_DOUBLEBUFFER))
    GUISetState(@SW_SHOW)
    ; Initialize GDI+ library
    _GDIPlus_Startup()

    ; Load images
    $hImage = _GUIImageList_Create(120, 70, 6, 2) ;32,32,5,5) ; 
    $DadosCombo = "Escolha|" & _GUIImageList_Add($hImage, _GUICtrlComboBoxEx_CreateSolidBitMap($hCombo, 0x0000FF, 120, 70))
    ;Local $aCursors[] = [32650, 32512, 32515, 32649, 32651, 32513, 32648, 32646, 32643, 32645, 32642, 32644, 32516, 32514]
    
    For $i = 1 To 10
        $sFile = FileOpenDialog("Please select an image", $PastaROMs, "Image (*.jpg;*.png;*.bmp;*.gif;*.tif)", BitOR($FD_PATHMUSTEXIST, $FD_FILEMUSTEXIST))
        If @error Then Exit MsgBox(BitOR($MB_TOPMOST, $MB_ICONERROR), "Error", "No image file has been selected", 30)

        $a = _GDIPlus_BitmapCreateFromFile ($sFile);<<<<< ok
        If @error Or Not $hImage Then
            MsgBox(BitOR($MB_TOPMOST, $MB_ICONERROR), "Error", "This file isn't supported by GDIPlus!")
        Else
            $b=_GUIImageList_Add($hImage, $a);<<<<<< Return -1
            $DadosCombo &= "|" & $i & "_img_princ.gif""|" & $b
        EndIf
    Next

    _GUICtrlListView_SetImageList($idListview, $hImage, 1)
    _GUICtrlComboBoxEx_SetImageList($hCombo, $hImage)

    ; Add columns
    _GUICtrlListView_AddColumn($idListview, "Icons - Mouses", 350)


    ; Add items
    $a = StringSplit($DadosCombo, "|")
    For $i = 1 To $a[0] Step 2
        _GUICtrlListView_AddItem($idListview, $a[$i], $a[$i + 1])
        _GUICtrlComboBoxEx_AddString($hCombo, $a[$i], $a[$i + 1], $a[$i + 1]) 
    Next
;AutoIt_Debugger_Command:Disable_Debug

    ; Loop until the user exits.
    Do
    Until GUIGetMsg() = $GUI_EVENT_CLOSE
    GUIDelete()
;AutoIt_Debugger_Command:Enable_Debug
    
EndFunc   ;==>Example

tks

Link to comment
Share on other sites

You should look in the help file for _GUIImageList_Create and _GUICtrlComboBoxEx_SetImageList and the associated functions that go with them.

Edited by BrewManNH

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

On 19/06/2018 at 10:25 AM, BrewManNH said:

Você deve procurar no arquivo de ajuda por _GUIImageList_Create e _GUICtrlComboBoxEx_SetImageList e as funções associadas que os acompanham.

 

On 19/06/2018 at 10:25 AM, BrewManNH said:

You should look in the help file for _GUIImageList_Create and _GUICtrlComboBoxEx_SetImageList and the associated functions that go with them.

You think I did not do it ...
Unfortunately I did not get results
Can anyone give a more meaningful light?

Link to comment
Share on other sites

The examplein helpile

#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 : Random 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

didn't work for you?  

Which errors happened? => Better show your script, what you tried.

Here a copy & paste script (based on func's from @progandy & helpfile):

#include <APIShellExConstants.au3>
#include <FileConstants.au3>
#include <MsgBoxConstants.au3>
#include <GUIConstantsEx.au3>
#include <GuiComboBoxEx.au3>
#include <GuiListView.au3>
#include <File.au3>
#AutoIt3Wrapper_AU3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6

Global Const $tagSHFILEINFO = 'ptr hIcon; int iIcon; DWORD dwAttributes; CHAR szDisplayName[255]; CHAR szTypeName[80];'
Global $FOLDER_ICON_INDEX= _GUIImageList_GetFileIconIndex(@SystemDir, True, 1)
;Global $UP_ICON_INDEX = _GUIImageList_GetFileIconIndex($sIconDir & 'up.ico', True, 1)


Global $idComboEx, $idRoot, $hIcon
Global $aDirs, $aFiles

; Create GUI
Global $hGui = GUICreate("Demo _GUICtrlComboBoxEx_AddString", 500, 700)
GUISetFont(14)
$idComboEx = _GUICtrlComboBoxEx_Create($hGui,'Test',2, 2, 494, 694)
_GUICtrlComboBoxEx_SetImageList($idComboEx, _GUIImageList_GetSystemImageList(True))
Global $sAutoItPath = StringReplace(StringReplace(@AutoItExe,'_x64',''),'autoit3.exe','')
If Not FileExists($sAutoItPath&'autoit3.exe') Then
    $sAutoItPath=''
    if MsgBox($MB_YESNO,'Ordner nicht gefunden','Möchten Sie selbst danach suchen?',0,$hGui)=6 Then
        $sAutoItPath=FileSelectFolder('AutoIt Ordner manuell suchen','c:\')
    EndIf
    if $sAutoItPath='' Then Exit
EndIf
ConsoleWrite($sAutoItPath&@CRLF)

$aDirs=_FileListToArray($sAutoItPath, '*', 2)
If Not @error Then
    For $i = 1 To $aDirs[0]
        ; Add items
        _GUICtrlComboBoxEx_AddString($idComboEx,$aDirs[$i],$FOLDER_ICON_INDEX,$FOLDER_ICON_INDEX)
    Next
EndIf
$aFiles = _FileListToArray($sAutoItPath, '*', 1)
If Not @error Then
    For $i = 1 To $aFiles[0]
        ; Add items
        $hIcon=_GUIImageList_GetFileIconIndex($aFiles[$i], True)
        _GUICtrlComboBoxEx_AddString($idComboEx,$aFiles[$i],$hIcon,$hIcon)
    Next
EndIf

GUISetState(@SW_SHOW)
; Loop until the user exits.
Do
Until GUIGetMsg() = $GUI_EVENT_CLOSE
GUIDelete()


; Author: progandy (www.autoit.de)
Func _GUIImageList_GetSystemImageList($bLargeIcons = False)
    Local $dwFlags, $hIml, $FileInfo = DllStructCreate($tagSHFILEINFO)
    $dwFlags = BitOR($SHGFI_USEFILEATTRIBUTES, $SHGFI_SYSICONINDEX)
    If Not ($bLargeIcons) Then
        $dwFlags = BitOR($dwFlags, $SHGFI_SMALLICON)
    EndIf
;~    '// Load the image list - use an arbitrary file extension for the
;~    '// call to SHGetFileInfo (we don't want to touch the disk, so use
;~    '// FILE_ATTRIBUTE_NORMAL && SHGFI_USEFILEATTRIBUTES).
    $hIml = _WinAPI_SHGetFileInfo(".txt", $FILE_ATTRIBUTE_NORMAL, _
            DllStructGetPtr($FileInfo), DllStructGetSize($FileInfo), $dwFlags)
    Return $hIml
EndFunc   ;==>_GUIImageList_GetSystemImageList

; Author: progandy (www.autoit.de)
Func _WinAPI_SHGetFileInfo($pszPath, $dwFileAttributes, $psfi, $cbFileInfo, $uFlags)
    Local $return = DllCall("shell32.dll", "dword_ptr", "SHGetFileInfo", "str", $pszPath, "DWORD", $dwFileAttributes, "ptr", $psfi, "UINT", $cbFileInfo, "UINT", $uFlags)
    If @error Then Return SetError(@error, 0, 0)
    Return $return[0]
EndFunc   ;==>_WinAPI_SHGetFileInfo

; Author: progandy (www.autoit.de)
Func _GUIImageList_GetFileIconIndex($sFileSpec, $bLargeIcons = False, $bForceLoadFromDisk = False)
    Local $dwFlags, $FileInfo = DllStructCreate($tagSHFILEINFO)
    $dwFlags = $SHGFI_SYSICONINDEX
    If $bLargeIcons Then
        $dwFlags = BitOR($dwFlags, $SHGFI_LARGEICON)
    Else
        $dwFlags = BitOR($dwFlags, $SHGFI_SMALLICON)
    EndIf
;~ ' We choose whether to access the disk or not. If you don't
;~ ' hit the disk, you may get the wrong icon if the icon is
;~ ' not cached. But the speed is very good!
    If Not $bForceLoadFromDisk Then $dwFlags = BitOR($dwFlags, $SHGFI_USEFILEATTRIBUTES)
;~ ' sFileSpec can be any file. You can specify a
;~ ' file that does not exist and still get the
;~ ' icon, for example sFileSpec = "C:\PANTS.DOC"
    Local $lR = _WinAPI_SHGetFileInfo( _
            $sFileSpec, $FILE_ATTRIBUTE_NORMAL, DllStructGetPtr($FileInfo), DllStructGetSize($FileInfo), _
            $dwFlags _
            )
    If ($lR = 0) Then
        Return SetError(1, 0, -1)
    Else
        Return DllStructGetData($FileInfo, "iIcon")
    EndIf
EndFunc   ;==>_GUIImageList_GetFileIconIndex

must be polished, try by using _GUICtrlComboBoxEx_SetItemHeight and _GUICtrlComboBoxEx_SetItem.

Edited by AutoBert
Link to comment
Share on other sites

3 hours ago, odaylton said:

You think I did not do it ...
Unfortunately I did not get results
Can anyone give a more meaningful light?

I said to study the examples in the help file, not just look at them for some names.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

2 hours ago, BrewManNH said:

I said to study the examples in the help file, not just look at them for some names.

I think you did not understand the real problem.
Putting "icons" or parts of "DLLs" to uncertain images or even SolidBitmap is not the problem ....
The real problem is how to convert Gif or jpg images to be compatible.
Note in the first listing I use _GDIPlus_BitmapCreateFromFile to import the image but by using the _GUIImageList_Add construct it returns me -1 (error) ...
How to solve this ...
I have a list of 120x70 gif photos and I would like to uncertain both the combobox and the listview

Link to comment
Share on other sites

2 hours ago, AutoBert said:

The examplein helpile

#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 : Random 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

didn't work for you?  

Which errors happened? => Better show your script, what you tried.

Here a copy & paste script (based on func's from @progandy & helpfile):

#include <APIShellExConstants.au3>
#include <FileConstants.au3>
#include <MsgBoxConstants.au3>
#include <GUIConstantsEx.au3>
#include <GuiComboBoxEx.au3>
#include <GuiListView.au3>
#include <File.au3>
#AutoIt3Wrapper_AU3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6

Global Const $tagSHFILEINFO = 'ptr hIcon; int iIcon; DWORD dwAttributes; CHAR szDisplayName[255]; CHAR szTypeName[80];'
Global $FOLDER_ICON_INDEX= _GUIImageList_GetFileIconIndex(@SystemDir, True, 1)
;Global $UP_ICON_INDEX = _GUIImageList_GetFileIconIndex($sIconDir & 'up.ico', True, 1)


Global $idComboEx, $idRoot, $hIcon
Global $aDirs, $aFiles

; Create GUI
Global $hGui = GUICreate("Demo _GUICtrlComboBoxEx_AddString", 500, 700)
GUISetFont(14)
$idComboEx = _GUICtrlComboBoxEx_Create($hGui,'Test',2, 2, 494, 694)
_GUICtrlComboBoxEx_SetImageList($idComboEx, _GUIImageList_GetSystemImageList(True))
Global $sAutoItPath = StringReplace(StringReplace(@AutoItExe,'_x64',''),'autoit3.exe','')
If Not FileExists($sAutoItPath&'autoit3.exe') Then
    $sAutoItPath=''
    if MsgBox($MB_YESNO,'Ordner nicht gefunden','Möchten Sie selbst danach suchen?',0,$hGui)=6 Then
        $sAutoItPath=FileSelectFolder('AutoIt Ordner manuell suchen','c:\')
    EndIf
    if $sAutoItPath='' Then Exit
EndIf
ConsoleWrite($sAutoItPath&@CRLF)

$aDirs=_FileListToArray($sAutoItPath, '*', 2)
If Not @error Then
    For $i = 1 To $aDirs[0]
        ; Add items
        _GUICtrlComboBoxEx_AddString($idComboEx,$aDirs[$i],$FOLDER_ICON_INDEX,$FOLDER_ICON_INDEX)
    Next
EndIf
$aFiles = _FileListToArray($sAutoItPath, '*', 1)
If Not @error Then
    For $i = 1 To $aFiles[0]
        ; Add items
        $hIcon=_GUIImageList_GetFileIconIndex($aFiles[$i], True)
        _GUICtrlComboBoxEx_AddString($idComboEx,$aFiles[$i],$hIcon,$hIcon)
    Next
EndIf

GUISetState(@SW_SHOW)
; Loop until the user exits.
Do
Until GUIGetMsg() = $GUI_EVENT_CLOSE
GUIDelete()


; Author: progandy (www.autoit.de)
Func _GUIImageList_GetSystemImageList($bLargeIcons = False)
    Local $dwFlags, $hIml, $FileInfo = DllStructCreate($tagSHFILEINFO)
    $dwFlags = BitOR($SHGFI_USEFILEATTRIBUTES, $SHGFI_SYSICONINDEX)
    If Not ($bLargeIcons) Then
        $dwFlags = BitOR($dwFlags, $SHGFI_SMALLICON)
    EndIf
;~    '// Load the image list - use an arbitrary file extension for the
;~    '// call to SHGetFileInfo (we don't want to touch the disk, so use
;~    '// FILE_ATTRIBUTE_NORMAL && SHGFI_USEFILEATTRIBUTES).
    $hIml = _WinAPI_SHGetFileInfo(".txt", $FILE_ATTRIBUTE_NORMAL, _
            DllStructGetPtr($FileInfo), DllStructGetSize($FileInfo), $dwFlags)
    Return $hIml
EndFunc   ;==>_GUIImageList_GetSystemImageList

; Author: progandy (www.autoit.de)
Func _WinAPI_SHGetFileInfo($pszPath, $dwFileAttributes, $psfi, $cbFileInfo, $uFlags)
    Local $return = DllCall("shell32.dll", "dword_ptr", "SHGetFileInfo", "str", $pszPath, "DWORD", $dwFileAttributes, "ptr", $psfi, "UINT", $cbFileInfo, "UINT", $uFlags)
    If @error Then Return SetError(@error, 0, 0)
    Return $return[0]
EndFunc   ;==>_WinAPI_SHGetFileInfo

; Author: progandy (www.autoit.de)
Func _GUIImageList_GetFileIconIndex($sFileSpec, $bLargeIcons = False, $bForceLoadFromDisk = False)
    Local $dwFlags, $FileInfo = DllStructCreate($tagSHFILEINFO)
    $dwFlags = $SHGFI_SYSICONINDEX
    If $bLargeIcons Then
        $dwFlags = BitOR($dwFlags, $SHGFI_LARGEICON)
    Else
        $dwFlags = BitOR($dwFlags, $SHGFI_SMALLICON)
    EndIf
;~ ' We choose whether to access the disk or not. If you don't
;~ ' hit the disk, you may get the wrong icon if the icon is
;~ ' not cached. But the speed is very good!
    If Not $bForceLoadFromDisk Then $dwFlags = BitOR($dwFlags, $SHGFI_USEFILEATTRIBUTES)
;~ ' sFileSpec can be any file. You can specify a
;~ ' file that does not exist and still get the
;~ ' icon, for example sFileSpec = "C:\PANTS.DOC"
    Local $lR = _WinAPI_SHGetFileInfo( _
            $sFileSpec, $FILE_ATTRIBUTE_NORMAL, DllStructGetPtr($FileInfo), DllStructGetSize($FileInfo), _
            $dwFlags _
            )
    If ($lR = 0) Then
        Return SetError(1, 0, -1)
    Else
        Return DllStructGetData($FileInfo, "iIcon")
    EndIf
EndFunc   ;==>_GUIImageList_GetFileIconIndex

must be polished, try by using _GUICtrlComboBoxEx_SetItemHeight and _GUICtrlComboBoxEx_SetItem.

I think you did not understand the real problem.
Putting "icons" or parts of "DLLs" to uncertain images or even SolidBitmap is not the problem ....
The real problem is how to convert Gif or jpg images to be compatible.
Note in the first listing I use _GDIPlus_BitmapCreateFromFile to import the image but by using the _GUIImageList_Add construct it returns me -1 (error) ...
How to solve this ...
I have a list of 120x70 gif photos and I would like to uncertain both the combobox and the listview

Link to comment
Share on other sites

@odaylton

...
    For $i = 1 To 10
        $sFile = FileOpenDialog("Please select an image", $PastaROMs, "Image (*.jpg;*.png;*.bmp;*.gif;*.tif)", BitOR($FD_PATHMUSTEXIST, $FD_FILEMUSTEXIST))
        If @error Then Exit MsgBox(BitOR($MB_TOPMOST, $MB_ICONERROR), "Error", "No image file has been selected", 30)

        $a = _GDIPlus_BitmapCreateFromFile ($sFile);<<<<< ok
        If @error Or Not $hImage Then
            MsgBox(BitOR($MB_TOPMOST, $MB_ICONERROR), "Error", "This file isn't supported by GDIPlus!")
        Else
            $bmp = _GDIPlus_BitmapCreateHBITMAPFromBitmap($a)
            _GDIPlus_BitmapDispose($a)
            $b=_GUIImageList_Add($hImage, $bmp)
            _WinAPI_DeleteObject($bmp)
            $DadosCombo &= "|" & $i & "_img_princ.gif|" & $b
        EndIf
    Next
...

 

Link to comment
Share on other sites

this is great

$bmp = _GDIPlus_BitmapCreateHBITMAPFromBitmap($a)
            _GDIPlus_BitmapDispose($a)
            $b=_GUIImageList_Add($hImage, $bmp)
            _WinAPI_DeleteObject($bmp)

would be asking too much that could scale the image to fit in a specific area.
See that I'm missing the hit because I tried to use the _GDIPlus_BitmapCreateDIBFromBitmap.au3 ex to make the scale change.
Works perfect for a GUICtrlCreatePic but crach according to the listing below:
in the line
$ bmp = _GDIPlus_BitmapCreateHBITMAPFromBitmap ($ hHBitmap); <<<<<
I believe I am passing the wrong Handle but I do not know how to solve

#include <GUIConstantsEx.au3>
#include <GuiImageList.au3>
#include <GuiListView.au3>
#include <WinAPI.au3>
#include <WindowsConstants.au3>
;dados de mouse
#include <WinAPIRes.au3>
;COMBO
#include <GuiComboBoxEx.au3>
;Fonts
#include <FontConstants.au3>
;obter imagem de arquivo
#include <GDIPlus.au3>
#include <WinAPIGdi.au3>

Example()

Func Example()
    Local $hGUI, $hImage, $hCombo, $hFont
    Local $idListview, $hImage
    Local $sWow64 = ""
    
    Local $PastaROMs = @MyDocumentsDir & "\Stella\ROMs\" ;com barra no final
    $hGUI = GUICreate("ImageList", 500, 310)

    GUISetFont(14, 400, 0, "Arial") ;<<<<<<<<<<this does not work for _GUICtrlComboBoxEx_Create
    $Tam=50
    $hCombo = _GUICtrlComboBoxEx_Create($hGUI, "", 2, 2, 494, $Tam*2)
    ;GUICtrlSetFont($hCombo, 14, 400, 0, "Arial");<<<<<<<<<<It does not work
    ;
    ;Create a handle to a font object
    $hFont = _WinAPI_CreateFont($Tam, 0, 0, 0, 400, False, False, False, $DEFAULT_CHARSET, $OUT_DEFAULT_PRECIS, $CLIP_DEFAULT_PRECIS, $DEFAULT_QUALITY, 0, 'Arial')
    ;Pass the handle to _WinAPI_SetFont
    _WinAPI_SetFont($hCombo, $hFont)

    $idListview = GUICtrlCreateListView("", 2, $Tam*2, 494, 250, BitOR($LVS_SHOWSELALWAYS, $LVS_NOSORTHEADER, $LVS_REPORT))
    _GUICtrlListView_SetExtendedListViewStyle($idListview, BitOR($LVS_EX_FULLROWSELECT, $LVS_EX_GRIDLINES, $LVS_EX_DOUBLEBUFFER))
    GUISetState(@SW_SHOW)
    ; Initialize GDI+ library
    _GDIPlus_Startup()

    ; Load images
    $hImage = _GUIImageList_Create($Tam*2, $Tam, 6, 2) ;32,32,5,5) ;
    $DadosCombo = "Escolha|" & _GUIImageList_Add($hImage, _GUICtrlComboBoxEx_CreateSolidBitMap($hCombo, 0x0000FF, $Tam*2, $Tam))
    ;Local $aCursors[] = [32650, 32512, 32515, 32649, 32651, 32513, 32648, 32646, 32643, 32645, 32642, 32644, 32516, 32514]
    
    For $i = 1 To 3
        $sFile = FileOpenDialog("Please select an image", $PastaROMs, "Image (*.jpg;*.png;*.bmp;*.gif;*.tif)", BitOR($FD_PATHMUSTEXIST, $FD_FILEMUSTEXIST))
        If @error Then Exit MsgBox(BitOR($MB_TOPMOST, $MB_ICONERROR), "Error", "No image file has been selected", 30)
        $hBitmap = _GDIPlus_BitmapCreateFromFile($sFile);<<<<< ok
        If @error Or Not $hImage Then
            MsgBox(BitOR($MB_TOPMOST, $MB_ICONERROR), "Error", "This file isn't supported by GDIPlus!")
        Else
            $iWidthBMP = _GDIPlus_ImageGetWidth($hBitmap)
            $iHeightBMP = _GDIPlus_ImageGetHeight($hBitmap)
            ;If $iWidth = -1 Then
                ;$iWidth = $iWidthBMP
                ;$EscalaX = 1
            ;Else
                ;$EscalaX = $iWidth / $iWidthBMP
            ;EndIf
            ;If $iHeight = -1 Then
                ;$iHeight = $iHeightBMP
                ;$EscalaY = 1
            ;Else
                ;$EscalaY = $iHeight / $iHeightBMP
            ;EndIf
            $EscalaX = $Tam*2 / $iWidthBMP
            $EscalaY = $Tam / $iHeightBMP
            If $EscalaX > $EscalaY Then
                $EscalaX = $EscalaY
            EndIf
            Local $hBitmap_Resized = _GDIPlus_BitmapCreateFromScan0($iWidthBMP * $EscalaX, $iHeightBMP * $EscalaX)
            Local $hBMP_Ctxt = _GDIPlus_ImageGetGraphicsContext($hBitmap_Resized)
            _GDIPlus_GraphicsSetInterpolationMode($hBMP_Ctxt, $GDIP_INTERPOLATIONMODE_HIGHQUALITYBICUBIC)
            _GDIPlus_GraphicsDrawImageRect($hBMP_Ctxt, $hBitmap, 0, 0, $Tam*2, $Tam)
            $hHBitmap = _GDIPlus_BitmapCreateDIBFromBitmap($hBitmap_Resized)
            
            $bmp = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hHBitmap) ;<<<<<
            _GDIPlus_BitmapDispose($hBitmap_Resized)
            _GDIPlus_GraphicsDispose($hBMP_Ctxt)
            $b = _GUIImageList_Add($hImage, $bmp)
            _WinAPI_DeleteObject($hHBitmap)
            _WinAPI_DeleteObject($bmp)
            _GDIPlus_BitmapDispose($hBitmap)
            
            $DadosCombo &= "|" & $i & "_img_princ.gif""|" & $b
        EndIf
    Next

    _GUICtrlListView_SetImageList($idListview, $hImage, 1)
    _GUICtrlComboBoxEx_SetImageList($hCombo, $hImage)

    ; Add columns
    _GUICtrlListView_AddColumn($idListview, "Icons - Mouses", 350)


    ; Add items
    $a = StringSplit($DadosCombo, "|")
    For $i = 1 To $a[0] Step 2
        _GUICtrlListView_AddItem($idListview, $a[$i], $a[$i + 1])
        _GUICtrlComboBoxEx_AddString($hCombo, $a[$i], $a[$i + 1], $a[$i + 1])
    Next
    ;AutoIt_Debugger_Command:Disable_Debug

    ; Loop until the user exits.
    Do
    Until GUIGetMsg() = $GUI_EVENT_CLOSE
    GUIDelete()
    ;AutoIt_Debugger_Command:Enable_Debug
    
EndFunc   ;==>Example

now it works perfectly

; PNG work around by UEZ

#include <GDIPlus.au3>

#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
Global $Tam = 50
; Create GUI
Local $hMainGUI = GUICreate("Show PNG", 510, 510)

$PastaROMs = @MyDocumentsDir & "\Stella\ROMs\" ;com barra no final
If Not FileExists($PastaROMs & "*.gif") Then
    $PastaROMs = FileSelectFolder("Escolha a pasta com as imagens das ROMs", @MyDocumentsDir, 6, $PastaROMs)
EndIf
If $PastaROMs = "" Then
    MsgBox(0, "Cancelado", "No foi escolhido uma pasta", 5)
    Exit
Else
    If StringRight($PastaROMs, 1) <> "\" Then $PastaROMs &= "\"
EndIf

$sFile = FileOpenDialog("Please select an image", $PastaROMs, "Image (*.jpg;*.png;*.bmp;*.gif;*.tif)", BitOR($FD_PATHMUSTEXIST, $FD_FILEMUSTEXIST))
If @error Then Exit MsgBox(BitOR($MB_TOPMOST, $MB_ICONERROR), "Error", "No image file has been selected", 30)

_GUICtrlPic_Create($sFile, 10, 10, 50, 100)

GUISetState(@SW_SHOW)

; Loop until the user exits.
While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            ExitLoop

    EndSwitch
WEnd

; #INTERNAL_USE_ONLY#=================================================================================================
; Name...........: _GUICtrlPic_Create
; Description ...: Creates a Picture control for the GUI
; Syntax ........: _GUICtrlPic_Create($sFilename, $iLeft, $iTop, $iWidth, $iHeight, $iStyle = -1 , $iExStyle = -1)
; Parameters ....: $sFilename - Path of image file
; Author ........: UEZ
; Modified.......: Melba23, guinness, jpm
; Remarks .......: PNG image can be used.
; ====================================================================================================================
Func _GUICtrlPic_Create($sFilename, $iLeft, $iTop, $iWidth = -1, $iHeight = -1, $iStyle = -1, $iExStyle = -1)
    Local $EscalaX
    Local $EscalaY

    _GDIPlus_Startup()
    Local $idPic = GUICtrlCreatePic("", $iLeft, $iTop, $iWidth, $iHeight, $iStyle, $iExStyle)
    Local $hBitmap = _GDIPlus_BitmapCreateFromFile($sFilename)
    $iWidthBMP = _GDIPlus_ImageGetWidth($hBitmap)
    $iHeightBMP = _GDIPlus_ImageGetHeight($hBitmap)
    If $iWidth = -1 Then
        $iWidth = $iWidthBMP
        $EscalaX = 1
    Else
        $EscalaX = $iWidth / $iWidthBMP
    EndIf
    If $iHeight = -1 Then
        $iHeight = $iHeightBMP
        $EscalaY = 1
    Else
        $EscalaY = $iHeight / $iHeightBMP
    EndIf
    
    If $EscalaX > $EscalaY Then
        $EscalaX = $EscalaY
    EndIf
    Local $hBitmap_Resized = _GDIPlus_BitmapCreateFromScan0($iWidthBMP * $EscalaX, $iHeightBMP * $EscalaX)
    Local $hBMP_Ctxt = _GDIPlus_ImageGetGraphicsContext($hBitmap_Resized)
    _GDIPlus_GraphicsSetInterpolationMode($hBMP_Ctxt, $GDIP_INTERPOLATIONMODE_HIGHQUALITYBICUBIC)
    _GDIPlus_GraphicsDrawImageRect($hBMP_Ctxt, $hBitmap, 0, 0, $iWidth, $iHeight)
    Local $hHBitmap = _GDIPlus_BitmapCreateDIBFromBitmap($hBitmap_Resized)
    Local $hPrevImage = GUICtrlSendMsg($idPic, $STM_SETIMAGE, 0, $hHBitmap) ; $STM_SETIMAGE = 0x0172
    _WinAPI_DeleteObject($hPrevImage) ; Delete Prev image if any
    _GDIPlus_BitmapDispose($hBitmap)
    _GDIPlus_BitmapDispose($hBitmap_Resized)
    _GDIPlus_GraphicsDispose($hBMP_Ctxt)
    _WinAPI_DeleteObject($hHBitmap)
    _GDIPlus_Shutdown()

    Return $idPic
EndFunc   ;==>_GUICtrlPic_Create

PS: I have this working but it cuts an image bigger than the fixed size of 120x70

#include <GUIConstantsEx.au3>
#include <GuiImageList.au3>
#include <GuiListView.au3>
#include <WinAPI.au3>
#include <WindowsConstants.au3>
;dados de mouse
#include <WinAPIRes.au3>
;COMBO
#include <GuiComboBoxEx.au3>
;Fonts
#include <FontConstants.au3>
;obter imagem de arquivo
#include <GDIPlus.au3>
#include <WinAPIGdi.au3>

Example()

Func Example()
    Local $hGUI, $hImage, $hCombo, $hFont
    Local $idListview, $hImage
    Local $sWow64 = ""
    
    Local $PastaROMs = @MyDocumentsDir & "\Stella\ROMs\" ;com barra no final
    If Not FileExists($PastaROMs & "*.gif") Then
        $PastaROMs = FileSelectFolder("Escolha a pasta com as imagens das ROMs", @MyDocumentsDir, 6, $PastaROMs)
    EndIf
    If $PastaROMs = "" Then
        MsgBox(0, "Cancelado", "No foi escolhido uma pasta", 5)
        Exit
    Else
        If StringRight($PastaROMs, 1) <> "\" Then $PastaROMs &= "\"
    EndIf

    $hGUI = GUICreate("ImageList", 500, 310)

    GUISetFont(14, 400, 0, "Arial") ;<<<<<<<<<<this does not work for _GUICtrlComboBoxEx_Create

    $hCombo = _GUICtrlComboBoxEx_Create($hGUI, "", 2, 2, 494, 200)
    ;GUICtrlSetFont($hCombo, 14, 400, 0, "Arial");<<<<<<<<<<It does not work
    ;
    ;Create a handle to a font object
    $hFont = _WinAPI_CreateFont(30, 0, 0, 0, 400, False, False, False, $DEFAULT_CHARSET, $OUT_DEFAULT_PRECIS, $CLIP_DEFAULT_PRECIS, $DEFAULT_QUALITY, 0, 'Arial')
    ;Pass the handle to _WinAPI_SetFont
    _WinAPI_SetFont($hCombo, $hFont)

    $idListview = GUICtrlCreateListView("Titulo|Local", 2, 50, 494, 250, BitOR($LVS_SHOWSELALWAYS, $LVS_NOSORTHEADER, $LVS_REPORT))
    _GUICtrlListView_SetExtendedListViewStyle($idListview, BitOR($LVS_EX_FULLROWSELECT, $LVS_EX_GRIDLINES, $LVS_EX_DOUBLEBUFFER))
    GUISetState(@SW_SHOW)
    ; Initialize GDI+ library
    _GDIPlus_Startup()

    ; Load images
    $hImage = _GUIImageList_Create(120, 70, 6, 3)
    
    $DadosCombo = "<Escolha>"
    $ImgDefaut = _GUIImageList_Add($hImage, _GUICtrlComboBoxEx_CreateSolidBitMap($hCombo, 0xFF0000, 120, 70))
    $DadosCombo &= "|" & $ImgDefaut & "|"
    ;$DadosCombo [n1]= Texto
    ;$DadosCombo [n2]= Indice Imagem
    ;$DadosCombo [n3]= Informao
    ;AutoIt_Debugger_Command:Disable_Debug

    
    Local $QuantGifs
    ;obtendo a quant de imagens GIF
    Local $search = FileFindFirstFile($PastaROMs & "*.gif")
    If $search <> -1 Then
        While 1
            Local $file = FileFindNextFile($search)
            If @error Then
                ExitLoop
            Else
                $QuantGifs += 1
                
            EndIf
        WEnd
    EndIf
    ; Close the search handle
    FileClose($search)
    $QuantGifs = 5 ;<<<<<TEMP PATA TESTES
    
    Local $search = FileFindFirstFile($PastaROMs & "*.gif")
    ;AutoIt_Debugger_Command:Enable_Debug

    If $search <> -1 Then
        $Quant = 0
        $Show = Int($QuantGifs * .1)
        While 1
            Local $sFile = FileFindNextFile($search)
            If @error Then
                ExitLoop
            Else
                $Quant += 1
                ;temp
                If $Quant > $QuantGifs Then ExitLoop
                If Int($Quant / $Show) = ($Quant / $Show) Then
                    ;performace 10%
                    TrayTip("Fase I", _
                            "Obtendo Dados da ROMs[" & $Quant & "] de [" & $QuantGifs & "]" & @CRLF & _
                            "[" & $PastaROMs & $sFile & "]", 5)
                EndIf
                $a = _GDIPlus_BitmapCreateFromFile($PastaROMs & $sFile) ;<<<<< ok
                If @error Or Not $a Then
                    ;MsgBox(BitOR($MB_TOPMOST, $MB_ICONERROR), "Error", "This file["& $sFile & "] isn't supported by GDIPlus!")
                    $DadosCombo &= "|<ERRO>[" & @extended & "]Bitmap" & $sFile & "|" & $ImgDefaut & "|" & $PastaROMs & $sFile
                Else
                    $bmp = _GDIPlus_BitmapCreateHBITMAPFromBitmap($a)
                    If @error Or Not $bmp Then
                        ;MsgBox(BitOR($MB_TOPMOST, $MB_ICONERROR), "Error", "This file["& $sFile & "] isn't supported by GDIPlus!")
                        $DadosCombo &= "|<ERRO>[" & @extended & "]HBITMAP" & $sFile & "|" & $ImgDefaut & "|" & $PastaROMs & $sFile
                        _GDIPlus_BitmapDispose($a)
                    Else
                        _GDIPlus_BitmapDispose($a)
                        $b = _GUIImageList_Add($hImage, $bmp)
                        If @error Or Not $b Then
                            ;MsgBox(BitOR($MB_TOPMOST, $MB_ICONERROR), "Error", "This file["& $sFile & "] isn't supported by GDIPlus!")
                            $DadosCombo &= "|<ERRO>[" & @extended & "]Add" & $sFile & "|" & $ImgDefaut & "|" & $PastaROMs & $sFile
                            _WinAPI_DeleteObject($bmp)
                        Else
                            _WinAPI_DeleteObject($bmp)
                            $DadosCombo &= "|" & $sFile & "|" & $b & "|" & $PastaROMs & $sFile
                            ;$DadosCombo [n1]= Texto
                            ;$DadosCombo [n2]= Indice Imagem
                            ;$DadosCombo [n3]= Informao
                        EndIf
                    EndIf

                EndIf
            EndIf
        WEnd
        _GUICtrlComboBoxEx_SetImageList($hCombo, $hImage)
        _GUICtrlListView_SetImageList($idListview, $hImage, 1) ;temp
        TrayTip("Fase I - finalizada", _
                "Obtendo Dados da ROMs[" & $Quant & "] de [" & $QuantGifs & "]" & @CRLF & _
                "[" & $PastaROMs & $sFile & "]", 5)
    Else
        MsgBox(0, "Cancelado", "Erro de logica", 5)
        Exit
    EndIf
    
    ; Add items
    $a = StringSplit($DadosCombo, "|")
    ;$DadosCombo [n1]= Texto
    ;$DadosCombo [n2]= Indice Imagem
    ;$DadosCombo [n3]= Informao

    For $i = 1 To $a[0] Step 3 ;de 3 em 3
        ;If Int($i / $Show) = ($i / $Show) Then
        ;performace 10%
        TrayTip("Fase II", _
                "Incerindo no ComboBox[" & $i & "] de [" & $QuantGifs & "]" & @CRLF & _
                "[" & $a[$i] & "-" & $a[$i + 1] & "-" & $a[$i + 2] & "]", 5)
        ;   EndIf
        
        _GUICtrlListView_AddItem($idListview, $a[$i] & "|" & $a[$i + 2], $a[$i + 1]) ;temp
        _GUICtrlComboBoxEx_AddString($hCombo, $a[$i], $a[$i + 1], $a[$i + 1])
    Next
    
    ;AutoIt_Debugger_Command:Disable_Debug
    Do
    Until GUIGetMsg() = $GUI_EVENT_CLOSE
    GUIDelete()
    
EndFunc   ;==>Example

 

Link to comment
Share on other sites

14 hours ago, odaylton said:

scale the image to fit in a specific area

...
        $a = _GDIPlus_BitmapCreateFromFile ($sFile);<<<<< ok
        If @error Or Not $hImage Then
            MsgBox(BitOR($MB_TOPMOST, $MB_ICONERROR), "Error", "This file isn't supported by GDIPlus!")
        Else
            $size = _GDIPlus_ImageResize($a, 120, 70)
            _GDIPlus_BitmapDispose($a)
            $bmp = _GDIPlus_BitmapCreateHBITMAPFromBitmap($size)
            _GDIPlus_BitmapDispose($size)
            $b=_GUIImageList_Add($hImage, $bmp)
            _WinAPI_DeleteObject($bmp)
            $DadosCombo &= "|" & $i & "_img_princ.gif|" & $b
        EndIf
...

 

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

×
×
  • Create New...