Jump to content

Recommended Posts

Posted

I am trying to do some work on editing labels in a ListView. It's going to be related to file system stuff such as filenames and folders. So I want to disallow a label edit if the rename (label edit) is blank. I will likely have to check for other things as well such as characters that are not allowed in a filename or folder name.

Problem:

The example that I am following uses DllStructCreate and DllStructGetData to retrieve the Text of the changed label name to determine whether it is blank and so on. The problem with the example is that it is only returning the very first character. That, at the very least, allows me to check if the new text is blank or not. But it would not allow me to parse it any further to determine other filename or folder name character rules and such.

I assume that the problem is in the $tBuffer line where it is only pulling the first character. My goal would be to retrieve the full text of the new label text to determine further course of action.

Thank you so much for any assistance with this. :)

Example:

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

Global $g_hListView, $idListview

Example()

Func Example()
    Local $hGui

    $hGui = GUICreate("ListView Edit Labels", 400, 300, Default, Default, Default, $WS_EX_CLIENTEDGE)
    $idListview = GUICtrlCreateListView("Column", 0, 0, 400, 300, BitOR($LVS_SHOWSELALWAYS, $LVS_EDITLABELS), BitOR($LVS_EX_FULLROWSELECT, $LVS_EX_DOUBLEBUFFER))
    $g_hListView = GUICtrlGetHandle($idListview)
    GUISetState(@SW_SHOW)

    ; Add items
    GUICtrlCreateListViewItem("item1", $idListview)
    GUICtrlCreateListViewItem("item2", $idListview)
    GUICtrlCreateListViewItem("item3", $idListview)

    ; Monitor the WM_NOTIFY message.
    GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")

    ; Loop until the user exits.
    Do
    Until GUIGetMsg() = $GUI_EVENT_CLOSE
    GUIDelete()
EndFunc   ;==>Example

Func WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam)
    #forceref $hWnd, $iMsg, $wParam
    Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR, $tText, $hWndListView = $g_hListView
    If Not IsHWnd($g_hListView) Then $hWndListView = GUICtrlGetHandle($g_hListView)

    $tNMHDR = DllStructCreate($tagNMHDR, $lParam)
    $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
    $iIDFrom = DllStructGetData($tNMHDR, "IDFrom")
    $iCode = DllStructGetData($tNMHDR, "Code")
    Switch $hWndFrom
        Case $hWndListView
            Switch $iCode
                Case $LVN_BEGINLABELEDITA, $LVN_BEGINLABELEDITW ; Start of label editing for an item
                    Return False ; Allow the user to edit the label
                Case $LVN_ENDLABELEDITA, $LVN_ENDLABELEDITW ; The end of label editing for an item
                    $tText = DllStructCreate($tagNMLVDISPINFO, $lParam)
                    Local $tBuffer = DllStructCreate("char Text[" & DllStructGetData($tText, "TextMax") & "]", DllStructGetData($tText, "Text"))
                    Local $sTextRet = DllStructGetData($tBuffer, "Text")
                    ConsoleWrite("text after: " & DllStructGetData($tBuffer, "Text") & @CRLF)
                    If $sTextRet <> "" Then
                        Return True ; allow label edit
                    Else
                        Return False ; disallow label edit since text was blank
                    EndIf
            EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_NOTIFY

 

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
×
×
  • Create New...