找回密码
 加入
搜索
查看: 2631|回复: 3

[系统综合] 使用_GUICtrlMenu_CreatePopup()创建上下文菜单如何显示子菜单?

[复制链接]
发表于 2010-5-31 22:53:00 | 显示全部楼层 |阅读模式
#include <GUIConstants.au3>
#include <WindowsConstants.au3>
#include <WinAPI.au3>
#Include <GuiRebar.au3>
#include <GuiToolBar.au3>
#include <GuiListView.au3>
#include <GuiImageList.au3>
#include <GuiMenu.au3>
#Include <GuiStatusBar.au3>
#include <Constants.au3>

Global $idMenuInsert = 1000

$Gui = GUICreate("测试", 320, 200)

$hListView = _GUICtrlListView_Create($GUI, "连接数(0)", 10, 10, 300, 180, -1, $WS_EX_CLIENTEDGE)

_GUICtrlListView_SetExtendedListViewStyle($hListView, BitOR($LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT))

_GUICtrlListView_SetColumnWidth($hListView, 0, 295)

;系统服务右键菜单
Global $ServerRightDisabled,$ServerRightManual,$ServerRightAuto,$ServerRightAllTask,$ServerRightRunning,$ServerRightStopped,$ServerRightRestart,$ServerRightRefresh,$ServerRightAttribute,$ServerRightHelpe,$ServerRightSubMemu,$ServerRightMemu
;子菜单
$ServerRightSubMemu =_GUICtrlMenu_CreatePopup()
_GUICtrlMenu_AddMenuItem($ServerRightMemu,"启动",$ServerRightRunning)
_GUICtrlMenu_AddMenuItem($ServerRightMemu,"停止",$ServerRightStopped)
_GUICtrlMenu_AddMenuItem($ServerRightMemu,"重新启动",$ServerRightRestart)
;主菜单
$ServerRightMemu =_GUICtrlMenu_CreatePopup()
_GUICtrlMenu_AddMenuItem($ServerRightMemu,"禁用",$ServerRightDisabled)
_GUICtrlMenu_AddMenuItem($ServerRightMemu,"手动",$ServerRightManual)
_GUICtrlMenu_AddMenuItem($ServerRightMemu,"自动",$ServerRightAuto)
_GUICtrlMenu_AddMenuItem($ServerRightMemu,"")
_GUICtrlMenu_AddMenuItem($ServerRightMemu,"所有任务",$ServerRightAllTask,$ServerRightSubMemu)
_GUICtrlMenu_AddMenuItem($ServerRightMemu,"")
_GUICtrlMenu_AddMenuItem($ServerRightMemu,"刷新",$ServerRightRefresh)
_GUICtrlMenu_AddMenuItem($ServerRightMemu,"")
_GUICtrlMenu_AddMenuItem($ServerRightMemu,"属性",$ServerRightAttribute)
_GUICtrlMenu_AddMenuItem($ServerRightMemu,"")
_GUICtrlMenu_AddMenuItem($ServerRightMemu,"帮助",$ServerRightHelpe)
GUISetState()

GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")

While 1
    $msg = GUIGetMsg()
    Switch $msg
    Case $GUI_EVENT_CLOSE
        ExitLoop
    EndSwitch
WEnd

Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)
    Local $hWndFrom, $iCode, $tNMHDR, $hWndListView, $iItemCount
    $hWndListView = $hListView
    If Not IsHWnd($hListView) Then $hWndListView = GUICtrlGetHandle($hListView)

    $tNMHDR = DllStructCreate($tagNMHDR, $ilParam)
    $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
    $iCode = DllStructGetData($tNMHDR, "Code")

    Switch $hWndFrom
    Case $hWndListView
        Switch $iCode
                        Case $NM_RCLICK
                                _GUICtrlMenu_TrackPopupMenu($ServerRightMemu, $hListView, -1, -1, 1, 1, 2)

        EndSwitch
    EndSwitch
    
    Return $GUI_RUNDEFMSG
EndFunc
如上代码中如何显示所有任务中的子菜单?
发表于 2010-5-31 23:25:27 | 显示全部楼层
......................................

评分

参与人数 1金钱 -50 收起 理由
pusofalse -50 禁止无意义回复,扣分警告!

查看全部评分

发表于 2010-6-1 01:30:19 | 显示全部楼层
本帖最后由 l4ever 于 2010-6-1 01:33 编辑

试试
#include <GUIConstantsEx.au3>
#include <ListViewConstants.au3>
#include <WindowsConstants.au3>
#include <GuiListView.au3>
#include <ComboConstants.au3>
$maingui = GUICreate("TEST", 300, 150, -1, -1)
GUISetFont(8.9, 400, 0, "Arial")
$list = GUICtrlCreateListView("TEST", 0,0, 300, 150, "", BitOR($LVS_EX_CHECKBOXES, $LVS_EDITLABELS, $LVS_EX_FULLROWSELECT))

$listMenu = GUICtrlCreateContextMenu($list)
$a = GUICtrlCreateMenuItem("A", $listMenu)
$b = GUICtrlCreateMenu("B", $listMenu)
$b1 = GUICtrlCreateMenuItem("B1", $b)
$b2 = GUICtrlCreateMenuItem("B2", $b)
$b3 = GUICtrlCreateMenuItem("B3", $b)
GUICtrlCreateMenuItem("", $listMenu)
$c = GUICtrlCreateMenuItem("C", $listMenu)
GUISetState(@SW_SHOW,$maingui)

 While 1
     $msg = GUIGetMsg()
     Switch $msg
     Case $GUI_EVENT_CLOSE
         ExitLoop
         Case $a
                 MsgBox(32,"","点击了A")
         Case $B1
                 MsgBox(32,"","点击了B1")
         Case $C
                 MsgBox(32,"","点击了C")
     EndSwitch
 WEnd
 楼主| 发表于 2010-6-1 08:41:08 | 显示全部楼层
楼上的是右键菜单,但是我使用的是_GUICtrlMenu_CreatePopup()创建的上下文菜单,在该函数下如何显示子菜单?
您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2024-11-16 02:25 , Processed in 0.089135 second(s), 27 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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