Jump to content

GUICtrlSetImage()


dRsrb
 Share

Recommended Posts

Hi everybody! :)

I'm new to autoit and again I have a problem, that I don't understand.

I extract the following code segment out of my application:

#include <GUIConstantsEx.au3>
#include <GuiImageList.au3>
#include <GuiListView.au3>

#include <EditConstants.au3>

AutoItSetOption('GUIOnEventMode', 1)
AutoItSetOption('MustDeclareVars', 1)

Global Const $ApplicationTitle = 'Test'
Global $Main
Global $ListView

_Main()

Func _Main()
    
    $Main = GUICreate($ApplicationTitle, 118, 62, -1, -1)
    GUISetOnEvent($GUI_EVENT_CLOSE, '_ExitApplication')
    
    $ListView = GUICtrlCreateListView('Image|Text', 0, 0, 118, 62, $ES_READONLY)
    _GUICtrlListView_SetExtendedListViewStyle($ListView, $LVS_EX_INFOTIP)
    _GUICtrlListView_SetColumnWidth($ListView, 0, 46)
    _GUICtrlListView_SetColumnWidth($ListView, 1, 67)
    _GUICtrlListView_SetSelectedColumn($ListView, 2)
    GUICtrlSetResizing($ListView, BitOR($GUI_DOCKLEFT, $GUI_DOCKTOP, $GUI_DOCKRIGHT, $GUI_DOCKBOTTOM))

    GUISetState(@SW_SHOW)
    
    _TestFunc_SetItem()
    
    _TestFunc()
    
    While True
        Sleep(1000)
    WEnd
    
EndFunc

Func _ExitApplication()

    If @GUI_WINHANDLE = $Main Then
        Exit 0
    EndIf
    
EndFunc

Func _TestFunc_SetItem()
    
    GUICtrlCreateListViewItem('|Test1', $ListView)
    GUICtrlSetImage(-1, '.\red.ico')
    GUICtrlCreateListViewItem('|Test2', $ListView)
    GUICtrlSetImage(-1, '.\red.ico')
    
    MsgBox(0, '', 'Items created')
    
EndFunc

Func _TestFunc()
    
    Local $j, $ListViewItemCount, $ListViewItemText, $ListViewItemAttributes, $Test, $AnyFile
    
    $ListViewItemCount = _GUICtrlListView_GetItemCount($ListView)
    
    For $j = 0 To $ListViewItemCount - 1
        $ListViewItemText = _GUICtrlListView_GetItemTextArray($ListView, $j)
        $ListViewItemAttributes = _GUICtrlListView_GetItem($ListView, $j)
        
        If $ListViewItemText[2] = 'Test1' Then
            _GUICtrlListView_SetItem($ListView, 'Tested', $j, 1)
            
            $Test = GUICtrlSetImage($ListViewItemAttributes[5], '.\green.ico')
            
            MsgBox(262144,'Debug line ~' & @ScriptLineNumber,'Selection:' & @lf & '$Test' & @lf & @lf & 'Return:' & @lf & $Test);### Debug MSGBOX
            
            ExitLoop
        EndIf
    Next
    
    $AnyFile = FileOpenDialog('Select any file', 'C:\', 'All (*.*)', 1)
    MsgBox(262144,'Debug line ~' & @ScriptLineNumber,'Selection:' & @lf & '$AnyFile' & @lf & @lf & 'Return:' & @lf & $AnyFile);### Debug MSGBOX
    
    For $j = 0 To $ListViewItemCount - 1
        $ListViewItemText = _GUICtrlListView_GetItemTextArray($ListView, $j)
        $ListViewItemAttributes = _GUICtrlListView_GetItem($ListView, $j)
        
        If $ListViewItemText[2] = 'Test2' Then
            _GUICtrlListView_SetItem($ListView, 'Tested', $j, 1)
            $Test = GUICtrlSetImage($ListViewItemAttributes[5], '.\green.ico')
            
            If $Test = 0 Then
                _GUICtrlListView_SetItem($ListView, 'Not tested!', $j, 1)
            EndIf
            
            MsgBox(262144,'Debug line ~' & @ScriptLineNumber,'Selection:' & @lf & '$Test' & @lf & @lf & 'Return:' & @lf & $Test);### Debug MSGBOX
            
            ExitLoop
        EndIf
    Next
    
EndFunc

The problem: "GUICtrlSetImage()" doesn't work, if "FileOpenDialog()" is true. This behaviour makes no sense for me. :)

If you cancel the "FileOpenDialog()" "$AnyFile" is false and "GUICtrlSetImage()" works.

You can remove the variable "$AnyFile". It makes no difference.

The two icons for testing are attached.

green.ico

red.ico

Link to comment
Share on other sites

  • Moderators

dRsrb,

The icon changes for me whether I select a file or press cancel within the FileOpenDialog. So GUICtrlSetImage is working in both cases.

Or have I completely misunderstood the problem?

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

Oh, really? :)

This is my result (I can always reproduce it):

1.: Start

Posted Image

2.: Press OK

Posted Image

~Open a file in "FileOpenDialog()"

3.1.: Select and open a file (in my case it's "Öffnen")

Posted Image

4.1.: See the selection

Posted Image

5.1.: "GUICtrlSetImage()" has an error

Posted Image

~Cancel the "FileOpenDialog()"

3.2.: Cancel (in my case it's "Abbrechen")

Posted Image

4.2.: No selection

Posted Image

5.2.: "GUICtrlSetImage()" works fine

Posted Image

Always the same. In the test application as in my "real" application! :)

EDIT:

SciTE

Version 1.77

Oct 23 2008 19:06:08

Edited by dRsrb
Link to comment
Share on other sites

  • Moderators

dRsrb,

I used my own icons because I could not be bothered to download yours, but that should not affect the price of fish.

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

The problem: "GUICtrlSetImage()" doesn't work, if "FileOpenDialog()" is true. This behaviour makes no sense for me. :)

If you cancel the "FileOpenDialog()" "$AnyFile" is false and "GUICtrlSetImage()" works.

This is a known behaviour of FileOpenDialog() & FileSaveDialog().

From the help file remarks

@WorkingDir is changed on successful return.

Because you are using a relative path for your icons
'.\green.ico'

on a return of TRUE your script is now looking for the icon to use in the folder your FileOpen() command was used in.

Change you icon paths to

@ScriptDir & '\green.ico'
and all should work as planned.

Edit: I'm gussing that Melba23 must have used FileOpenDialog to select a file from the folder the script was in.

Edited by ResNullius
Link to comment
Share on other sites

  • Moderators

ResNullius,

Close, but no cigar! By chance I used the full path for the icons when I ran the script, so that is why it worked for me.

Thanks for the explanation.

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

ResNullius,

Close, but no cigar! By chance I used the full path for the icons when I ran the script, so that is why it worked for me.

Thanks for the explanation.

M23

Well then, that makes it difficult to troubleshoot the OP's code if you change it, doesn't it? :)
Link to comment
Share on other sites

  • Moderators

Touché!

Edited by Melba23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

Great! Thank you very much! :)

I spent over 3 hs trying to find the problem, but without success.

I read the remarks, but it was not clear enough for me (@WorkingDir rather @ScriptDir). Now it is. :)

Edited by dRsrb
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

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...