Sign in to follow this  
Followers 0
Lupo73

ListView item editing doesn't work

4 posts in this topic

I'm trying to implement a listview item editing feature, but it doesn't work fine. The problem is that I'm integrating this feature with a context menu that appears on item right-click, so I can't use the WM_NOTIFY function reported in _GUICtrlListView_EditLabel (I have modified it because it didn't allow me to detect if an item was selected or not). This is the code, that still have problems because allow to edit items but don't save them:

Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)
    #forceref $hWnd, $iMsg, $iwParam
    Local $tNMITEMACTIVATE = DllStructCreate($tagNMITEMACTIVATE, $ilParam)
    Local $hWndFrom = HWnd(DllStructGetData($tNMITEMACTIVATE, 'hWndFrom'))
    Local $Index = DllStructGetData($tNMITEMACTIVATE, 'Index')
    Local $Code = DllStructGetData($tNMITEMACTIVATE, 'Code')
    
    Switch $hWndFrom
        Case $hListView
            Switch $Code
                Case $LVN_BEGINLABELEDITA
                    Local $tInfo = DllStructCreate($tagNMLVDISPINFO, $ilParam)
                    Return False
                    
                Case $LVN_ENDLABELEDITA
                    Local $tInfo = DllStructCreate($tagNMLVDISPINFO, $ilParam)
                    Local $tBuffer = DllStructCreate("char Text[" & DllStructGetData($tInfo, "TextMax") & "]", DllStructGetData($tInfo, "Text"))
                    If StringLen(DllStructGetData($tBuffer, "Text")) Then Return True
                    
                Case $NM_RCLICK
                    GUICtrlSendToDummy($Dummy, $Index)
                    Return 0
                    
            EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc


