Cancels an item text editing operation
#include <GuiListView.au3>
_GUICtrlListView_CancelEditLabel ( $hWnd )
$hWnd | Control ID/Handle to the control |
_GUICtrlListView_EditLabel, _GUICtrlListView_GetEditControl
#include <GUIConstantsEx.au3>
#include <GuiImageList.au3>
#include <GuiListView.au3>
#include <WindowsConstants.au3>
Global $g_idListView
Example()
Func Example()
Local $hImage, $iTime
GUICreate("ListView Cancel Edit", 392, 322)
$g_idListView = GUICtrlCreateListView("", 2, 2, 394, 268, BitOR($LVS_EDITLABELS, $LVS_REPORT))
GUISetState(@SW_SHOW)
GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")
; Load images
$hImage = _GUIImageList_Create()
_GUIImageList_Add($hImage, _GUICtrlListView_CreateSolidBitMap(GUICtrlGetHandle($g_idListView), 0xFF0000, 16, 16))
_GUIImageList_Add($hImage, _GUICtrlListView_CreateSolidBitMap(GUICtrlGetHandle($g_idListView), 0x00FF00, 16, 16))
_GUIImageList_Add($hImage, _GUICtrlListView_CreateSolidBitMap(GUICtrlGetHandle($g_idListView), 0x0000FF, 16, 16))
_GUICtrlListView_SetImageList($g_idListView, $hImage, 1)
; Add columns
_GUICtrlListView_InsertColumn($g_idListView, 0, "Column 1", 100)
_GUICtrlListView_InsertColumn($g_idListView, 1, "Column 2", 100)
_GUICtrlListView_InsertColumn($g_idListView, 2, "Column 3", 100)
; Add items
_GUICtrlListView_AddItem($g_idListView, "Row 1: Col 1", 0)
_GUICtrlListView_AddSubItem($g_idListView, 0, "Row 1: Col 2", 1)
_GUICtrlListView_AddSubItem($g_idListView, 0, "Row 1: Col 3", 2)
_GUICtrlListView_AddItem($g_idListView, "Row 2: Col 1", 1)
_GUICtrlListView_AddSubItem($g_idListView, 1, "Row 2: Col 2", 1)
_GUICtrlListView_AddItem($g_idListView, "Row 3: Col 1", 2)
; Edit item 0 label with time out
_GUICtrlListView_EditLabel($g_idListView, 0)
$iTime = TimerInit()
; Loop until the user exits.
Do
If _GUICtrlListView_GetEditControl($g_idListView) <> 0 Then
If TimerDiff($iTime) > 3000 Then _GUICtrlListView_CancelEditLabel($g_idListView)
EndIf
Until GUIGetMsg() = $GUI_EVENT_CLOSE
GUIDelete()
EndFunc ;==>Example
Func WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam)
#forceref $hWnd, $iMsg, $wParam
Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR, $hWndListView, $tInfo
$hWndListView = $g_idListView
If Not IsHWnd($g_idListView) Then $hWndListView = GUICtrlGetHandle($g_idListView)
$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_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_ITEMCHANGING ; An item is changing
$tInfo = DllStructCreate($tagNMLISTVIEW, $lParam)
_DebugPrint("$LVN_ITEMCHANGING" & @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"))
Return True ; prevent the change
;Return False ; allow the change
Case $LVN_KEYDOWN ; A key has been pressed
$tInfo = DllStructCreate($tagNMLVKEYDOWN, $lParam)
_DebugPrint("$LVN_KEYDOWN" & @CRLF & "--> hWndFrom:" & @TAB & $hWndFrom & @CRLF & _
"-->IDFrom:" & @TAB & $iIDFrom & @CRLF & _
"-->Code:" & @TAB & $iCode & @CRLF & _
"-->VKey:" & @TAB & DllStructGetData($tInfo, "VKey") & @CRLF & _
"-->Flags:" & @TAB & DllStructGetData($tInfo, "Flags"))
; No return value
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