BuckMaster

Treeview Icon Problems

5 posts in this topic

I've been having some problems adding a icon from a .dll into a treeview,

Does the function _GUICtrlTreeView_SetIcon only allow you to use Shell icons or am i doing something wrong?

My main script is way to large to post up so I've created a short example to illustrate my problem

the resource file is attatched

#include <GUITreeView.au3>
#include <TreeViewConstants.au3>
#include <GUIConstants.au3>

Global $GUITree, $hTree

$hGUI = GUICreate("Example", 500, 500, -1, -1)
GUICtrlCreateLabel("Add Item Type ( 1 - 22 )", 220, 20)
$hCombo = GUICtrlCreateCombo("", 220, 40, 50, 22, 0x0003)
GUICtrlSetData(-1, "1|2|3|4|5|6|7|8|9|10|11|12|13|14|15|16|17|18|19|20|21|22", "1")
$hCreate = GUICtrlCreateButton("Create Tree Item", 280, 39, 100, 22)
$hTree = GUICtrlCreateTreeView( 10, 10, 200, 480, BitOR($TVS_HASBUTTONS, $TVS_HASLINES, $TVS_LINESATROOT, $TVS_DISABLEDRAGDROP, $TVS_SHOWSELALWAYS))
GUISetState()

_GUICtrlTreeView_BeginUpdate($hTree)
$GUITree = _GUICtrlTreeView_Add($hTree, 0, "hGUI")
_GUICtrlTreeView_SetIcon($GUITree, $GUITree, @ScriptDir&"\Resources.dll", 119)
_GUICtrlTreeView_EndUpdate($hTree)

While 1
    $hMsg = GUIGetMsg()
    Switch $hMsg
        Case -3
            Exit
        Case $hCreate
            $hTreeItem = _AddTreeItem("Control Type "&GUICtrlRead($hCombo), GUICtrlRead($hCombo))
            _GUICtrlTreeView_Expand($hTree)
    EndSwitch
WEnd

Func _AddTreeItem($aName, $aType)
    _GUICtrlTreeView_BeginUpdate($hTree)
    $hItem = _GUICtrlTreeView_AddChild($hTree, $GUITree, $aName)
    _GUICtrlTreeView_SetIcon($hTree, $hItem, @ScriptDir&"\Resources.dll", _GetIcon($aType))
    _GUICtrlTreeView_EndUpdate($hTree)
    ConsoleWrite("+ _AddTreeItem("&$aName&", "&$aType&")    Icon # "&_GetIcon($aType)&@CRLF)
    Return $hItem
EndFunc

Func _GetIcon($Type)
    If $Type = 1 Then
        Return 122
    ElseIf $Type = 2 Then
        Return 102
    ElseIf $Type = 3 Then
        Return 121
    ElseIf $Type = 4 Then
        Return 114
    ElseIf $Type = 5 Then
        Return 105
    ElseIf $Type = 6 Then
        Return 129
    ElseIf $Type = 7 Then
        Return 107
    ElseIf $Type = 8 Then
        Return 123
    ElseIf $Type = 9 Then
        Return 111
    ElseIf $Type = 10 Then
        Return 127
    ElseIf $Type = 11 Then
        Return 120
    ElseIf $Type = 12 Then
        Return 128
    ElseIf $Type = 13 Then
        Return 135
    ElseIf $Type = 14 Then
        Return 138
    ElseIf $Type = 15 Then
        Return 126
    ElseIf $Type = 16 Then
        Return 136
    ElseIf $Type = 17 Then
        Return 133
    ElseIf $Type = 18 Then
        Return 124
    ElseIf $Type = 19 Then
        Return 116
    ElseIf $Type = 20 Then
        Return 113
    ElseIf $Type = 21 Then
        Return 118
    ElseIf $Type = 22 Then
        Return 104
    EndIf
EndFunc

Any help would be appreciated :)

Resources.zip

Share this post


Link to post
Share on other sites



#include <GUITreeView.au3>

#include <TreeViewConstants.au3>

#include <GUIConstants.au3>



Global $GUITree, $hTree



$hGUI = GUICreate("Example", 500, 500, -1, -1)

GUICtrlCreateLabel("Add Item Type ( 1 - 22 )", 220, 20)

$hCombo = GUICtrlCreateCombo("", 220, 40, 50, 22, 0x0003)

GUICtrlSetData(-1, "1|2|3|4|5|6|7|8|9|10|11|12|13|14|15|16|17|18|19|20|21|22", "1")

