Sign in to follow this  
Followers 0
knet74

Listview and Pictures

4 posts in this topic

#1 ·  Posted (edited)

Hi

I hope that some of you autoit wizards can lead me in the right direction with a problem that I have with a script.

This is the problem. I have a gui with a listview, and some items i that listview. When I left click on one of the item's, I would like it to show a picture right next to the listview control. How to do this? I have searched the forums & the help file, but I can have missed the solution.

Here is the code so far.

#include <GuiListView.au3>
#include <GuiListBox.au3>
#include <Array.au3>

Global $iLastItem = -1, $ret
Local $nRow = 0, $avArray[1], $item

$MAINGUI = GUICreate("FileList GUI",482,302)


$listview = GUICtrlCreateListView("Filelist",5,40,270,200, -1, $LVS_EX_CHECKBOXES)
_GUICtrlListView_SetColumnWidth($listview, 0, $LVSCW_AUTOSIZE_USEHEADER)

$button = GUICtrlCreateButton("Button",5,260,100,25)

Call ("BuildList")

GUISetState()
Send("{DOWN}")    ; select first item

While 1
    $m = GUIGetMsg()
    Select
    Case $m = $GUI_EVENT_CLOSE
        Exit
    Case $m = $button
        For $i=1 to UBound($item)-1
            If BitOR(GUICtrlRead($item[$i], 1), $GUI_CHECKED) = $GUI_CHECKED Then
                ConsoleWrite("Item " & $i & " - Checked" & @CRLF)
;MsgBox(0,"",$avArray[$i])
            Else
                ConsoleWrite("Item " & $i & " - Unchecked" & @CRLF)
            EndIf
        Next
    EndSelect
WEnd


Func BuildList()
    Dim $item[3]
    _ArrayAdd($avArray, "2440.jpg")
    _ArrayAdd($avArray, "2904.jpg")

;   _ArrayDisplay($avArray, "$avArray AFTER _ArrayAdd()")
    $item[0] = ubound($avArray)-1
    For $x = 1 to UBound($avArray)-1
        If $avArray[$x] <> "" Then
            $item[$x] = GUICtrlCreateListViewItem($avArray[$x],$listview)
        EndIf
    Next    
EndFunc

Hope someone can help me see the way to solve this.

Edited by knet74

Share this post


Link to post
Share on other sites



Hi

I hope that some of you autoit wizards can lead me in the right direction with a problem that I have with a script.

This is the problem. I have a gui with a listview, and some items i that listview. When I left click on one of the item's, I would like it to show a picture right next to the listview control. How to do this? I have searched the forums & the help file, but I can have missed the solution.

Here is the code so far.

#include <GuiListView.au3>
 #include <GuiListBox.au3>
 #include <Array.au3>
 
 Global $iLastItem = -1, $ret
 Local $nRow = 0, $avArray[1], $item
 
 $MAINGUI = GUICreate("FileList GUI",482,302)
 
 
 $listview = GUICtrlCreateListView("Filelist",5,40,270,200, -1, $LVS_EX_CHECKBOXES)
 _GUICtrlListView_SetColumnWidth($listview, 0, $LVSCW_AUTOSIZE_USEHEADER)
 
 $button = GUICtrlCreateButton("Button",5,260,100,25)
 
 Call ("BuildList")
 
 GUISetState()
 Send("{DOWN}")  ; select first item
 
 While 1
     $m = GUIGetMsg()
     Select
     Case $m = $GUI_EVENT_CLOSE
         Exit
     Case $m = $button
         For $i=1 to UBound($item)-1
             If BitOR(GUICtrlRead($item[$i], 1), $GUI_CHECKED) = $GUI_CHECKED Then
                 ConsoleWrite("Item " & $i & " - Checked" & @CRLF)
;MsgBox(0,"",$avArray[$i])
             Else
                 ConsoleWrite("Item " & $i & " - Unchecked" & @CRLF)
             EndIf
         Next
     EndSelect
 WEnd
 
 
 Func BuildList()
     Dim $item[3]
     _ArrayAdd($avArray, "2440.jpg")
     _ArrayAdd($avArray, "2904.jpg")
 
;   _ArrayDisplay($avArray, "$avArray AFTER _ArrayAdd()")
     $item[0] = ubound($avArray)-1
     For $x = 1 to UBound($avArray)-1
         If $avArray[$x] <> "" Then
             $item[$x] = GUICtrlCreateListViewItem($avArray[$x],$listview)
         EndIf
     Next   
 EndFunc

Hope someone can help me see the way to solve this.

