AutoIt上路10-Access操作(查询)及更新到ListView
http://www.gaohaiyan.com/986.html在
AutoIt上路06-通过鼠标右键菜单控制标签这一篇里已经介绍过GUIRegisterMsg($WM_NOTIFY, “_WM_NOTIFY”)监听鼠标右键的处理。但在本例中很不幸的不能满足需求,无法正确判断ListView的右键点击事件。
因此本例使用另一种方式:GUIRegisterMsg($WM_CONTEXTMENU, “_WM_CONTEXTMENU”),加GUIRegisterMsg($WM_COMMAND, ‘_WM_COMMAND’) 。
WM_CONTEXTMENU是右键点击消息处理,当有右键点击时,我们根据事件发生的位置,弹出菜单。
关键示例代码:
Java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
; 右键点击消息
Func _WM_CONTEXTMENU($hWnd, $iMsg, $iwParam, $ilParam)
; 匹配ListView
Switch $iwParam
Case $hLvInTabJournal, $hLvInTabAccets, $hLvInTabPartners, $hLvInTabProducts, $hLvInTabProjects, $hLvInTabSchools, $hLvInTabSources, $hLvInTabWorkers, $hLvInTabUsers, $hlvintabLog
; 获取右键点击的有效索引
If _GUICtrlListView_GetSelectedIndices ( $iwParam ) <> "" Then
$columnOldData = _GUICtrlListView_GetItemTextString ($iwParam, _GUICtrlListView_GetSelectedIndices ( $iwParam ))
Local $hMenu; $id_menu_lv_del = 2000, $id_menu_lv_update, $id_menu_lv_copy
$hMenu = _GUICtrlMenu_CreatePopup()
_GUICtrlMenu_InsertMenuItem($hMenu, 0, "删除", $id_menu_lv_del)
_GUICtrlMenu_InsertMenuItem($hMenu, 1, "", 0)
_GUICtrlMenu_InsertMenuItem($hMenu, 2, "修改", $id_menu_lv_update)
_GUICtrlMenu_InsertMenuItem($hMenu, 3, "", 0)
_GUICtrlMenu_InsertMenuItem($hMenu, 4, "复制", $id_menu_lv_copy)
_GUICtrlMenu_TrackPopupMenu($hMenu, $hWnd)
_GUICtrlMenu_DestroyMenu($hMenu)
$hEnableListView = $iwParam
EndIf
Return True
EndSwitch
EndFunc
Java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
; 右键菜单项点击之后,通过此消息处理
Func _WM_COMMAND($hWnd, $msg, $wParam, $lParam)
; 匹配是在哪个LV上右键的菜单
Switch $hEnableListView
Case $hLvInTabJournal
; 匹配菜单项
Switch $wParam
Case $id_menu_lv_del
; $strTbName: 表名称
; $strLvInTab:列表ID
; $columnOldData: 整行的内容
FuncDeleteItemFromAccessAndListView ( "tb_journal", $lvInTabJournal, $columnOldData )
Case $id_menu_lv_update
Case $id_menu_lv_copy
EndSwitch
Case $hLvInTabAccets
;...... 代码略
源码:
https://github.com/731942771/AutoitWorkingRecorder
本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请
点击举报。