AutoIt上路11-通过鼠标右键菜单操作ListView的项目
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是右键点击消息处理,当有右键点击时,我们根据事件发生的位置,弹出菜单。
关键示例代码:Java1234567891011121314151617181920212223242526; 右键点击消息Func _WM_CONTEXTMENU($hWnd, $iMsg, $iwParam, $ilParam); 匹配ListViewSwitch $iwParamCase $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 = $iwParamEndIfReturn TrueEndSwitchEndFuncJava123456789101112131415161718192021222324; 右键菜单项点击之后,通过此消息处理Func _WM_COMMAND($hWnd, $msg, $wParam, $lParam); 匹配是在哪个LV上右键的菜单Switch $hEnableListViewCase $hLvInTabJournal; 匹配菜单项Switch $wParamCase $id_menu_lv_del; $strTbName: 表名称; $strLvInTab:列表ID; $columnOldData: 整行的内容FuncDeleteItemFromAccessAndListView ( "tb_journal", $lvInTabJournal, $columnOldData )Case $id_menu_lv_updateCase $id_menu_lv_copyEndSwitchCase $hLvInTabAccets;...... 代码略源码:https://github.com/731942771/AutoitWorkingRecorder