Func Customize($profiles)
    Local $cust, $sel, $bt1, $bt2, $bt3, $bt4, $bt5, $close, $ListView, $item, $Menu, $hMenu, $tp, $tem, $decision
    $cust = GUICreate("Customize Profiles", 286, 202, -1, -1, -1, $WS_EX_TOOLWINDOW, $hGUI)
    
    $Dummy = GUICtrlCreateDummy()
    $Menu = GUICtrlCreateContextMenu($Dummy)
    $bt1 = GUICtrlCreateMenuItem("Create new", $Menu)
    GUICtrlCreateMenuItem("", $Menu)
    $bt2 = GUICtrlCreateMenuItem("Rename", $Menu)
    $bt3 = GUICtrlCreateMenuItem("Set image", $Menu)
    $bt4 = GUICtrlCreateMenuItem("Set size", $Menu)
    GUICtrlCreateMenuItem("", $Menu)
    $bt5 = GUICtrlCreateMenuItem("Remove", $Menu)
    
    $ListView = GUICtrlCreateListView("Profile|Image|Size", 8, 8, 270, 155, BitOr($LVS_NOSORTHEADER, $LVS_EDITLABELS, $LVS_REPORT, $LVS_SINGLESEL))
    $hListView = GUICtrlGetHandle($ListView)
    _GUICtrlListView_SetExtendedListViewStyle($hListView, BitOr($LVS_EX_DOUBLEBUFFER, $LVS_EX_FULLROWSELECT, $LVS_EX_GRIDLINES, $LVS_EX_INFOTIP))
    _GUICtrlListView_SetColumnWidth($hListView, 0, 100)
    _GUICtrlListView_SetColumnWidth($hListView, 1, 100)
    _GUICtrlListView_SetColumnWidth($hListView, 2, 60)
    $close = GUICtrlCreateButton("OK", 143-35, 170, 70, 24)
    
    For $i = 1 To $profiles[0]
        $item = _GUICtrlListView_AddItem($hListView, $profiles[$i])
        $tp = IniRead($PrDir & "\" & $profiles[$i] & ".ini", "Target", "Image", "")
        If $tp = "" Then $tp = $ImDef
        _GUICtrlListView_AddSubItem($hListView, $item, $tp, 1)
        $tp = IniRead($PrDir & "\" & $profiles[$i] & ".ini", "Target", "SizeX", "")
        If $tp = "" Then $tp = "64"
        $temp = $tp
        $tp = IniRead($PrDir & "\" & $profiles[$i] & ".ini", "Target", "SizeY", "")
        If $tp = "" Then $tp = "64"
        $temp = $temp & "x" & $tp
        _GUICtrlListView_AddSubItem($hListView, $item, $temp, 2)
    Next
    
    GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")
    GUISetState()
    $hMenu = GUICtrlGetHandle($Menu)
    
    While 1
        $sel = GUIGetMsg()
        Switch $sel
            Case $Dummy
                $tem = GUICtrlRead($Dummy)
                If $tem >= 0 Then
                    GUICtrlSetState($bt1, $GUI_DISABLE)
                    GUICtrlSetState($bt2, $GUI_ENABLE)
                    GUICtrlSetState($bt3, $GUI_ENABLE)
                    GUICtrlSetState($bt4, $GUI_ENABLE)
                    GUICtrlSetState($bt5, $GUI_ENABLE)
                    $temp = _GUICtrlListView_GetItemText($hListView, $tem, 0)
                Else
                    GUICtrlSetState($bt1, $GUI_ENABLE)
                    GUICtrlSetState($bt2, $GUI_DISABLE)
                    GUICtrlSetState($bt3, $GUI_DISABLE)
                    GUICtrlSetState($bt4, $GUI_DISABLE)
                    GUICtrlSetState($bt5, $GUI_DISABLE)
                EndIf
                _GUICtrlMenu_TrackPopupMenu($hMenu, $cust)
                
            Case $bt1
                ; function not implemented yet
                
            Case $bt2
                _GUICtrlListView_EditLabel($hListView, $tem)
                
            Case $bt3
                $tp = FileOpenDialog("Select target image", $ImDir & "\", "Image (*.gif)", 1)
                If Not @error Then
                    If StringInStr($tp, $ImDir) Then
                        $tp = StringTrimLeft($tp, StringLen($ImDir) + 1)
                        IniWrite($PrDir & "\" & $temp & ".ini", "Target", "Image", $tp)
                        _GUICtrlListView_SetItemText($hListView, $tem, $tp, 1)
                    Else
                        MsgBox(0x40000, "Image not correct", "The target image must be placed in this directory:" & @LF & $ImDir)
                    EndIf
                EndIf
                
            Case $bt4
                ; function not implemented yet
                
            Case $bt5
                $decision = MsgBox(0x40004, "Remove Selected Profile", 'Are you sure to remove selected profile?')
                If $decision = 6 Then
                    FileDelete($PrDir & "\" & $temp & ".ini")
                    If $temp = IniRead($sIni, "General", "Profile", "Default") Then
                        IniWrite($sIni, "General", "Profile", "Default")
                        $sIniPr = $PrDir & "\Default.ini"
                        If Not FileExists($PrDir) Then DirCreate($PrDir)
                        If Not FileExists($sIniPr) Then
                            ; create the default profile
                            IniWriteSection($sIniPr, "Target", "Image=" & $ImDef & @LF & "SizeX=64" & @LF & "SizeY=64")
                            IniWriteSection($sIniPr, "Patterns", "")
                        EndIf
                    EndIf
                    _GUICtrlListView_DeleteItem($hListView, $tem)
                EndIf
                
            Case $close, $GUI_EVENT_CLOSE
                ExitLoop
            
            EndSwitch
    WEnd
    GUIDelete($cust)
    Return ListProfiles()
EndFunc

SFTPEx, AutoCompleteInput_DateTimeStandard(), _ImageWriteResize()_GUIGraduallyHide(): some AutoIt functions.

Lupo PenSuite: all-in-one and completely free selection of portable programs and games.

DropIt: a personal assistant to automatically manage your files.

ArcThemALL!: application to multi-archive your files and folders.

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Finally I resolved the issue.. I missed $LVN_BEGINLABELEDITW in WM_NOTIFY :D

Now I have problems to find the text of the item edited, at the end of the editing (because the edit function returns immediately and so I can't read it after _GUICtrlListView_EditLabel). How can I find it? thanks!

Edited by Lupo73

SFTPEx, AutoCompleteInput_DateTimeStandard(), _ImageWriteResize()_GUIGraduallyHide(): some AutoIt functions.

Lupo PenSuite: all-in-one and completely free selection of portable programs and games.

DropIt: a personal assistant to automatically manage your files.

ArcThemALL!: application to multi-archive your files and folders.

Share this post


Link to post
Share on other sites

Now I have problems to find the text of the item edited, at the end of the editing (because the edit function returns immediately and so I can't read it after _GUICtrlListView_EditLabel). How can I find it? thanks!

Use _GUICtrlListView_GetEditControl() to get the handle of the edit control itself and use that.

:D


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

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