$hCreate = GUICtrlCreateButton("Create Tree Item", 280, 39, 100, 22)

$hTree = GUICtrlCreateTreeView(10, 10, 200, 480, BitOR($TVS_HASBUTTONS, $TVS_HASLINES, $TVS_LINESATROOT, $TVS_DISABLEDRAGDROP, $TVS_SHOWSELALWAYS))

GUISetState()



$GUITree = _GUICtrlTreeView_Add($hTree, 0, "hGUI")

_GUICtrlTreeView_SetIcon($hTree, $GUITree, @ScriptDir & "Resources.dll", -119)

; _GUICtrlTreeView_SetIcon($hTree, $GUITree, "shell32.dll", 39)



While 1

    Switch GUIGetMsg()

        Case -3

            Exit

        Case $hCreate

            $hTreeItem = _AddTreeItem("Control Type " & GUICtrlRead($hCombo), GUICtrlRead($hCombo))

            _GUICtrlTreeView_Expand($hTree)

    EndSwitch

WEnd



Func _AddTreeItem($aName, $aType)

    $hItem = _GUICtrlTreeView_AddChild($hTree, $GUITree, $aName)

    _GUICtrlTreeView_SetIcon($hTree, $hItem, @ScriptDir & "Resources.dll", _GetIcon($aType))

    ; _GUICtrlTreeView_SetIcon($hTree, $hItem, "shell32.dll", _GetIcon($aType))

    Return $hItem

EndFunc



Func _GetIcon($Type)

    Switch $Type

        Case 1

            Return -122

        Case 2

            Return -102

        Case 3

            Return -121

        Case 4

            Return -114

        Case 5

            Return -105

        Case 6

            Return -129

        Case 7

            Return -107

        Case 8

            Return -123

        Case 9

            Return -111

        Case 10

            Return -127

        Case 11

            Return -120

        Case 12

            Return -128

        Case 13

            Return -135

        Case 14

            Return -138

        Case 15

            Return -126

        Case 16

            Return -136

        Case 17

            Return -133

        Case 18

            Return -124

        Case 19

            Return -116

        Case 20

            Return -113

        Case 21

            Return -118

        Case 22

            Return -104

    EndSwitch

EndFunc

Share this post


Link to post
Share on other sites

AZJIO Thank You very much, i would have never of thought to make it negative.

BuckMaster

Share this post


Link to post
Share on other sites

I'm trying to set a treeview icon using an icon from the Web, like this:

InetGet("https://www.fastmail.com/static/favicons/icon-64x64.png", @ScriptDir & "fastmail.png", 1, 1)
If Not FileExists(@ScriptDir & "fastmail.png") Then
    MsgBox(0, "Test", "Whoops! " & @ScriptDir & "\fastmail.png does not exist.")
EndIf

$SetIcon = _GUICtrlTreeView_SetIcon($Tree, $L2_item, @ScriptDir & "fastmail.png")
If $SetIcon = "False" Then
    MsgBox(0, "Test", "Whoops! Icon not set.")
EndIf

But it's not setting it. It does save the file, though.

I think the problem is that _GUICtrlTreeView_SetIcon() expects to retrieve an icon from an .exe or .dll rather than directly from an image file, like GUICtrlSetImage() does when setting an icon for a listview item or a button. But I don't know how to do that. Any idea? I'm building a treeview that shows bookmarks, and I want to display the icon for each bookmark.

Share this post


Link to post
Share on other sites

