Sign in to follow this  
Followers 0
Madza91

Create ImageList problem

3 posts in this topic

Hello. I want to add PNG image to my ImageList for ListView Items...

But I see that can be only added icons and bitmaps, why isn't possible to add png images? Or if possible, I how to do that?

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

Opt('MustDeclareVars', 1)

$Debug_LV = False ; Check ClassName being passed to ListView functions, set to True and use a handle to another control to see it work

_Main()

Func _Main()
    Local $hImage, $hListView
    
    GUICreate("ListView Set Image List", 400, 300)
    $hListView = GUICtrlCreateListView("", 2, 2, 394, 268)
    GUISetState()

    ; Load images
    $hImage = _GUIImageList_Create(16, 16, 5, 3)
    _GUIImageList_Add($hImage, @DesktopDir & "\favicons.png")
;~  _GUIImageList_AddIcon($hImage, @SystemDir & "\shell32.dll", 131)
    _GUIImageList_Add($hImage, _GUICtrlListView_CreateSolidBitMap($hListView, 0x00FF00, 16, 16))
    _GUIImageList_Add($hImage, _GUICtrlListView_CreateSolidBitMap($hListView, 0x0000FF, 16, 16))
    _GUICtrlListView_SetImageList($hListView, $hImage, 1)

    _GUICtrlListView_AddColumn($hListView, "Column 1", 100)

    _GUICtrlListView_AddItem($hListView, "Item 1", 0)
    _GUICtrlListView_AddItem($hListView, "Item 2", 1)
    _GUICtrlListView_AddItem($hListView, "Item 3", 2)

Do
    Until GUIGetMsg() = $GUI_EVENT_CLOSE
    GUIDelete()
EndFunc   ;==>_Main

*Note: You need file "favicons.png" on Desktop...

Here is one:


[quote name='dbzfanatic' post='609696' date='Nov 26 2008, 08:46 AM']This is a help forum not a "write this for me" forum.[/quote](Sorry for bad English) :)

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

This works for me:

Edit: Better clean up used resources...

#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 <GDIPlus.au3>
#include <WinAPI.au3>

Opt('MustDeclareVars', 1)

$Debug_LV = False ; Check ClassName being passed to ListView functions, set to True and use a handle to another control to see it work

_GDIPlus_Startup ()
_Main()
_GDIPlus_ShutDown ()


Func _Main()
    Local $hImage, $hListView, $hBitmap, $hImagePNG

    GUICreate("ListView Set Image List", 400, 300)
    $hListView = GUICtrlCreateListView("", 2, 2, 394, 268)
    GUISetState()

    ; Load images
    $hImage = _GUIImageList_Create(16, 16, 5, 3)
    _GUIImageList_Add($hImage, @DesktopDir & "\favicons.png")
;~  _GUIImageList_AddIcon($hImage, @SystemDir & "\shell32.dll", 131)
    _GUIImageList_Add($hImage, _GUICtrlListView_CreateSolidBitMap($hListView, 0x00FF00, 16, 16))
    _GUIImageList_Add($hImage, _GUICtrlListView_CreateSolidBitMap($hListView, 0x0000FF, 16, 16))

    $hBitmap = _GDIPlus_BitmapCreateFromFile(@ScriptDir & "\logo.png")
    $hImagePNG = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hBitmap)
    _GUIImageList_Add($hImage, $hImagePNG)
    _GDIPlus_ImageDispose ($hBitmap)
    _WinAPI_DeleteObject ($hImagePNG)

    _GUICtrlListView_SetImageList($hListView, $hImage, 1)
    _GUICtrlListView_AddColumn($hListView, "Column 1", 100)

    _GUICtrlListView_AddItem($hListView, "Item 1", 0)
    _GUICtrlListView_AddItem($hListView, "Item 2", 1)
    _GUICtrlListView_AddItem($hListView, "Item 3", 2)

Do
    Until GUIGetMsg() = $GUI_EVENT_CLOSE
    GUIDelete()
EndFunc   ;==>_Main
Edited by KaFu

Share this post


Link to post
Share on other sites

Hello. I want to add PNG image to my ImageList for ListView Items...

But I see that can be only added icons and bitmaps, why isn't possible to add png images? Or if possible, I how to do that?

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

Opt('MustDeclareVars', 1)

$Debug_LV = False ; Check ClassName being passed to ListView functions, set to True and use a handle to another control to see it work

_Main()

Func _Main()
    Local $hImage, $hListView
    
    GUICreate("ListView Set Image List", 400, 300)
    $hListView = GUICtrlCreateListView("", 2, 2, 394, 268)
    GUISetState()

    ; Load images
    $hImage = _GUIImageList_Create(16, 16, 5, 3)
    _GUIImageList_Add($hImage, @DesktopDir & "\favicons.png")
;~  _GUIImageList_AddIcon($hImage, @SystemDir & "\shell32.dll", 131)
    _GUIImageList_Add($hImage, _GUICtrlListView_CreateSolidBitMap($hListView, 0x00FF00, 16, 16))
    _GUIImageList_Add($hImage, _GUICtrlListView_CreateSolidBitMap($hListView, 0x0000FF, 16, 16))
    _GUICtrlListView_SetImageList($hListView, $hImage, 1)

    _GUICtrlListView_AddColumn($hListView, "Column 1", 100)

    _GUICtrlListView_AddItem($hListView, "Item 1", 0)
    _GUICtrlListView_AddItem($hListView, "Item 2", 1)
    _GUICtrlListView_AddItem($hListView, "Item 3", 2)

Do
    Until GUIGetMsg() = $GUI_EVENT_CLOSE
    GUIDelete()
EndFunc   ;==>_Main

*Note: You need file "favicons.png" on Desktop...

Here is one: http://lh3.ggpht.com/_Vao-ccymw28/Sb4BUtvGdjI/AAAAAAAAAmQ/QcPG2lJJisY/parsix+basic-logo16*16.png

But why just not save the image to BMP format?

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