|
本帖最后由 solo_k 于 2013-4-1 00:00 编辑
我想创建一个树控件,并且为这个树控件的节点都创建右键菜单,以下代码(只需关注标为红色和绿色字体的部分即可)是可以成功创建右键菜单的
#include <GUIConstantsEx.au3>
#include <GUIConstants.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <TreeViewConstants.au3>
#Include <GuiTreeView.au3>
#include <GuiImageList.au3>
#Include <GuiMenu.au3>
Opt("MustDeclareVars",1)
Opt("TrayIconDebug",1)
Opt("TrayAutoPause",0)
Opt("GUIOnEventMode", 1) ; 切换为 OnEvent 模式
GUIRegisterMsg($WM_GETMINMAXINFO, "WM_GETMINMAXINFO")
#Region 界面
CreateGUI()
GUISetOnEvent($GUI_EVENT_CLOSE, "CLOSEClicked") ; 设置窗口关闭事件
GUICtrlSetOnEvent ( $excPass, "_pass" )
While 1
Sleep(1000) ; 不做任何事
WEnd
Func CreateGUI()
Global $MyGUI = GUICreate("tree的右键菜单",1000,700, -1, -1, BitOR($WS_MAXIMIZEBOX,$WS_MINIMIZEBOX,$WS_SIZEBOX))
Global $tree = GUICtrlCreateTreeView ( 10, 10, 200, 400,BitOR($TVS_HASBUTTONS, $TVS_HASLINES, $TVS_LINESATROOT, $TVS_DISABLEDRAGDROP, $TVS_SHOWSELALWAYS), $WS_EX_CLIENTEDGE )
GUICtrlSetResizing ( -1,290)
Global $treeProgram = GUICtrlCreateTreeViewItem ( "他有右键菜单", $tree )
GUICtrlSetOnEvent ( -1, "_clickFolder" )
_GUICtrlTreeView_SetIcon($tree, $treeProgram,"shell32.dll", 3)
;_GUICtrlTreeView_SetItemParam($tree, $treeProgram, 1)
GUICtrlCreateTreeViewItem ( "基线", $treeProgram )
Global $test1 = GUICtrlCreateTreeViewItem ( "文本1", $treeProgram )
GUICtrlCreateTreeViewItem ( "文本2", $treeProgram )
GUICtrlCreateTreeViewItem ( "文本3", $treeProgram )
GUICtrlCreateTreeViewItem ( "文本4", $treeProgram )
GUICtrlCreateTreeViewItem ( "文本5", $treeProgram )
Global $treeitem2 = GUICtrlCreateContextMenu ( $treeProgram )
Global $excPass = GUICtrlCreateMenuItem ( "执行通过", $treeitem2 )
GUICtrlCreateMenuItem ( "执行失败", $treeitem2 )
GUISetState()
EndFunc
Func _pass()
GUIctrlSetState($treeProgram,$GUI_FOCUS)
EndFunc
Func CLOSEClicked()
GUIDelete()
Exit
EndFunc
#EndRegion
但是如果把以上代码中已注释的这个函数
;_GUICtrlTreeView_SetItemParam($tree, $treeProgram, 1)
恢复,就无法创建右键菜单了
请高手指点一下是什么原因,如何解决?小弟万分感谢!!! |
|