找回密码
 加入
搜索
查看: 7801|回复: 11

[AU3基础] 请教:如何为ListView控件创建右键菜单。[已解决]

  [复制链接]
发表于 2009-10-28 13:19:58 | 显示全部楼层 |阅读模式
本帖最后由 水木子 于 2010-11-22 17:55 编辑

下面是我随便画的一个GUI、并做了简单的右键菜单,但是现在右键菜单不能在ListView响应
我想问的是,如何让右键菜单在ListView中也能响应。
请大家指点下,非常感谢。
#include <GUIListView.au3>
#include <WindowsConstants.au3>

GUICreate("右键菜单测试", 400, 350)
$ListView1 = GUICtrlCreateListView(" 代码测试  ", 10, 10, 380, 200, -1, BitOR($WS_EX_CLIENTEDGE, $LVS_EX_FULLROWSELECT, $LVS_REPORT))
$hMenu0 = GUICtrlCreateContextMenu()
$hMenu1 = GUICtrlCreateMenuItem("添加数据        ", $hMenu0)
$hMenu2 = GUICtrlCreateMenuItem("删除数据", $hMenu0)
$hMenu3 = GUICtrlCreateMenuItem("修改数据", $hMenu0)
$hMenu4 = GUICtrlCreateMenuItem("搜索数据", $hMenu0)
GUICtrlCreateMenuItem("", $hMenu0)
$hMenu5 = GUICtrlCreateMenu("排列方式", $hMenu0)
$hMenu6 = GUICtrlCreateMenuItem("录入时间", $hMenu5)
$hMenu7 = GUICtrlCreateMenuItem("销售日期", $hMenu5)
$hMenu8 = GUICtrlCreateMenuItem("控制面板", $hMenu0)
GUICtrlCreateMenuItem("", $hMenu0)
$hMenu9 = GUICtrlCreateMenuItem("关闭程序", $hMenu0)
GUISetState()

Do
Until GUIGetMsg() = - 3
发表于 2009-10-28 13:37:17 | 显示全部楼层
哥们,租什么?

用句柄试试看如何?
 楼主| 发表于 2009-10-28 13:41:54 | 显示全部楼层
2# netegg
呵呵!不好意思,没注意打错字了。

句柄?怎么做,能说详细点儿不?
发表于 2009-10-28 14:06:37 | 显示全部楼层
#include <GUIListBox.au3>

#include <GUIListView.au3>

#include <GUIConstantsEx.au3>

#include <WindowsConstants.au3>



GUICreate("右键菜单测试", 400, 350)

$hListView = GUICtrlCreateListView(" 代码测试  ",10, 10, 380, 200,-1, BitOR($WS_EX_CLIENTEDGE,$LVS_EX_FULLROWSELECT,$LVS_REPORT))

$zhucaidan = GUICtrlCreateContextMenu($hListView)

$tianjia = GUICtrlCreateMenuItem("添加数据        ", $zhucaidan)

$shanchu = GUICtrlCreateMenuItem("删除数据", $zhucaidan)

$shuaxin = GUICtrlCreateMenuItem("修改数据", $zhucaidan)

$sousuo = GUICtrlCreateMenuItem("搜索数据", $zhucaidan)

GUICtrlCreateMenuItem("", $zhucaidan) 

$pailie = GUICtrlCreateMenu("排列方式", $zhucaidan)

$plshijian = GUICtrlCreateMenuItem("录入时间", $pailie)

$plriqi = GUICtrlCreateMenuItem("销售日期", $pailie)

$fileitem = GUICtrlCreateMenuItem("控制面板", $zhucaidan)

GUICtrlCreateMenuItem("", $zhucaidan)    

$infoitem = GUICtrlCreateMenuItem("关闭程序", $zhucaidan)



GUISetState(@SW_SHOW)



While 1

        $nMsg = GUIGetMsg()

        Switch $nMsg

                Case $GUI_EVENT_CLOSE

                        Exit



        EndSwitch
WEnd

评分

参与人数 1金钱 +10 收起 理由
水木子 + 10 非常感谢

查看全部评分

发表于 2009-10-28 14:07:09 | 显示全部楼层
$zhucaidan = GUICtrlCreateContextMenu($hListView)
重点就是这一句
GUICtrlCreateContextMenu ( [控件ID] )
 楼主| 发表于 2009-10-28 14:16:01 | 显示全部楼层
非常感谢,破帽前辈!
发表于 2010-4-14 15:54:21 | 显示全部楼层
不错。。。。。。。。。。
发表于 2011-2-26 09:36:12 | 显示全部楼层
不错,又学习到一点了,呵呵
发表于 2011-3-12 15:52:55 | 显示全部楼层
这个貌似不是很hard吧
发表于 2013-4-21 11:36:57 | 显示全部楼层
水木子大侠好厉害呵呵。我看了你的软件菜单写得超好
发表于 2014-9-29 09:31:30 | 显示全部楼层
正好用到,谢谢大神
发表于 2015-6-12 14:35:25 | 显示全部楼层
原来答案在这里
您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2024-9-28 18:24 , Processed in 0.106629 second(s), 21 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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