#include <GuiConstantsEx.au3>
#include <GuiListView.au3>
#include <WindowsConstants.au3>
#include <EditConstants.au3>
$Gui = GUICreate("Кликайте по элементам в ListView, нажмите F2", 550, 320)
$ListView = GUICtrlCreateListView("кол1 |кол2|кол3 ", 2, 2, 199, 88, $LVS_EDITLABELS)
$item1 = GUICtrlCreateListViewItem("пункт 1|1111|1 в кол 3", $ListView)
$item2 = GUICtrlCreateListViewItem("пункт 2|2222|2 в кол 3", $ListView)
$item3 = GUICtrlCreateListViewItem("пункт 3|3333|3 в кол 3", $ListView)
Global $hListView = GUICtrlGetHandle($ListView)
$hEdit = GUICtrlCreateEdit('', 2, 95, 545, 222, $ES_AUTOVSCROLL + $WS_VSCROLL + $ES_NOHIDESEL + $ES_WANTRETURN)
GUICtrlSetBkColor(-1, 0xfffbd7)
GUISetState()
GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")
Do
Until GUIGetMsg() = $GUI_EVENT_CLOSE
GUIDelete()
Func WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam)
#forceref $hWnd, $iMsg, $wParam
Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR, $tInfo
$tNMHDR = DllStructCreate($tagNMHDR, $lParam)
$hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
$iIDFrom = DllStructGetData($tNMHDR, "IDFrom")
$iCode = DllStructGetData($tNMHDR, "Code")
Switch $hWndFrom
Case $hListView
Switch $iCode
Case $NM_RCLICK ; правый клик мышкой по пункту
$tInfo = DllStructCreate($tagNMITEMACTIVATE, $lParam)
GUICtrlSetData($hEdit, _
"$NM_RCLICK" & @TAB & "одинарный клик ПРАВОЙ кнопкой мыши" & @CRLF & _
"дескриптор:" & @TAB & $hWndFrom & @CRLF & _
"идентификатор:" & @TAB & $iIDFrom & @TAB & "(порядковый номер элемента в GUI)" & @CRLF & _
"код клика:" & @TAB & $iCode & @TAB & "(определяет правой или левой, двойной или одинарный клик мыши)" & @CRLF & _
"№ пункта:" & @TAB & DllStructGetData($tInfo, "Index") & @TAB & "(номер строки, отсчёт от 0, -1 пустое пространство)" & @CRLF & _
"№ колонки:" & @TAB & DllStructGetData($tInfo, "SubItem") & @TAB & "(отсчёт от 0)" & @CRLF & _
"удерж. клавиша:" & @TAB & DllStructGetData($tInfo, "KeyFlags") & @TAB & "(0=ничего; 1=Alt, 2=Ctrl, 4=Shift, 3,5,6,7 - комбинации)")
EndSwitch
EndSwitch
Return $GUI_RUNDEFMSG
EndFunc ;==>WM_NOTIFY
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GuiListView.au3>
Opt("GUIOnEventMode", 1)
Global $aElement[2], $hActive, $iInput
Global $iListView, $hListView, $dummy1, $dummy2
$hGUI = GUICreate('', 450, 360)
GUISetOnEvent(-3, '_Exit')
$iInput = GUICtrlCreateInput("", 0, 0, 0, 0)
GUICtrlSetState(-1, $GUI_HIDE)
$iListView = GUICtrlCreateListView('Col 1|Col 2', 5, 5, 440, 330, BitOR($GUI_SS_DEFAULT_LISTVIEW, $LVS_REPORT, $LVS_SHOWSELALWAYS))
$hListView = GUICtrlGetHandle(-1)
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
GUISetState()
GUIRegisterMsg(0x4E, "_WM_NOTIFY")
While 1
Sleep(100000)
WEnd
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
Switch $iCode
Case $NM_CLICK ; двойной клик - редактируем пункт ListView
Local $tInfo = DllStructCreate($tagNMITEMACTIVATE, $ilParam)
;ToolTip(_GUICtrlListView_GetItemText($hListView, DllStructGetData($tInfo, "Index"), DllStructGetData($tInfo, "SubItem")))
MsgBox(0,"", _GUICtrlListView_GetItemText($hListView, DllStructGetData($tInfo, "Index"), DllStructGetData($tInfo, "SubItem")) & ". Row " & _
DllStructGetData($tInfo, "Index") & ". Column " & DllStructGetData($tInfo, "SubItem"))
EndSwitch
EndSwitch
Return $GUI_RUNDEFMSG
EndFunc
Func _Exit()
Exit
EndFunc
#include <MsgBoxConstants.au3>
#include <GUIConstantsEx.au3>
#include <GUIListView.au3>
#include <GUIMenu.au3>
_Example()
Func _Example()
Local $hGUI = GUICreate("ListView & ContextMenu", 500, 500)
Local $idLV = GUICtrlCreateListView("Ст. 0|Ст. 1|Ст. 2", 5, 5, 490, 490)
Local $hLV = GUICtrlGetHandle(-1)
For $i = 0 To 20
GUICtrlCreateListViewItem("..." & $i & "|..." & $i & "|..." & $i, $idLV)
Next
For $i = 0 To _GUICtrlListView_GetColumnCount($idLV) - 1
_GUICtrlListView_SetColumnWidth($idLV, $i, 100)
Next
Local $idMenu = GUICtrlCreateContextMenu(GUICtrlCreateDummy())
Local $hMenu = GUICtrlGetHandle(-1)
Local $idMenItRow = GUICtrlCreateMenuItem("Строка", $idMenu)
Local $idMenItCol = GUICtrlCreateMenuItem("Столбец", $idMenu)
Local $idMenItText = GUICtrlCreateMenuItem("Текст", $idMenu)
GUISetState()
Local $aHitTest = _GUICtrlListView_SubItemHitTest($hLV)
While 1
Switch GUIGetMsg()
Case $GUI_EVENT_CLOSE
Exit
Case $GUI_EVENT_SECONDARYDOWN
$aHitTest = _GUICtrlListView_SubItemHitTest($hLV)
If $aHitTest[0] <> -1 Then _GUICtrlMenu_TrackPopupMenu($hMenu, $hGUI)
Case $idMenItRow
MsgBox($MB_TOPMOST + $MB_ICONINFORMATION, Default, $aHitTest[0])
Case $idMenItCol
MsgBox($MB_TOPMOST + $MB_ICONINFORMATION, Default, $aHitTest[1])
Case $idMenItText
MsgBox($MB_TOPMOST + $MB_ICONINFORMATION, Default, _GUICtrlListView_GetItemText($idLV, $aHitTest[0], $aHitTest[1]))
EndSwitch
WEnd
EndFunc ;==>_Example
#include <MsgBoxConstants.au3>
#include <WindowsConstants.au3>
#include <GUIConstantsEx.au3>
#include <GUIListView.au3>
#include <GUIMenu.au3>
Global $g_hGUI, $g_idLV, $g_hMenu, $g_aRClick[2]
_Example()
Func _Example()
$g_hGUI = GUICreate("ListView & ContextMenu", 500, 500)
$g_idLV = GUICtrlCreateListView("Ст. 0|Ст. 1|Ст. 2", 5, 5, 490, 490)
For $i = 0 To 20
GUICtrlCreateListViewItem("..." & $i & "|..." & $i & "|..." & $i, $g_idLV)
Next
For $i = 0 To _GUICtrlListView_GetColumnCount($g_idLV) - 1
_GUICtrlListView_SetColumnWidth($g_idLV, $i, 100)
Next
Local $idMenu = GUICtrlCreateContextMenu(GUICtrlCreateDummy())
$g_hMenu = GUICtrlGetHandle(-1)
Local $idMenItRow = GUICtrlCreateMenuItem("Строка", $idMenu)
Local $idMenItCol = GUICtrlCreateMenuItem("Столбец", $idMenu)
Local $idMenItText = GUICtrlCreateMenuItem("Текст", $idMenu)
GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")
GUISetState()
While 1
Switch GUIGetMsg()
Case $GUI_EVENT_CLOSE
Exit
Case $idMenItRow
MsgBox($MB_TOPMOST + $MB_ICONINFORMATION, Default, $g_aRClick[0])
Case $idMenItCol
MsgBox($MB_TOPMOST + $MB_ICONINFORMATION, Default, $g_aRClick[1])
Case $idMenItText
MsgBox($MB_TOPMOST + $MB_ICONINFORMATION, Default, _GUICtrlListView_GetItemText($g_idLV, $g_aRClick[0], $g_aRClick[1]))
EndSwitch
WEnd
EndFunc ;==>_Example
Func WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam)
Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR, $tInfo
$tNMHDR = DllStructCreate($tagNMHDR, $lParam)
$hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
$iIDFrom = DllStructGetData($tNMHDR, "IDFrom")
$iCode = DllStructGetData($tNMHDR, "Code")
Switch $iIDFrom
Case $g_idLV
Switch $iCode
Case $NM_RCLICK
$tInfo = DllStructCreate($tagNMITEMACTIVATE, $lParam)
$g_aRClick[0] = DllStructGetData($tInfo, "Index")
$g_aRClick[1] = DllStructGetData($tInfo, "SubItem")
If $g_aRClick[0] <> -1 Then _GUICtrlMenu_TrackPopupMenu($g_hMenu, $g_hGUI)
EndSwitch
EndSwitch
Return $GUI_RUNDEFMSG
EndFunc ;==>WM_NOTIFY