找回密码
 加入
搜索
查看: 3395|回复: 5

[GUI管理] 请问创建右键菜单的函数和Tree的UDF函数有冲突吗?

  [复制链接]
发表于 2013-3-31 23:48:07 | 显示全部楼层 |阅读模式
本帖最后由 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)
恢复,就无法创建右键菜单了
请高手指点一下是什么原因,如何解决?小弟万分感谢!!!
 楼主| 发表于 2013-3-31 23:54:04 | 显示全部楼层
自己顶一下,请高手看看啊,急求!!
发表于 2013-3-31 23:57:41 | 显示全部楼层
用消息搞不就完了吗
发表于 2013-4-1 00:22:07 | 显示全部楼层
_GUICtrlTreeView_SetItemParam 示例有注:
警告:不要对 GUICtrlCreateTreeViewItem 创建的项目使用 _GUICtrlTreeView_SetItemParam 函数
发表于 2013-4-1 01:40:31 | 显示全部楼层
回复 4# afan
后来试过,其实也没啥关系,只是必须处理下
 楼主| 发表于 2013-4-2 17:34:26 | 显示全部楼层
谢谢大家,搞定!
您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2024-4-29 05:37 , Processed in 0.088066 second(s), 23 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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