This will help I hope.

#include <GuiListView.au3>
#include <GuiListBox.au3>
#include <Array.au3>
#include <windowsconstants.au3>
Global $iLastItem = -1, $ret
Local $nRow = 0, $avArray[1], $item

$MAINGUI = GUICreate("FileList GUI",482,302)


$listview = GUICtrlCreateListView("Filelist",5,40,270,200, -1, $LVS_EX_CHECKBOXES)
_GUICtrlListView_SetColumnWidth($listview, 0, $LVSCW_AUTOSIZE_USEHEADER)

$button = GUICtrlCreateButton("Button",5,260,100,25)

BuildList()
;$pic = GUICtrlCreatePic("2440.jpg"....

GUISetState()
$lastseltxt = ''
GUIRegisterMsg($WM_NOTIFY, "WM_Notify_Events")
Send("{DOWN}")   ; select first item

While 1
    $m = GUIGetMsg()
    Select
    Case $m = $GUI_EVENT_CLOSE
        Exit
    Case $m = $button
        For $i=1 to UBound($item)-1
            If BitOR(GUICtrlRead($item[$i], 1), $GUI_CHECKED) = $GUI_CHECKED Then
                ConsoleWrite("Item " & $i & " - Checked" & @CRLF)
;MsgBox(0,"",$avArray[$i])
            Else
                ConsoleWrite("Item " & $i & " - Unchecked" & @CRLF)
            EndIf
        Next
    EndSelect
WEnd


Func BuildList()
    Dim $item[3]
    _ArrayAdd($avArray, "2440.jpg")
    _ArrayAdd($avArray, "2904.jpg")

;   _ArrayDisplay($avArray, "$avArray AFTER _ArrayAdd()")
    $item[0] = ubound($avArray)-1
    For $x = 1 to UBound($avArray)-1
        If $avArray[$x] <> "" Then
            $item[$x] = GUICtrlCreateListViewItem($avArray[$x],$listview)
        EndIf
    Next    
EndFunc


Func WM_Notify_Events($hWndGUI, $MsgID, $wParam, $lParam)
    If ControlGetFocus('Testing') <> 'Edit1' Then
        #forceref $hWndGUI, $MsgID, $wParam
        Local $tagNMHDR, $event
        $tagNMHDR = DllStructCreate("int;int;int", $lParam);NMHDR (hwndFrom, idFrom, code)
        
        $event = DllStructGetData($tagNMHDR, 3)
        Select
            Case $wParam = $listview

                Select
                    Case $event = $NM_CLICK
                       ;Local $tagNMITEMACTIVATE = DllStructCreate("int;int;int;int;int;int;int;int;int", $lParam)
                       ;$selected = DllStructGetData($tagNMITEMACTIVATE, 4)
                       ;$selcol = DllStructGetData($tagNMITEMACTIVATE, 5)
                    
                        $seltxt = GUICtrlRead(GUICtrlRead($ListView))
                        if StringRight($seltxt,1) = '|' then $seltxt = StringLeft($seltxt,stringLen($seltxt) - 1)
                        ConsoleWrite($seltxt & @CRLF)
                        if $lastseltxt <> $seltxt Then
                        ; GUICtrlSetImage() change the image for a GuiCtrlCreatePic control ?
                             $lastseltxt = $seltxt
                        EndIf        
                        
                EndSelect
        EndSelect
        $tagNMHDR = 0
        $event = 0
        $lParam = 0
        Return $GUI_RUNDEFMSG
    EndIF
EndFunc  ;==>WM_Notify_Events

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

Share this post


Link to post
Share on other sites

GREAT!, Thank you martin for showing how it could be done. I have a little extra question after I looked into the code you made.

When you use the mouse to click on the items in the list it works fine, but if you use the arrows up/down on the keybord, it don't change the picture.

How can that be done?

This will help I hope.

#include <GuiListView.au3>
#include <GuiListBox.au3>
#include <Array.au3>
#include <windowsconstants.au3>
Global $iLastItem = -1, $ret
Local $nRow = 0, $avArray[1], $item

$MAINGUI = GUICreate("FileList GUI",482,302)


$listview = GUICtrlCreateListView("Filelist",5,40,270,200, -1, $LVS_EX_CHECKBOXES)
_GUICtrlListView_SetColumnWidth($listview, 0, $LVSCW_AUTOSIZE_USEHEADER)

$button = GUICtrlCreateButton("Button",5,260,100,25)

BuildList()
;$pic = GUICtrlCreatePic("2440.jpg"....

GUISetState()
$lastseltxt = ''
GUIRegisterMsg($WM_NOTIFY, "WM_Notify_Events")
Send("{DOWN}")  ; select first item

While 1
    $m = GUIGetMsg()
    Select
    Case $m = $GUI_EVENT_CLOSE
        Exit
    Case $m = $button
        For $i=1 to UBound($item)-1
            If BitOR(GUICtrlRead($item[$i], 1), $GUI_CHECKED) = $GUI_CHECKED Then
                ConsoleWrite("Item " & $i & " - Checked" & @CRLF)
;MsgBox(0,"",$avArray[$i])
            Else
                ConsoleWrite("Item " & $i & " - Unchecked" & @CRLF)
            EndIf
        Next
    EndSelect
WEnd


Func BuildList()
    Dim $item[3]
    _ArrayAdd($avArray, "2440.jpg")
    _ArrayAdd($avArray, "2904.jpg")

;   _ArrayDisplay($avArray, "$avArray AFTER _ArrayAdd()")
    $item[0] = ubound($avArray)-1
    For $x = 1 to UBound($avArray)-1
        If $avArray[$x] <> "" Then
            $item[$x] = GUICtrlCreateListViewItem($avArray[$x],$listview)
        EndIf
    Next    
EndFunc


Func WM_Notify_Events($hWndGUI, $MsgID, $wParam, $lParam)
    If ControlGetFocus('Testing') <> 'Edit1' Then
        #forceref $hWndGUI, $MsgID, $wParam
        Local $tagNMHDR, $event
        $tagNMHDR = DllStructCreate("int;int;int", $lParam);NMHDR (hwndFrom, idFrom, code)
        
        $event = DllStructGetData($tagNMHDR, 3)
        Select
            Case $wParam = $listview

                Select
                    Case $event = $NM_CLICK
                      ;Local $tagNMITEMACTIVATE = DllStructCreate("int;int;int;int;int;int;int;int;int", $lParam)
                      ;$selected = DllStructGetData($tagNMITEMACTIVATE, 4)
                      ;$selcol = DllStructGetData($tagNMITEMACTIVATE, 5)
                    
                        $seltxt = GUICtrlRead(GUICtrlRead($ListView))
                        if StringRight($seltxt,1) = '|' then $seltxt = StringLeft($seltxt,stringLen($seltxt) - 1)
                        ConsoleWrite($seltxt & @CRLF)
                        if $lastseltxt <> $seltxt Then
                    ; GUICtrlSetImage() change the image for a GuiCtrlCreatePic control ?
                             $lastseltxt = $seltxt
                        EndIf        
                        
                EndSelect
        EndSelect
        $tagNMHDR = 0
        $event = 0
        $lParam = 0
        Return $GUI_RUNDEFMSG
    EndIF
EndFunc ;==>WM_Notify_Events

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

GREAT!, Thank you martin for showing how it could be done. I have a little extra question after I looked into the code you made.

When you use the mouse to click on the items in the list it works fine, but if you use the arrows up/down on the keybord, it don't change the picture.

How can that be done?

Something like this:

Func WM_Notify_Events($hWndGUI, $MsgID, $wParam, $lParam)


    If ControlGetFocus('Testing') <> 'Edit1' Then
        #forceref $hWndGUI, $MsgID, $wParam
        Local $tagNMHDR, $event
        $tagNMHDR = DllStructCreate("int;int;int", $lParam);NMHDR (hwndFrom, idFrom, code)
        
        $event = DllStructGetData($tagNMHDR, 3)
        Select
            Case $wParam = $listview

                Select
                        
                Case $LVN_ITEMCHANGED
                    $NMLISTVIEW = DllStructCreate($tagNMLISTVIEW, $lParam)
                    If BitAND(DllStructGetData($NMLISTVIEW, "Changed"), $LVIF_STATE) = $LVIF_STATE And _
                        DllStructGetData($NMLISTVIEW, "NewState") <> DllStructGetData($NMLISTVIEW, "OldState") Then 
                            $i = _GUICtrlListView_GetNextItem($ListView) ; current selected
                            $seltxt = _GUICtrlListView_GetItemText($ListView,$i)
                            ConsoleWrite($seltxt & @CRLF)
                    ; GUICtrlSetImage()    change the image for a GuiCtrlCreatePic control ?
                        EndIf
                EndSelect
        EndSelect
        $tagNMHDR = 0
        $event = 0
        $lParam = 0
        Return $GUI_RUNDEFMSG
    EndIF
EndFunc ;==>WM_Notify_Events
Edited by Zedna

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