#include #include #include #include #include "GuiListViewEx.au3" Opt("GUIDataSeparatorChar", Chr(31)) global $g_GUI = GUICreate("Test", 560, 360, 300, 50) $lv = CreateListView() $a = _GUIListViewEx_ReadToArray($lv, 1) $lvx = _GUIListViewEx_Init($lv, $a, 1, 0, True, 192) _GUIListViewEx_MsgRegister _ ( _ False, _ ; NOTIFY True, _ ; MOUSEMOVE True, _ ; LBUTTONUP True _ ; SYSCOMMAND ) $b_new = GUICtrlCreateButton("New", 10, 320, 50, 30) $b_mod = GUICtrlCreateButton("Modify", 80, 320, 50, 30) $b_del = GUICtrlCreateButton("Delete", 150, 320, 50, 30) GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY") GUISetState(@sw_show) HotKeySet("^q", Quit) while True $msg = GUIGetMsg() $index = _GUICtrlListView_GetSelectedIndices($lv) $id = ($index <> "") ? _GUICtrlListView_GetItem($lv, $index)[3] : "" $sel = -1 select ; New case $msg = $b_new: ConsoleWrite(StringFormat(" New [%s]", $id)) local $a[3] = ["foo3", "bar3", "baz3"] if ($index <> "") then _GUIListViewEx_InsertSpec($lvx, $index, $a, False, True) $sel = $index else _GUIListViewEx_InsertSpec($lvx, -1, $a, False, True) $sel = _GUICtrlListView_GetItemCount($lv) - 1 endif ; Modify case $msg = $b_mod: if ($index <> "") then ConsoleWrite(StringFormat("Modify [%s]", $id)) _GUIListViewEx_ChangeItem($lvx, $index, 2, "foo bar") $sel = $index endif ; Delete case $msg = $b_del: if ($index <> "") then ConsoleWrite(StringFormat("Delete [%s]", $id)) _GUIListViewEx_DeleteSpec($lvx, $index) if (_GUICtrlListView_GetItemCount($lv) > 0) then $sel = _Min(Int($index), _GUICtrlListView_GetItemCount($lv) - 1) endif endif ; Close case $msg = $GUI_EVENT_CLOSE Exit endselect $vRet = _GUIListViewEx_EventMonitor() If @error Then ; As far as I know, I'm not particularly concerned with this right now EndIf Switch @extended Case 0 ; No event detected Case 4 ConsoleWrite(StringFormat("Dragged - From:To [%s]", $vRet)) EndSwitch wend ; -------------------------- func Quit() _SendMessage($g_GUI, $WM_CLOSE) endfunc ; -------------------------- func CreateListView() ; Styles $style = BitOR($LVS_DEFAULT, $WS_BORDER) ; $lv = _GUICtrlListView_Create($g_GUI, "", 10, 10, 540, 120, $style) $lv = GUICtrlCreateListView("", 10, 10, 540, 120, $style) $ex_style = BitOR($LVS_EX_FULLROWSELECT, $LVS_EX_BORDERSELECT) _GUICtrlListView_SetExtendedListViewStyle($lv, $ex_style) _GUICtrlListView_InsertColumn($lv, 0, "Foo", 100) _GUICtrlListView_InsertColumn($lv, 1, "Bar", 100) _GUICtrlListView_InsertColumn($lv, 2, "Baz", 100) for $i = 0 to 2 _GUICtrlListView_AddItem($lv, "foo" & $i, $i) _GUICtrlListView_AddSubItem($lv, $i, "bar" & $i, 1) _GUICtrlListView_AddSubItem($lv, $i, "baz" & $i, 2) next return $lv endfunc ; -------------------------- func WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam) local $hdr = DllStructCreate($tagNMHDR, $lParam) local $from = HWnd(DllStructGetData($hdr, "hWndFrom")) local $ctrl = DllStructGetData($hdr, "IDFrom") local $event = DllStructGetData($hdr, "Code") switch $event case $NM_DBLCLK ConsoleWrite('Double click') case $NM_RCLICK ConsoleWrite('Right click') endswitch return _GUIListViewEx_WM_NOTIFY_Handler($hWnd, $iMsg, $wParam, $lParam) endfunc