Icon <> Png

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

    • WoodGrain
      By WoodGrain
      Hi All,
      I'm using UseTraySetIcon("shell32.dll", xx) to set my tray icon to a specific icon while running, is there a way I can specify this icon when I compile my script into an exe so my exe icon is the same?
      Thanks!
    • nacerbaaziz
      By nacerbaaziz
      Hi guys
      I have an inquiry please
      I want an example of how to add an icon file to the compiled autoit file and how to use it in GUICtrlCreateIcon
      Preferably in a separate list within the resourceFor example myIcons
      I hope my request is clear and I hope you will help me solve this problem
      Because I found an example in the help files but I did not understand the method well
    • corgano
      By corgano
      I can't explain easily what i want to do, so i made a picture:

      What i want to do is to specify a treeview item, and then be able to move it right to be a child of the previous item, or left to do the opposite (make a child into a sibling). I also want to move and child items of the target with it, like in the bottom half of the above image depicts. However I didn't see any functions in the help file to move items around. All i want is a button that when pressed, makes the selected item and any of selected item's children move one layer to the right / left. Does anyone know how?

      Edit: something along the lines of _GUICtrlTreeView_Level but SET level
    • amimemeami
      By amimemeami
      I have a simple script that switches between IE and Chrome for the default browser, I even made a custom half chrome half ie icon for it. Question is, can I have the script toggle between two icons to signify the last browser it changed to? I would have the active browser's half of the icon in color, and inactive half grey scale. As a workaround, I put link next to it, and refresh the icon cache after it runs. 
      #RequireAdmin #Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_Icon=..\..\Icons\IE_Chrome.ico #AutoIt3Wrapper_Outfile=..\..\..\..\Users\dmking\Desktop\Browser Switcher.exe #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** $sCurrentDefault = RegRead('HKCU\Software\Microsoft\Windows\Shell\Associations\UrlAssociations\http\UserChoice',"ProgId") if $sCurrentDefault = "IE.HTTP" Then     ChromeDefault() Else     IEDefault() EndIf ;~ Run("ie4uinit.exe -ClearIconCache") Run("C:\Windows\System32\ie4uinit.exe -ClearIconCache") Func IEDefault()     RegWrite("HKCU\Software\Microsoft\Windows\Shell\Associations\UrlAssociations\ftp\UserChoice","Progid","REG_SZ","IE.FTP")     RegWrite("HKCU\Software\Microsoft\Windows\Shell\Associations\UrlAssociations\http\UserChoice","Progid","REG_SZ","IE.HTTP")     RegWrite("HKCU\Software\Microsoft\Windows\Shell\Associations\UrlAssociations\https\UserChoice","Progid","REG_SZ","IE.HTTPS")     RegWrite("HKCU\Software\Clients\StartMenuInternet","","REG_SZ","IEXPLORE.EXE") EndFunc Func ChromeDefault()     RegWrite("HKCU\Software\Microsoft\Windows\Shell\Associations\UrlAssociations\ftp\UserChoice","Progid","REG_SZ","ChromeHTML")     RegWrite("HKCU\Software\Microsoft\Windows\Shell\Associations\UrlAssociations\http\UserChoice","Progid","REG_SZ","ChromeHTML")     RegWrite("HKCU\Software\Microsoft\Windows\Shell\Associations\UrlAssociations\https\UserChoice","Progid","REG_SZ","ChromeHTML")     RegWrite("HKCU\Software\Clients\StartMenuInternet","","REG_SZ","Google Chrome") EndFunc  
    • Tjalve
      By Tjalve
      Hi everyone. Im creating a GUI for an application. Im usinga  treeview item and i want to add some information to the side of the treeview based on what cilditem you are pressing. For the moment i have a "get info" button that works. But that means that you have to select your child in the treeview, and then press a button to gte the info. I want the info to be visable as soon as you select it.
      With uther controls you can just add it to the loop but it doesnt seem to work with tyhe UDF version of the treeview control. Is there anything I can do?
      #include <GUIConstantsEx.au3> #include <GuiTreeView.au3> #include <MsgBoxConstants.au3> #include <WindowsConstants.au3> ;~ Create GUI dim $guilabel[7] local $currentlevel = 1 Local $hGui = GUICreate( "Grejs", 1000, 500, 600, 300, BitOR( $GUI_SS_DEFAULT_GUI, $WS_MAXIMIZEBOX, $WS_SIZEBOX ) ) Local $iBorderWidth = 4, $aPos = WinGetClientSize( $hGui ) $idTV = _GUICtrlTreeView_Create($hGui, $iBorderWidth, $iBorderWidth, $aPos[0]-2*$iBorderWidth-400, $aPos[1]-2*$iBorderWidth-30 ) $root_level = _GUICtrlTreeView_Add($idTV,0,"Root") $item1 = _GUICtrlTreeView_AddChild($idTV, $root_level, "child1") $item2 = _GUICtrlTreeView_AddChild($idTV, $root_level, "child2") $item3 = _GUICtrlTreeView_AddChild($idTV, $root_level, "child3") ;~ Start Gui GUISetState() While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop Case $idTV MsgBox(0,"","") EndSwitch WEnd GUIDelete($hGui) Exit In this example, i want the msgbox to appear whenevr i select something in the treeview. It ios not my full code, but its an example of the problam i have. Help is much appritiated
      /G