Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <EditConstants.au3>
- #include <GUIConstantsEx.au3>
- #include <WindowsConstants.au3>
- #include <GuiListView.au3>
- ; En
- $LngTitle = 'Double click the'
- $LngCol = 'Col'
- ; Ru
- ; если русская локализация, то русский язык
- If @OSLang = 0419 Then
- $LngTitle = 'Двойной клик на элементе'
- $LngCol = 'колонка'
- EndIf
- Opt("GUIOnEventMode", 1)
- Global $aElement[2], $hActive, $iInput
- Global $iListView, $hListView, $iExit, $iSaveChange
- $hGUI = GUICreate($LngTitle, 450, 365)
- GUISetOnEvent(-3, '_Exit')
- $iInput = GUICtrlCreateInput("", 0, 0, 0, 0)
- GUICtrlSetState(-1, $GUI_HIDE)
- $iListView = GUICtrlCreateListView($LngCol & ' 1|' & $LngCol & ' 2', 5, 5, 220, 330, BitOR($GUI_SS_DEFAULT_LISTVIEW, $LVS_REPORT, $LVS_SHOWSELALWAYS))
- $hListView = GUICtrlGetHandle(-1)
- ; _GUICtrlListView_SetExtendedListViewStyle ($hListView, $LVS_EX_GRIDLINES, $LVS_EX_GRIDLINES)
- _ListView_Random_Fill($iListView)
- $iListView2 = GUICtrlCreateListView($LngCol & ' 1|' & $LngCol & ' 2', 230, 5, 220, 330, BitOR($GUI_SS_DEFAULT_LISTVIEW, $LVS_REPORT, $LVS_SHOWSELALWAYS))
- $hListView2 = GUICtrlGetHandle(-1)
- _GUICtrlListView_SetExtendedListViewStyle ($hListView, $LVS_EX_GRIDLINES, $LVS_EX_GRIDLINES)
- _ListView_Random_Fill($iListView2)
- GUICtrlCreateButton('Button', 10, 340, 70, 25)
- $iExit = GUICtrlCreateDummy()
- GUICtrlSetOnEvent(-1, "_Exit")
- $iSaveChange = GUICtrlCreateDummy()
- GUICtrlSetOnEvent(-1, "_SaveChange")
- Global $AccelKeys[2][2] = [["{ESC}", $iExit],["{ENTER}", $iSaveChange]]
- GUISetAccelerators($AccelKeys)
- GUISetState()
- GUIRegisterMsg(0x4E, "_WM_NOTIFY")
- GUIRegisterMsg($WM_COMMAND, "WM_COMMAND") ; для скрытия поля ввода при потере фокуса.
- While 1
- Sleep(100000)
- WEnd
- Func _ListView_Random_Fill($iListView)
- Local $item1, $item2
- For $i = 1 To 20
- $item1 = Random(10, 99, 1)
- $item2 = ''
- For $j = 1 To 9
- $item2 &= Chr(Random(65, 90, 1)) ; 192, 255 - Ru
- Next
- GUICtrlCreateListViewItem($item1 & '|' & $item2, $iListView) ; создаём пункты
- Next
- EndFunc
- ; Выводит элемент Input на передний план
- Func _GUICtrlListView_EditItem($hWnd, $iIndex, $iSubItem)
- ;funkey 19.02.2010
- If $iIndex < 0 Then Return
- Local $aPos, $aRect, $iSum = 0
- Local $x, $y, $w, $h
- For $i = 0 To $iSubItem - 1
- $iSum += _GUICtrlListView_GetColumnWidth($hWnd, $i)
- Next
- $aRect = _GUICtrlListView_GetItemRect($hWnd, $iIndex)
- $aPos = ControlGetPos($hGUI, "", $hWnd)
- $x = $iSum + $aPos[0] + $aRect[0]
- $y = $aPos[1] + $aRect[1]
- $w = _GUICtrlListView_GetColumnWidth($hWnd, $iSubItem)
- $h = $aRect[3] - $aRect[1]
- GUICtrlSetPos($iInput, $x - 1, $y + 1, $w + 1, $h + 1)
- GUICtrlSetData($iInput, _GUICtrlListView_GetItemText($hWnd, $iIndex, $iSubItem))
- GUICtrlSetState($iInput, $GUI_SHOW)
- GUICtrlSetState($iInput, $GUI_FOCUS)
- $aElement[0] = $iIndex
- $aElement[1] = $iSubItem
- EndFunc
- ; Сохранить изменения редактирования пункта
- Func _SaveChange()
- Local $sText = GUICtrlRead($iInput)
- If StringInStr($sText, @CR) Or StringInStr($sText, @LF) Then
- If StringLeft($sText, 1) <> '"' And StringInStr(StringMid($sText, 2, StringLen($sText) - 2), '"') Then $sText = StringReplace($sText, '"', "'")
- $sText = '"' & StringReplace($sText, '"', '') & '"'
- EndIf
- _GUICtrlListView_BeginUpdate($hActive)
- _GUICtrlListView_SetItemText($hActive, $aElement[0], $sText, $aElement[1])
- GUICtrlSetState($iInput, $GUI_HIDE)
- _GUICtrlListView_SetColumnWidth($hActive, $aElement[1], -2) ;$LVSCW_AUTOSIZE_USEHEADER
- _GUICtrlListView_EndUpdate($hActive)
- Return $sText ; возвращаем текст, если требуется его использовать после применения
- EndFunc
- Func _WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)
- Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR
- $tNMHDR = DllStructCreate($tagNMHDR, $ilParam)
- $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
- $iIDFrom = DllStructGetData($tNMHDR, "IDFrom")
- $iCode = DllStructGetData($tNMHDR, "Code")
- Switch $hWndFrom
- Case $hListView, $hListView2
- Switch $iCode
- Case $LVN_BEGINSCROLL ; прокрутка ListView
- If $hActive Then
- $hActive = 0
- GUICtrlSetState($iInput, $GUI_HIDE)
- GUICtrlSetData($iInput, '') ; Очищаем поле ввода
- EndIf
- Case $NM_DBLCLK ; двойной клик - редактируем пункт ListView
- Local $tInfo = DllStructCreate($tagNMITEMACTIVATE, $ilParam)
- $hActive = $hWndFrom
- _GUICtrlListView_EditItem($hActive, DllStructGetData($tInfo, "Index"), DllStructGetData($tInfo, "SubItem"))
- ; _GUICtrlListView_EnsureVisible($hActive, DllStructGetData($tInfo, "Index"), True)
- EndSwitch
- EndSwitch
- Return $GUI_RUNDEFMSG
- EndFunc
- Func WM_COMMAND($hWnd, $iMsg, $iwParam, $ilParam)
- #forceref $hWnd, $iMsg
- Local $iIDFrom, $iCode
- $iIDFrom = BitAND($iwParam, 0xFFFF) ; младшее слово
- $iCode = BitShift($iwParam, 16) ; старшее слово
- Switch $iIDFrom
- Case $iInput
- Switch $iCode
- Case $EN_KILLFOCUS
- GUICtrlSetState($iInput, $GUI_HIDE)
- GUICtrlSetData($iInput, '') ; Очищаем поле ввода
- EndSwitch
- EndSwitch
- Return $GUI_RUNDEFMSG
- EndFunc
- Func _Exit()
- Exit
- EndFunc
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement