Jump to content
odaylton

How to insert images in combobox

Recommended Posts

odaylton

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

Share this post


Link to post
Share on other sites
BrewManNH
Posted (edited)

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

Share this post


Link to post
Share on other sites
odaylton
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?

Share this post


Link to post
Share on other sites
AutoBert
Posted (edited)

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

Share this post


Link to post
Share on other sites
BrewManNH
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

Share this post


Link to post
Share on other sites
odaylton
Posted (edited)
2 hours ago, BrewManNH said:

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

 

Edited by odaylton

Share this post


Link to post
Share on other sites
odaylton
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

Share this post


Link to post
Share on other sites
odaylton
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

Share this post


Link to post
Share on other sites
InnI

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

 

Share this post


Link to post
Share on other sites
odaylton

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

 

Share this post


Link to post
Share on other sites
InnI
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
...

 

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

  • Similar Content

    • aiter
      By aiter
      I  possibly misunderstood the value of combo boxes, but I thought you could type a value, press enter and the combo box would store that value.
      The reason for wanting this is to store a history of typed commands into the combo box (accepted by pressing enter).
       
      After hours of trying to trap enter on a combobox I realized that the enter event was not registering.
      I had code like this (which used to work on a input box), but it does not for a combobox (because it does not accept enter)
      unc WM_COMMAND($hWnd, $Msg, $wParam, $lParam) Local $nNotifyCode = BitShift($wParam, 16) Local $nID = BitAND($wParam, 0x0000FFFF) If $hWnd = $CmdForm Then If $nID = $ComboInput Then ; useed to work on a normal input box If _IsPressed('0D') Then ; enter was pressed, respond DoCmd() Anyone able to help?
    • corz
      By corz
      We've been able to drag images out of web browsers since forever. Can I drag one into my GUI?
      Or rather, can I drag an image from my web browser onto my GUI and have my app *do* something with that image?
      My fingers bleed from searching. Any ideas much appreciated!
      ;o) Cor
    • Grasoft
      By Grasoft
      Greetings everyone,
      I'm writing a software that edit an ini file section by section with adding/renaming abilities
      but whenever I manually change the combobox to value other than constducted previously, I cannot get this value.
      THIS is a clean version of the code:
      #include <ButtonConstants.au3> #include <ComboConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #include <GuiStatusBar.au3> #include <GuiEdit.au3> #include <MsgBoxConstants.au3> #Region ### START Koda GUI section ### Form=C:\Program Files (x86)\AutoIt3\SciTE\Koda\Forms\QuickRepEditList7.kxf $SecMgr = GUICreate("Sections Manager", 1159, 690) GUISetFont(12, 800, 0, "MS Sans Serif") $EditSec = GUICtrlCreateEdit("", 45, 45, 1090, 644, BitOR($ES_AUTOVSCROLL, $ES_AUTOHSCROLL, $ES_WANTRETURN, $WS_HSCROLL, $ES_NOHIDESEL)) $Edit2 = GUICtrlCreateEdit("", 11, 45, 33, 617, BitOR($ES_RIGHT, $ES_READONLY, $ES_WANTRETURN)) GUICtrlSetData(-1, StringFormat(" 1:\r\n 2:\r\n 3:\r\n 4:\r\n 5:\r\n 6:\r\n 7:\r\n 8:\r\n 9:\r\n10:\r\n11:\r\n12:\r\n13:\r\n14:\r\n15:\r\n16:\r\n17:\r\n18:\r\n19:\r\n20:\r\n21:\r\n22:\r\n23:\r\n24:\r\n25:\r\n26:\r\n27:\r\n28:\r\n29:\r\n30:")) $Label1 = GUICtrlCreateLabel("Select Section:", 7, 13, 126, 24) GUICtrlSetFont(-1, 11, 800, 0, "MS Sans Serif") $Savesec = GUICtrlCreateButton("Save Changes", 375, 7, 129, 33) $NewSec = GUICtrlCreateButton("New Section", 700, 7, 121, 33) $SecDwn = GUICtrlCreateButton("Section Down", 830, 7, 137, 33) $SecUp = GUICtrlCreateButton("Section Up", 980, 7, 129, 33) $copystrs = GUICtrlCreateButton("*******", 507, 7, 73, 33) GUICtrlSetFont(-1, 12, 800, 0, "MS Sans Serif") $HeavySep = GUICtrlCreateButton("====", 581, 7, 73, 33) GUICtrlSetFont(-1, 12, 800, 0, "MS Sans Serif") Global $SecSel Global $secno Global $secn = "NULLz" Global $sFilePathtemp Global $aArray Global $SecNames Global $secnnew Global $ssecn $SecSel = GUICtrlCreateCombo("", 110, 10, 257, 25, BitOR($CBS_DROPDOWN, $CBS_AUTOHSCROLL)) queysecs() Filledit() GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### $secno=GUICtrlRead($SecSel) $changed=0 While 1 $secn = GUICtrlRead($SecSel) $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE saveeditedmsg() Exit Case $SecSel $secno=GUICtrlRead($SecSel) queysecs() Filledit() Case $Savesec saveeditedmsg() queysecs() Case $NewSec Case $SecDwn Case $SecUp Case $copystrs ClipPut("**************************************************************************************************************************************************************") Case $HeavySep ClipPut("==============================================================================================================================================================") EndSwitch WEnd Func queysecs();query section names $sFilePath = @ScriptDir & "\" & "Txt_Reps.ini" $aArray = IniReadSectionNames($sFilePath) $SecNames = $aArray[1] If $secn = "NULLz" Then $secn = $aArray[1] EndIf If Not @error Then For $i = 2 To $aArray[0] $SecNames = $SecNames & "|" & $aArray[$i] Next GUICtrlSetData($SecSel, "", "") GUICtrlSetData($SecSel, $SecNames, $secn) $secno = $secn EndIf EndFunc ;==>queysecs Func Filledit(); transfer section values on the edit box GUICtrlSetData($EditSec, "") $sFilePath = @ScriptDir & "\" & "Txt_Reps.ini" For $i = 1 To 30 $sRead = IniRead($sFilePath, $secn, $i, "") GUICtrlSetData($EditSec, $sRead & @CRLF, 1) Next GUISetState(@SW_SHOW) EndFunc ;==>Filledit Func saveeditedmsg(); save or rename modified section If $secn <> $secno Then $iMsgBoxAnswer = MsgBox(3, "NEW/RENAME", "Press YES to Add this as NEW section" & @CRLF & "Press NO to rename and save this section from " & $secno & "To" & $secn) Select Case $iMsgBoxAnswer = 6 ;YES $secn = $secno save($secn) $secn = GUICtrlRead($SecSel) $secno = $secn Case 7 ;NO $sFilePath = @ScriptDir & "\" & "Txt_Reps.ini" IniRenameSection($sFilePath, $secno, $secn) save($secn) $secn = GUICtrlRead($SecSel) $secno = $secn EndSelect Else $iMsgBoxAnswer = MsgBox(4, "Do you want to save changes to this section", "Save Section: " & $secn) Select Case $iMsgBoxAnswer = 6 ;yes save($secn) EndSelect EndIf EndFunc ;==>saveeditedmsg ;MsgBox(4, "Do you want to add this to Database?",$secn) Func save($ssecn); save edit control to a file and then rewrite modified values by line order. $sFilePathtemp = FileOpen(@ScriptDir & "\" & "tempo.quickrep", $FO_READ + $FO_OVERWRITE + $FO_CREATEPATH + $FO_UTF8) $sFilePath = @ScriptDir & "\" & "Txt_Reps.ini" FileWrite($sFilePathtemp, GUICtrlRead($EditSec)) $sFilePathtemp = FileOpen(@ScriptDir & "\" & "tempo.quickrep", $FO_READ + $FO_UTF8) For $i = 1 To 30 $sRead = FileReadLine($sFilePathtemp, $i) IniWrite($sFilePath, $ssecn, $i, $sRead) Next GUISetState(@SW_SHOW) EndFunc ;==>save And this is with som test msg boxes to know how to get it
      #include <ButtonConstants.au3> #include <ComboConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #include <GuiStatusBar.au3> #include <GuiEdit.au3> #include <MsgBoxConstants.au3> #Region ### START Koda GUI section ### Form=C:\Program Files (x86)\AutoIt3\SciTE\Koda\Forms\QuickRepEditList7.kxf $SecMgr = GUICreate("Sections Manager", 1159, 690) GUISetFont(12, 800, 0, "MS Sans Serif") $EditSec = GUICtrlCreateEdit("", 45, 45, 1090, 644, BitOR($ES_AUTOVSCROLL, $ES_AUTOHSCROLL, $ES_WANTRETURN, $WS_HSCROLL, $ES_NOHIDESEL)) $Edit2 = GUICtrlCreateEdit("", 11, 45, 33, 617, BitOR($ES_RIGHT, $ES_READONLY, $ES_WANTRETURN)) GUICtrlSetData(-1, StringFormat(" 1:\r\n 2:\r\n 3:\r\n 4:\r\n 5:\r\n 6:\r\n 7:\r\n 8:\r\n 9:\r\n10:\r\n11:\r\n12:\r\n13:\r\n14:\r\n15:\r\n16:\r\n17:\r\n18:\r\n19:\r\n20:\r\n21:\r\n22:\r\n23:\r\n24:\r\n25:\r\n26:\r\n27:\r\n28:\r\n29:\r\n30:")) $Label1 = GUICtrlCreateLabel("Select Section:", 7, 13, 126, 24) GUICtrlSetFont(-1, 11, 800, 0, "MS Sans Serif") $Savesec = GUICtrlCreateButton("Save Changes", 375, 7, 129, 33) $NewSec = GUICtrlCreateButton("New Section", 700, 7, 121, 33) $SecDwn = GUICtrlCreateButton("Section Down", 830, 7, 137, 33) $SecUp = GUICtrlCreateButton("Section Up", 980, 7, 129, 33) ;$LineNo = GUICtrlCreateInput("LineNo", 664, 7, 65, 28) $copystrs = GUICtrlCreateButton("*******", 507, 7, 73, 33) GUICtrlSetFont(-1, 12, 800, 0, "MS Sans Serif") $HeavySep = GUICtrlCreateButton("====", 581, 7, 73, 33) GUICtrlSetFont(-1, 12, 800, 0, "MS Sans Serif") Global $SecSel Global $secno Global $secn = "NULLz" Global $sFilePathtemp Global $aArray Global $SecNames Global $secnnew Global $ssecn $SecSel = GUICtrlCreateCombo("", 110, 10, 257, 25, BitOR($CBS_DROPDOWN, $CBS_AUTOHSCROLL)) queysecs() Filledit() GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### $secno=GUICtrlRead($SecSel) $changed=0 While 1 $secn = GUICtrlRead($SecSel) ;If $secn <> $secno and $changed=0 Then ; $secns = $secn ; $changed=1 ;EndIf $nMsg = GUIGetMsg() ;MsgBox(4, "TEST1?", $secn) Switch $nMsg Case $GUI_EVENT_CLOSE saveeditedmsg() Exit Case $SecSel ;MsgBox(4, "TEST?", GUICtrlRead($SecSel)) ;MsgBox(4, "TEST1?", $secns) ;MsgBox(4, "TEST2?", $secn) $secno=GUICtrlRead($SecSel) ;saveeditedmsg() queysecs() Filledit() ;$changed=0 Case $Savesec saveeditedmsg() queysecs() Case $NewSec Case $SecDwn Case $SecUp Case $copystrs ClipPut("**************************************************************************************************************************************************************") Case $HeavySep ClipPut("==============================================================================================================================================================") EndSwitch ; MsgBox(4, "TEST2?", $secn) WEnd Func queysecs();query section names $sFilePath = @ScriptDir & "\" & "Txt_Reps.ini" $aArray = IniReadSectionNames($sFilePath) $SecNames = $aArray[1] ; MsgBox(4, "test3?", $secn) If $secn = "NULLz" Then $secn = $aArray[1] EndIf If Not @error Then For $i = 2 To $aArray[0] $SecNames = $SecNames & "|" & $aArray[$i] Next GUICtrlSetData($SecSel, "", "") GUICtrlSetData($SecSel, $SecNames, $secn) $secno = $secn ;MsgBox(4, "test4?", $secn) EndIf EndFunc ;==>queysecs Func Filledit(); transfer section values on the edit box GUICtrlSetData($EditSec, "") $sFilePath = @ScriptDir & "\" & "Txt_Reps.ini" For $i = 1 To 30 $sRead = IniRead($sFilePath, $secn, $i, "") GUICtrlSetData($EditSec, $sRead & @CRLF, 1) Next GUISetState(@SW_SHOW) EndFunc ;==>Filledit Func saveeditedmsg(); save or rename modified section If $secn <> $secno Then $iMsgBoxAnswer = MsgBox(3, "NEW/RENAME", "Press YES to Add this as NEW section" & @CRLF & "Press NO to rename and save this section from " & $secno & "To" & $secn) Select Case $iMsgBoxAnswer = 6 ;YES $secn = $secno save($secn) $secn = GUICtrlRead($SecSel) $secno = $secn Case 7 ;NO $sFilePath = @ScriptDir & "\" & "Txt_Reps.ini" IniRenameSection($sFilePath, $secno, $secn) save($secn) $secn = GUICtrlRead($SecSel) $secno = $secn EndSelect Else $iMsgBoxAnswer = MsgBox(4, "Do you want to save changes to this section", "Save Section: " & $secn) Select Case $iMsgBoxAnswer = 6 ;yes save($secn) EndSelect EndIf EndFunc ;==>saveeditedmsg ;MsgBox(4, "Do you want to add this to Database?",$secn) Func save($ssecn); save edit control to a file and then rewrite modified values by line order. $sFilePathtemp = FileOpen(@ScriptDir & "\" & "tempo.quickrep", $FO_READ + $FO_OVERWRITE + $FO_CREATEPATH + $FO_UTF8) $sFilePath = @ScriptDir & "\" & "Txt_Reps.ini" FileWrite($sFilePathtemp, GUICtrlRead($EditSec)) $sFilePathtemp = FileOpen(@ScriptDir & "\" & "tempo.quickrep", $FO_READ + $FO_UTF8) For $i = 1 To 30 $sRead = FileReadLine($sFilePathtemp, $i) IniWrite($sFilePath, $ssecn, $i, $sRead) Next GUISetState(@SW_SHOW) EndFunc ;==>save The ini file withthe au3 attached
      This is how I want: when the user changes the combo, the script will check the text combo. In case of changed text it will ask user if I should rename or add it as a new section and then save. If not changed the text of combo it will ask to save only.
      IF NOT possible, Will it possible with _GUICtrlComboBox__GUICtrlComboBoxEx_Create or _GUICtrlComboBoxEx_Create or not
       
      THANK you very much in advance
      QuickSecEdit.zip
    • fatpig
      By fatpig
      can anyone tell me how I stop this from occuring when I place a jpg in my GUI?
      White parts become black. might be transparent, too. Not sure.
      thanks

×