请教怎么使用鼠标事件删除列表行[已解决]
本帖最后由 cdrobin 于 2010-4-22 01:28 编辑双击可以显示鼠标所选择的数据,我想右键删除我所选择的那一行怎么可以实现!
论坛某位高手所写的代码!#include <GUIConstantsEx.au3>
#include <ListViewConstants.au3>
#include <WindowsConstants.au3>
#include <GUIListView.au3>
$Form1 = GUICreate("Form1", 410, 310)
GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")
$ListView1 = GUICtrlCreateListView("||", 8, 8, 400, 300)
GUISetState(@SW_SHOW)
For $I = 1 To 10
GUICtrlCreateListViewItem($I, $ListView1)
Next
Do
Until GUIGetMsg() = $GUI_EVENT_CLOSE
Func WM_NOTIFY($hWndGUI, $MsgID, $WParam, $LParam)
Local $tagNMHDR, $Event, $hWndFrom, $IDFrom
Local $tagNMHDR = DllStructCreate("int;int;int", $LParam)
If @error Then Return $GUI_RUNDEFMSG
$IDFrom = DllStructGetData($tagNMHDR, 2)
$Event = DllStructGetData($tagNMHDR, 3)
$tagNMHDR = 0
Switch $IDFrom;选择产生事件的控件
Case $ListView1
Switch $Event; 选择产生的事件
Case $NM_CLICK ; 左击
;~ ...
Case $NM_DBLCLK ; 双击
$Index = _GUICtrlListView_GetSelectedIndices($ListView1)
If Not StringLen($Index) Then; 这里用以判断是否选定了ListViewItem
MsgBox(0, "", "未选定")
Return
EndIf
MsgBox(0, 0, _GUICtrlListView_GetItemText($ListView1, Number($Index), 0))
Case $NM_RCLICK ; 右击
;~ ...
EndSwitch
EndSwitch
Return $GUI_RUNDEFMSG
EndFunc ;==>WM_NOTIFY 本帖最后由 水木子 于 2010-4-21 21:56 编辑
实现了LZ的要求,随便帮LZ整理了下代码。#include <GUIListView.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
GUICreate("ListView", 380, 350)
GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")
$ListView1 = GUICtrlCreateListView("|", 5, 5, 370, 300)
_GUICtrlListView_SetColumnWidth($ListView1, 0, 100)
GUISetState(@SW_SHOW)
For $I = 1 To 10
GUICtrlCreateListViewItem($I, $ListView1)
Next
Do
Until GUIGetMsg() = -3
Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)
Local $tNMTV, $iCode, $hItem
$tNMTV = DllStructCreate($tagNMTVDISPINFO, $ilParam)
$iCode = DllStructGetData($tNMTV, "Code")
$Index = _GUICtrlListView_GetSelectedIndices($ListView1)
If $iCode = $NM_DBLCLK And StringLen($Index) <> 0 Then MsgBox(0, 0, _GUICtrlListView_GetItemText($ListView1, Number($Index), 0))
If $iCode = $NM_RCLICK And StringLen($Index) <> 0 Then _GUICtrlListView_DeleteItem($ListView1, Number($Index))
EndFunc ;==>WM_NOTIFY 感谢 水木子 今天又学到东西了!!
谢谢了!!!! 学习一下如何注册消息
页:
[1]