使用_GUICtrlMenu_CreatePopup()创建上下文菜单如何显示子菜单?
#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如上代码中如何显示所有任务中的子菜单? ...................................... 本帖最后由 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 楼上的是右键菜单,但是我使用的是_GUICtrlMenu_CreatePopup()创建的上下文菜单,在该函数下如何显示子菜单?
页:
[1]