Function Reference


_GUICtrlListView_GetEditControl

Retrieves the handle to the edit control being used to edit an item's text

#include <GuiListView.au3>
_GUICtrlListView_GetEditControl ( $hWnd )

Parameters

$hWnd Control ID/Handle to the control

Return Value

Success: the handle to the edit control.
Failure: 0.

Remarks

When label editing begins, an edit control is created, positioned, and initialized.
Before displayed, the control sends its parent window an $LVN_BEGINLABELEDIT notification message.

If you want to customize label editing implement a handler for $LVN_BEGINLABELEDITA, $LVN_BEGINLABELEDITAW and have it send an $LVM_GETEDITCONTROL message to the control.
If a label is being edited, the return value will be a handle to the edit control.
Use this handle to customize the edit control by sending the usual EM_XXX messages.

When the user completes or cancels editing, the edit control is destroyed and the handle is no longer valid.
You can subclass the edit control, but you should not destroy it.
To cancel editing, send the control a $WM_CANCELMODE message.

The control item being edited is the currently focused item.
To find an item based on its state, use the $LVM_GETNEXTITEM message.

Related

_GUICtrlListView_CancelEditLabel

Example

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

Global $g_hListView, $g_idMemo

Example()

Func Example()
    Local $hGui, $hImage

    $hGui = GUICreate("ListView Get Edit Control", 400, 300, Default, Default, Default, $WS_EX_CLIENTEDGE)
    $g_hListView = _GUICtrlListView_Create($hGui, "", 2, 2, 394, 118, BitOR($LVS_EDITLABELS, $LVS_REPORT))
    $g_idMemo = GUICtrlCreateEdit("", 2, 124, 396, 174, 0)
    _GUICtrlListView_SetExtendedListViewStyle($g_hListView, BitOR($LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT, $LVS_EX_DOUBLEBUFFER))
    GUISetState(@SW_SHOW)

    ; Load images
    $hImage = _GUIImageList_Create()
    _GUIImageList_Add($hImage, _GUICtrlListView_CreateSolidBitMap(GUICtrlGetHandle($g_hListView), 0xFF0000, 16, 16))
    _GUIImageList_Add($hImage, _GUICtrlListView_CreateSolidBitMap(GUICtrlGetHandle($g_hListView), 0x00FF00, 16, 16))
    _GUIImageList_Add($hImage, _GUICtrlListView_CreateSolidBitMap(GUICtrlGetHandle($g_hListView), 0x0000FF, 16, 16))
    _GUICtrlListView_SetImageList($g_hListView, $hImage, 1)

    ; Add columns
    _GUICtrlListView_AddColumn($g_hListView, "Column 1", 100)
    _GUICtrlListView_AddColumn($g_hListView, "Column 2", 100)
    _GUICtrlListView_AddColumn($g_hListView, "Column 3", 100)

    ; Add items
    _GUICtrlListView_AddItem($g_hListView, "Row 1: Col 1", 0)
    _GUICtrlListView_AddSubItem($g_hListView, 0, "Row 1: Col 2", 1)
    _GUICtrlListView_AddSubItem($g_hListView, 0, "Row 1: Col 3", 2)
    _GUICtrlListView_AddItem($g_hListView, "Row 2: Col 1", 1)
    _GUICtrlListView_AddSubItem($g_hListView, 1, "Row 2: Col 2", 1)
    _GUICtrlListView_AddItem($g_hListView, "Row 3: Col 1", 2)

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

    _GUICtrlListView_EditLabel($g_hListView, 0)
    MemoWrite("Edit Handle: 0x" & Hex(_GUICtrlListView_GetEditControl($g_hListView)) & _
            " IsPtr = " & IsPtr(_GUICtrlListView_GetEditControl($g_hListView)) & " IsHWnd = " & IsHWnd(_GUICtrlListView_GetEditControl($g_hListView)))

    ; 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, $tInfo, $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
                    $tInfo = DllStructCreate($tagNMLVDISPINFO, $lParam)
                    _DebugPrint("$LVN_BEGINLABELEDIT" & @CRLF & "--> hWndFrom:" & @TAB & $hWndFrom & @CRLF & _
                            "-->IDFrom:" & @TAB & $iIDFrom & @CRLF & _
                            "-->Code:" & @TAB & $iCode & @CRLF & _
                            "-->Mask:" & @TAB & DllStructGetData($tInfo, "Mask") & @CRLF & _
                            "-->Item:" & @TAB & DllStructGetData($tInfo, "Item") & @CRLF & _
                            "-->SubItem:" & @TAB & DllStructGetData($tInfo, "SubItem") & @CRLF & _
                            "-->State:" & @TAB & DllStructGetData($tInfo, "State") & @CRLF & _
                            "-->StateMask:" & @TAB & DllStructGetData($tInfo, "StateMask") & @CRLF & _
                            "-->Image:" & @TAB & DllStructGetData($tInfo, "Image") & @CRLF & _
                            "-->Param:" & @TAB & DllStructGetData($tInfo, "Param") & @CRLF & _
                            "-->Indent:" & @TAB & DllStructGetData($tInfo, "Indent") & @CRLF & _
                            "-->GroupID:" & @TAB & DllStructGetData($tInfo, "GroupID") & @CRLF & _
                            "-->Columns:" & @TAB & DllStructGetData($tInfo, "Columns") & @CRLF & _
                            "-->pColumns:" & @TAB & DllStructGetData($tInfo, "pColumns"))
                    Return False ; Allow the user to edit the label
                    ; ;Return True  ; Prevent the user from editing the label
                Case $LVN_COLUMNCLICK ; A column was clicked
                    $tInfo = DllStructCreate($tagNMLISTVIEW, $lParam)
                    _DebugPrint("$LVN_COLUMNCLICK" & @CRLF & "--> hWndFrom:" & @TAB & $hWndFrom & @CRLF & _
                            "-->IDFrom:" & @TAB & $iIDFrom & @CRLF & _
                            "-->Code:" & @TAB & $iCode & @CRLF & _
                            "-->Item:" & @TAB & DllStructGetData($tInfo, "Item") & @CRLF & _
                            "-->SubItem:" & @TAB & DllStructGetData($tInfo, "SubItem") & @CRLF & _
                            "-->NewState:" & @TAB & DllStructGetData($tInfo, "NewState") & @CRLF & _
                            "-->OldState:" & @TAB & DllStructGetData($tInfo, "OldState") & @CRLF & _
                            "-->Changed:" & @TAB & DllStructGetData($tInfo, "Changed") & @CRLF & _
                            "-->ActionX:" & @TAB & DllStructGetData($tInfo, "ActionX") & @CRLF & _
                            "-->ActionY:" & @TAB & DllStructGetData($tInfo, "ActionY") & @CRLF & _
                            "-->Param:" & @TAB & DllStructGetData($tInfo, "Param"))
                    ; No return value
                Case $LVN_ENDLABELEDITA, $LVN_ENDLABELEDITW ; The end of label editing for an item
                    $tInfo = DllStructCreate($tagNMLVDISPINFO, $lParam)
                    If (DllStructGetData($tInfo, "Text") <> 0) Then
                        Local $tBuffer = DllStructCreate("char Text[" & DllStructGetData($tInfo, "TextMax") & "]", DllStructGetData($tInfo, "Text"))
                        _DebugPrint("$LVN_ENDLABELEDIT" & @CRLF & "--> hWndFrom:" & @TAB & $hWndFrom & @CRLF & _
                                "-->IDFrom:" & @TAB & $iIDFrom & @CRLF & _
                                "-->Code:" & @TAB & $iCode & @CRLF & _
                                "-->Mask:" & @TAB & DllStructGetData($tInfo, "Mask") & @CRLF & _
                                "-->Item:" & @TAB & DllStructGetData($tInfo, "Item") & @CRLF & _
                                "-->SubItem:" & @TAB & DllStructGetData($tInfo, "SubItem") & @CRLF & _
                                "-->State:" & @TAB & DllStructGetData($tInfo, "State") & @CRLF & _
                                "-->StateMask:" & @TAB & DllStructGetData($tInfo, "StateMask") & @CRLF & _
                                "-->Text:" & @TAB & DllStructGetData($tBuffer, "Text") & @CRLF & _
                                "-->TextMax:" & @TAB & DllStructGetData($tInfo, "TextMax") & @CRLF & _
                                "-->Image:" & @TAB & DllStructGetData($tInfo, "Image") & @CRLF & _
                                "-->Param:" & @TAB & DllStructGetData($tInfo, "Param") & @CRLF & _
                                "-->Indent:" & @TAB & DllStructGetData($tInfo, "Indent") & @CRLF & _
                                "-->GroupID:" & @TAB & DllStructGetData($tInfo, "GroupID") & @CRLF & _
                                "-->Columns:" & @TAB & DllStructGetData($tInfo, "Columns") & @CRLF & _
                                "-->pColumns:" & @TAB & DllStructGetData($tInfo, "pColumns"))
                        Return True ; If Text is empty the return value is ignored
                    EndIf
                Case $NM_CLICK ; Sent by a list-view control when the user clicks an item with the left mouse button
                    $tInfo = DllStructCreate($tagNMITEMACTIVATE, $lParam)
                    _DebugPrint("$NM_CLICK" & @CRLF & "--> hWndFrom:" & @TAB & $hWndFrom & @CRLF & _
                            "-->IDFrom:" & @TAB & $iIDFrom & @CRLF & _
                            "-->Code:" & @TAB & $iCode & @CRLF & _
                            "-->Index:" & @TAB & DllStructGetData($tInfo, "Index") & @CRLF & _
                            "-->SubItem:" & @TAB & DllStructGetData($tInfo, "SubItem") & @CRLF & _
                            "-->NewState:" & @TAB & DllStructGetData($tInfo, "NewState") & @CRLF & _
                            "-->OldState:" & @TAB & DllStructGetData($tInfo, "OldState") & @CRLF & _
                            "-->Changed:" & @TAB & DllStructGetData($tInfo, "Changed") & @CRLF & _
                            "-->ActionX:" & @TAB & DllStructGetData($tInfo, "ActionX") & @CRLF & _
                            "-->ActionY:" & @TAB & DllStructGetData($tInfo, "ActionY") & @CRLF & _
                            "-->lParam:" & @TAB & DllStructGetData($tInfo, "lParam") & @CRLF & _
                            "-->KeyFlags:" & @TAB & DllStructGetData($tInfo, "KeyFlags"))
                    ; No return value
                Case $NM_DBLCLK ; Sent by a list-view control when the user double-clicks an item with the left mouse button
                    $tInfo = DllStructCreate($tagNMITEMACTIVATE, $lParam)
                    _DebugPrint("$NM_DBLCLK" & @CRLF & "--> hWndFrom:" & @TAB & $hWndFrom & @CRLF & _
                            "-->IDFrom:" & @TAB & $iIDFrom & @CRLF & _
                            "-->Code:" & @TAB & $iCode & @CRLF & _
                            "-->Index:" & @TAB & DllStructGetData($tInfo, "Index") & @CRLF & _
                            "-->SubItem:" & @TAB & DllStructGetData($tInfo, "SubItem") & @CRLF & _
                            "-->NewState:" & @TAB & DllStructGetData($tInfo, "NewState") & @CRLF & _
                            "-->OldState:" & @TAB & DllStructGetData($tInfo, "OldState") & @CRLF & _
                            "-->Changed:" & @TAB & DllStructGetData($tInfo, "Changed") & @CRLF & _
                            "-->ActionX:" & @TAB & DllStructGetData($tInfo, "ActionX") & @CRLF & _
                            "-->ActionY:" & @TAB & DllStructGetData($tInfo, "ActionY") & @CRLF & _
                            "-->lParam:" & @TAB & DllStructGetData($tInfo, "lParam") & @CRLF & _
                            "-->KeyFlags:" & @TAB & DllStructGetData($tInfo, "KeyFlags"))
                    ; No return value
                Case $NM_KILLFOCUS ; The control has lost the input focus
                    _DebugPrint("$NM_KILLFOCUS" & @CRLF & "--> hWndFrom:" & @TAB & $hWndFrom & @CRLF & _
                            "-->IDFrom:" & @TAB & $iIDFrom & @CRLF & _
                            "-->Code:" & @TAB & $iCode)
                    ; No return value
                Case $NM_RCLICK ; Sent by a list-view control when the user clicks an item with the right mouse button
                    $tInfo = DllStructCreate($tagNMITEMACTIVATE, $lParam)
                    _DebugPrint("$NM_RCLICK" & @CRLF & "--> hWndFrom:" & @TAB & $hWndFrom & @CRLF & _
                            "-->IDFrom:" & @TAB & $iIDFrom & @CRLF & _
                            "-->Code:" & @TAB & $iCode & @CRLF & _
                            "-->Index:" & @TAB & DllStructGetData($tInfo, "Index") & @CRLF & _
                            "-->SubItem:" & @TAB & DllStructGetData($tInfo, "SubItem") & @CRLF & _
                            "-->NewState:" & @TAB & DllStructGetData($tInfo, "NewState") & @CRLF & _
                            "-->OldState:" & @TAB & DllStructGetData($tInfo, "OldState") & @CRLF & _
                            "-->Changed:" & @TAB & DllStructGetData($tInfo, "Changed") & @CRLF & _
                            "-->ActionX:" & @TAB & DllStructGetData($tInfo, "ActionX") & @CRLF & _
                            "-->ActionY:" & @TAB & DllStructGetData($tInfo, "ActionY") & @CRLF & _
                            "-->lParam:" & @TAB & DllStructGetData($tInfo, "lParam") & @CRLF & _
                            "-->KeyFlags:" & @TAB & DllStructGetData($tInfo, "KeyFlags"))
                    ;Return 1 ; not to allow the default processing
                    Return 0 ; allow the default processing
                Case $NM_RDBLCLK ; Sent by a list-view control when the user double-clicks an item with the right mouse button
                    $tInfo = DllStructCreate($tagNMITEMACTIVATE, $lParam)
                    _DebugPrint("$NM_RDBLCLK" & @CRLF & "--> hWndFrom:" & @TAB & $hWndFrom & @CRLF & _
                            "-->IDFrom:" & @TAB & $iIDFrom & @CRLF & _
                            "-->Code:" & @TAB & $iCode & @CRLF & _
                            "-->Index:" & @TAB & DllStructGetData($tInfo, "Index") & @CRLF & _
                            "-->SubItem:" & @TAB & DllStructGetData($tInfo, "SubItem") & @CRLF & _
                            "-->NewState:" & @TAB & DllStructGetData($tInfo, "NewState") & @CRLF & _
                            "-->OldState:" & @TAB & DllStructGetData($tInfo, "OldState") & @CRLF & _
                            "-->Changed:" & @TAB & DllStructGetData($tInfo, "Changed") & @CRLF & _
                            "-->ActionX:" & @TAB & DllStructGetData($tInfo, "ActionX") & @CRLF & _
                            "-->ActionY:" & @TAB & DllStructGetData($tInfo, "ActionY") & @CRLF & _
                            "-->lParam:" & @TAB & DllStructGetData($tInfo, "lParam") & @CRLF & _
                            "-->KeyFlags:" & @TAB & DllStructGetData($tInfo, "KeyFlags"))
                    ; No return value
                Case $NM_RETURN ; The control has the input focus and that the user has pressed the ENTER key
                    _DebugPrint("$NM_RETURN" & @CRLF & "--> hWndFrom:" & @TAB & $hWndFrom & @CRLF & _
                            "-->IDFrom:" & @TAB & $iIDFrom & @CRLF & _
                            "-->Code:" & @TAB & $iCode)
                    ; No return value
                Case $NM_SETFOCUS ; The control has received the input focus
                    _DebugPrint("$NM_SETFOCUS" & @CRLF & "--> hWndFrom:" & @TAB & $hWndFrom & @CRLF & _
                            "-->IDFrom:" & @TAB & $iIDFrom & @CRLF & _
                            "-->Code:" & @TAB & $iCode)
                    ; No return value
            EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_NOTIFY

Func _DebugPrint($s_Text, $sLine = @ScriptLineNumber)
    ConsoleWrite( _
            "!===========================================================" & @CRLF & _
            "+======================================================" & @CRLF & _
            "-->Line(" & StringFormat("%04d", $sLine) & "):" & @TAB & $s_Text & @CRLF & _
            "+======================================================" & @CRLF)
EndFunc   ;==>_DebugPrint

; Write a line to the memo control
Func MemoWrite($sMessage)
    GUICtrlSetData($g_idMemo, $sMessage & @CRLF, 1)
EndFunc   ;==>MemoWrite