找回密码
 加入
搜索
楼主: smooth

[AU3基础] [已解决]GUICtrlCreateMenuItem右键菜单怎么隐藏

[复制链接]
 楼主| 发表于 2022-4-4 10:20:40 | 显示全部楼层
chzj589 发表于 2022-4-4 10:02
搜索相关<ListView>的帖子找答案

我发帖之前,已经搜了几遍了,搜出来17页,一页一页的翻的。我再找找。
发表于 2022-4-4 10:31:27 | 显示全部楼层
smooth 发表于 2022-4-4 10:20
我发帖之前,已经搜了几遍了,搜出来17页,一页一页的翻的。我再找找。

要完整的答案是不可能的。寻找帖子借鉴
这个帖子就可借鉴
https://www.autoitx.com/forum.ph ... ;highlight=ListView
 楼主| 发表于 2022-4-4 16:32:42 | 显示全部楼层
chzj589 发表于 2022-4-4 10:31
要完整的答案是不可能的。寻找帖子借鉴
这个帖子就可借鉴
https://www.autoitx.com/forum.php?mod=view ...

根据你提供的这个例子,可以修改成我要实现的功能了,谢谢大佬。
发表于 2022-4-4 17:42:20 | 显示全部楼层
smooth 发表于 2022-4-4 16:32
根据你提供的这个例子,可以修改成我要实现的功能了,谢谢大佬。

恭喜。把解决的代码发上来观赏一下。
发表于 2022-4-5 02:17:34 | 显示全部楼层
另一個方法,ListView有數據就顯示右鍵選單,沒有或沒選中就沒右鍵選單
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <ListViewConstants.au3>
#include <WindowsConstants.au3>
#include <array.au3>
#include <GuiListView.au3>
#include <GuiMenu.au3>

Global Enum $idOpen = 1000, $idSave, $idInfo

$Form1 = GUICreate("Form1", 402, 376, 337, 189)
$ListView1 = GUICtrlCreateListView("row1|row2|row3", 8, 8, 385, 329, BitOR($LVS_SHOWSELALWAYS, $LVS_NOSORTHEADER, $LVS_REPORT))
GUICtrlCreateListViewItem("a1|a2|a3", $ListView1)
GUICtrlCreateListViewItem("b1|b2|b3", $ListView1)
GUICtrlCreateListViewItem("c1|c2|c3", $ListView1)
GUICtrlCreateListViewItem("d1|d2|d3", $ListView1)

$Button1 = GUICtrlCreateButton("讀取", 8, 344, 75, 25)
$Button2 = GUICtrlCreateButton("關閉", 320, 344, 75, 25)
$Button3 = GUICtrlCreateButton("清除", 110, 344, 75, 25)
$Button4 = GUICtrlCreateButton("建立", 210, 344, 75, 25)


GUIRegisterMsg($WM_COMMAND, "WM_COMMAND") ;$WM_COMMAND:0x0111,当用户选择一条菜单命令项或当某个控件发送一条消息给它的父窗口
GUIRegisterMsg($WM_CONTEXTMENU, "WM_CONTEXTMENU") ;$WM_CONTEXTMENU:0x007B,当用户某个窗口中点击了一下右键就发送此消息给这个窗口

GUISetState(@SW_SHOW)

While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
                Case $GUI_EVENT_CLOSE, $Button2
                        Exit
                Case $Button1
                        ListViewSelect()
                Case $Button3
                        _GUICtrlListView_DeleteAllItems ($ListView1)
                Case $Button4
                        GUICtrlCreateListViewItem("a1|a2|a3", $ListView1)
                        GUICtrlCreateListViewItem("b1|b2|b3", $ListView1)
                        GUICtrlCreateListViewItem("c1|c2|c3", $ListView1)
                        GUICtrlCreateListViewItem("d1|d2|d3", $ListView1)
        EndSwitch
WEnd

Func ListViewSelect()
        Dim $val[1],$j = 1
        $totalnum = _GUICtrlListView_GetItemCount($ListView1)
        $selectcount = _GUICtrlListView_GetSelectedCount($ListView1)
        $val[0] = $selectcount
        ReDim $val[$selectcount + 1]
        For $i = 0 To $totalnum
                If _GUICtrlListView_GetItemSelected($ListView1, $i) == True Then
                        $val[$j] = _GUICtrlListView_GetItemTextString($ListView1, $i)
                        $j += 1
                EndIf
        Next
        _ArrayDisplay($val)
EndFunc

Func WM_COMMAND($hWnd, $iMsg, $wParam, $lParam)
    #forceref $hWnd, $iMsg, $lParam
    Switch $wParam
        Case $idOpen
            _WinAPI_ShowMsg("你点击了 [打开] 菜单")
        Case $idSave
            _WinAPI_ShowMsg("你点击了 [保存]  菜单")
        Case $idInfo
            _WinAPI_ShowMsg("你点击了 [信息] 菜单")
    EndSwitch
EndFunc   ;==>WM_COMMAND

Func WM_CONTEXTMENU($hWnd, $iMsg, $wParam, $ilParam) ;$WM_CONTEXTMENU:0x007B,当用户某个窗口中点击了一下右键就发送此消息给这个窗口
Local $hMenu, $selectcount,$totalnum
Local $iRows = _GUICtrlListView_GetItemCount($ListView1) ;检索列表视图行数
If $iRows > 0 Then
        For $i = 0 To $iRows
                If _GUICtrlListView_GetItemSelected($ListView1, $i) == True Then
                        $hMenu = _GUICtrlMenu_CreatePopup() ;创建下拉菜单, 子菜单或快捷菜单.
                        _GUICtrlMenu_InsertMenuItem($hMenu, 0, "Open", $idOpen) ;插入一个新菜单项到指定位置.(使用参数)
                        _GUICtrlMenu_InsertMenuItem($hMenu, 1, "Save", $idSave)
                        _GUICtrlMenu_InsertMenuItem($hMenu, 2, "", 0)
                        _GUICtrlMenu_InsertMenuItem($hMenu, 3, "Info", $idInfo)
                        _GUICtrlMenu_TrackPopupMenu($hMenu, $hWnd) ;在指定位置显示一个快捷菜单
                        _GUICtrlMenu_DestroyMenu($hMenu) ;销毁指定菜单, 并释放菜单占用的内存
                        Return True
                Else
                        _GUICtrlMenu_DestroyMenu($hMenu)
                EndIf
        Next
Else
        _GUICtrlMenu_DestroyMenu($hMenu)
EndIf

EndFunc   ;==>WM_CONTEXTMENU
 楼主| 发表于 2022-4-5 17:46:01 | 显示全部楼层
chzj589 发表于 2022-4-4 17:42
恭喜。把解决的代码发上来观赏一下。

代码在1楼。
 楼主| 发表于 2022-4-5 17:47:25 | 显示全部楼层
yohoboy 发表于 2022-4-5 02:17
另一個方法,ListView有數據就顯示右鍵選單,沒有或沒選中就沒右鍵選單

谢谢大佬分享源码,请教一下,怎么样选中Listview的多行?
发表于 2022-4-5 17:56:39 | 显示全部楼层

1:这样右键菜单能用?
2:点击列表无数据时可不显示右键菜单?
发表于 2022-4-6 00:14:14 | 显示全部楼层
smooth 发表于 2022-4-5 17:47
谢谢大佬分享源码,请教一下,怎么样选中Listview的多行?

滑鼠加上 Cttrl 鍵, 先按Ctrl 鍵不放,滑鼠一個一個點選,
 楼主| 发表于 2022-4-6 07:00:07 | 显示全部楼层
本帖最后由 smooth 于 2022-4-6 07:06 编辑
chzj589 发表于 2022-4-5 17:56
1:这样右键菜单能用?
2:点击列表无数据时可不显示右键菜单?

是的,没错。就是先判断一下Listview有没有数据,再出来右键菜单,就可以了。
 楼主| 发表于 2022-4-6 07:05:41 | 显示全部楼层
yohoboy 发表于 2022-4-6 00:14
滑鼠加上 Cttrl 鍵, 先按Ctrl 鍵不放,滑鼠一個一個點選,

嗯,只滑动鼠标,不用按住CTRL键,可以么?
发表于 2022-4-6 07:39:55 | 显示全部楼层
smooth 发表于 2022-4-6 07:00
是的,没错。就是先判断一下Listview有没有数据,再出来右键菜单,就可以了。

用1楼的代码,鼠标点击没反映,右键菜单不显示?
 楼主| 发表于 2022-4-6 08:30:56 | 显示全部楼层
chzj589 发表于 2022-4-6 07:39
用1楼的代码,鼠标点击没反映,右键菜单不显示?

我把1楼的代码改为完整版的了,直接复制下来就可以测试了。
发表于 2022-4-6 08:51:58 | 显示全部楼层
smooth 发表于 2022-4-6 08:30
我把1楼的代码改为完整版的了,直接复制下来就可以测试了。

测试结果,列表点击鼠标没反映右键菜单
发表于 2022-4-6 08:59:01 | 显示全部楼层
smooth 发表于 2022-4-6 08:30
我把1楼的代码改为完整版的了,直接复制下来就可以测试了。

GUIRegisterMsg($WM_COMMAND, "WM_COMMAND")
GUIRegisterMsg($WM_CONTEXTMENU, "WM_CONTEXTMENU")
这两个不起作用?
您需要登录后才可以回帖 登录 | 加入

本版积分规则

QQ|手机版|小黑屋|AUTOIT CN ( 鲁ICP备19019924号-1 )谷歌 百度

GMT+8, 2024-5-4 08:10 , Processed in 0.069650 second(s), 14 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表