如何给GUICtrlCreateMenu添加动作
本帖最后由 CFL875801950 于 2016-12-24 17:45 编辑利用GUICtrlCreateMenu创建一个帮助菜单,想实现的功能是,当点击帮助菜单的时候,能弹出来一个msgbox消息框 回复 7# CFL875801950
有几个不对,修改了,你试看看
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <ButtonConstants.au3>
#include <MsgBoxConstants.au3>
#include <StaticConstants.au3>
Example1()
Func Example1()
Local $msg, $jchu, $bg, $jxue, $bzhu, $jszc, $qdong
Local $jchu_1, $jchu_2, $jchu_3, $jchu_4
Local $bg_1, $bg_2, $bg_3, $bg_4, $bg_5
Local $jxue_1, $jxue_2, $jxue_3
Local $qdong_1,$qdong_2, $qdong_3, $qdong_4
GUICreate("FROM") ; 创建一个居中显示的 GUI 窗口
GUISetState(@SW_SHOW) ; 显示一个空白的窗口
$jchu = GUICtrlCreateMenu("基础软件") ;创建基础软件菜单选项
$jchu_1 = GUICtrlCreateMenuItem("搜狗输入法", $jchu)
$jchu_2 = GUICtrlCreateMenuItem("谷歌浏览器", $jchu)
$jchu_3 = GUICtrlCreateMenuItem("火狐浏览器", $jchu)
$jchu_4 = GUICtrlCreateMenuItem("360压缩", $jchu)
$bg = GUICtrlCreateMenu("办公软件") ;创建办公软件菜单选项
$bg_1 = GUICtrlCreateMenuItem("office 2013", $bg)
$bg_2 = GUICtrlCreateMenuItem("播放器", $bg)
$bg_3 = GUICtrlCreateMenuItem("看图工具", $bg)
$bg_4 = GUICtrlCreateMenuItem("微信", $bg)
$bg_5 = GUICtrlCreateMenuItem("企业QQ", $bg)
$jxue = GUICtrlCreateMenu("教学软件") ;创建教学软件菜单选项
$jxue_1 = GUICtrlCreateMenuItem("Adobe CC", $jxue)
$jxue_2 = GUICtrlCreateMenuItem("Adobe CS6", $jxue)
$jxue_3 = GUICtrlCreateMenuItem("Autodesk", $jxue)
$qdong = GUICtrlCreateMenu("驱动程序") ;创建驱动程序菜单选项
$qdong_1 = GUICtrlCreateMenuItem("票据打印机", $qdong)
$qdong_2 = GUICtrlCreateMenuItem("证卡打印机", $qdong)
$qdong_3 = GUICtrlCreateMenuItem("HP_M128fw", $qdong)
$qdong_4 = GUICtrlCreateMenuItem("HP 1025nw", $qdong)
$bzhu = GUICtrlCreateMenu("帮助") ;创建帮助菜单选项
$jszc = GUICtrlCreateMenuItem("帮助",$bzhu) ;创建技术支持菜单选项
GUICtrlCreateButton("安装", 10, 300, 100)
GUICtrlCreateButton("取消", 286, 300, 100)
; 运行界面,直到窗口被关闭
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
Case $jszc
MsgBox($MB_SYSTEMMODAL,"回答","测试")
EndSwitch
WEnd
EndFunc
还不会看帮助文件?????
#include <GUIConstantsEx.au3>
#include <MsgBoxConstants.au3>
#include <StaticConstants.au3>
Example()
Func Example()
Local $sDefaultstatus = "准备就绪"
GUICreate("菜单控件 GUI", 300, 200)
Local $idFilemenu = GUICtrlCreateMenu("文件 &F")
Local $idFileitem = GUICtrlCreateMenuItem("打开", $idFilemenu)
GUICtrlSetState(-1, $GUI_DEFBUTTON)
Local $idHelpmenu = GUICtrlCreateMenu("?")
GUICtrlCreateMenuItem("保存", $idFilemenu)
GUICtrlSetState(-1, $GUI_DISABLE)
Local $idInfoitem = GUICtrlCreateMenuItem("信息", $idHelpmenu)
Local $idExititem = GUICtrlCreateMenuItem("退出", $idFilemenu)
Local $idRecentfilesmenu = GUICtrlCreateMenu("最近的文件", $idFilemenu, 1)
GUICtrlCreateMenuItem("", $idFilemenu, 2) ; 创建分隔线
Local $idViewmenu = GUICtrlCreateMenu("查看", -1, 1) ; 创建在 "?" 之前的菜单
Local $idViewstatusitem = GUICtrlCreateMenuItem("状态栏", $idViewmenu)
GUICtrlSetState(-1, $GUI_CHECKED)
$menu6 = GUICtrlCreateMenu("帮助[&H]")
$MenuItem22 = GUICtrlCreateMenuItem("关于[&G]", $menu6)
GUICtrlCreateButton("确定", 50, 130, 70, 20)
GUICtrlSetState(-1, $GUI_FOCUS)
Local $idCancelbutton = GUICtrlCreateButton("取消", 180, 130, 70, 20)
Local $idStatuslabel = GUICtrlCreateLabel($sDefaultstatus, 0, 165, 300, 16, BitOR($SS_SIMPLE, $SS_SUNKEN))
GUISetState(@SW_SHOW)
Local $sFile
; 循环到用户退出.
While 1
Switch GUIGetMsg()
Case $idFileitem
$sFile = FileOpenDialog("选择文件...", @TempDir, "所有文件 (*.*)")
If @error <> 1 Then GUICtrlCreateMenuItem($sFile, $idRecentfilesmenu)
Case $idViewstatusitem
If BitAND(GUICtrlRead($idViewstatusitem), $GUI_CHECKED) = $GUI_CHECKED Then
GUICtrlSetState($idViewstatusitem, $GUI_UNCHECKED)
GUICtrlSetState($idStatuslabel, $GUI_HIDE)
Else
GUICtrlSetState($idViewstatusitem, $GUI_CHECKED)
GUICtrlSetState($idStatuslabel, $GUI_SHOW)
EndIf
Case $GUI_EVENT_CLOSE, $idCancelbutton, $idExititem
ExitLoop
Case $idInfoitem
MsgBox($MB_SYSTEMMODAL, "信息", "只是一个测试...")
Case $MenuItem22
MsgBox($MB_SYSTEMMODAL, "回答", "弹出来一个 msgbox 消息框...")
EndSwitch
WEnd
GUIDelete()
EndFunc ;==>Example
回复 2# chzj589
帮助菜单没有下来的关于选项,可以实现吗,点击帮助,就直接出现MsgBox($MB_SYSTEMMODAL, "回答", "弹出来一个 msgbox 消息框...") 回复 3# CFL875801950
GUICtrlCreateMenu是主项目,不能接受命令
GUICtrlCreateMenuItem是子项目
把关于改为帮助
$menu6 = GUICtrlCreateMenu("帮助[&H]")
$MenuItem22 = GUICtrlCreateMenuItem("帮助[&G]", $menu6) 回复 4# chzj589
方便使用QQ吗,我看了你发的,然后自己写的会在case 报错 回复 5# CFL875801950
把你写的代码发上来!
不好意思,我很少用QQ 回复 6# chzj589
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <ButtonConstants.au3>
#include <MsgBoxConstants.au3>
#include <StaticConstants.au3>
Example1()
Func Example1()
Local $msg, $jchu, $bg, $jxue, $bzhu, $jszc, $qdong
Local $jchu_1, $jchu_2, $jchu_3, $jchu_4
Local $bg_1, $bg_2, $bg_3, $bg_4, $bg_5
Local $jxue_1, $jxue_2, $jxue_3
Local $qdong_1,$qdong_2, $qdong_3, $qdong_4
GUICreate("FROM") ; 创建一个居中显示的 GUI 窗口
GUISetState(@SW_SHOW) ; 显示一个空白的窗口
$jchu = GUICtrlCreateMenu("基础软件") ;创建基础软件菜单选项
$jchu_1 = GUICtrlCreateMenuItem("搜狗输入法", $jchu)
$jchu_2 = GUICtrlCreateMenuItem("谷歌浏览器", $jchu)
$jchu_3 = GUICtrlCreateMenuItem("火狐浏览器", $jchu)
$jchu_4 = GUICtrlCreateMenuItem("360压缩", $jchu)
$bg = GUICtrlCreateMenu("办公软件") ;创建办公软件菜单选项
$bg_1 = GUICtrlCreateMenuItem("office 2013", $bg)
$bg_2 = GUICtrlCreateMenuItem("播放器", $bg)
$bg_3 = GUICtrlCreateMenuItem("看图工具", $bg)
$bg_4 = GUICtrlCreateMenuItem("微信", $bg)
$bg_5 = GUICtrlCreateMenuItem("企业QQ", $bg)
$jxue = GUICtrlCreateMenu("教学软件") ;创建教学软件菜单选项
$jxue_1 = GUICtrlCreateMenuItem("Adobe CC", $jxue)
$jxue_2 = GUICtrlCreateMenuItem("Adobe CS6", $jxue)
$jxue_3 = GUICtrlCreateMenuItem("Autodesk", $jxue)
$qdong = GUICtrlCreateMenu("驱动程序") ;创建驱动程序菜单选项
$qdong_1 = GUICtrlCreateMenuItem("票据打印机", $qdong)
$qdong_2 = GUICtrlCreateMenuItem("证卡打印机", $qdong)
$qdong_3 = GUICtrlCreateMenuItem("HP_M128fw", $qdong)
$qdong_4 = GUICtrlCreateMenuItem("HP 1025nw", $qdong)
$bzhu = GUICtrlCreateMenu("帮助") ;创建帮助菜单选项
$jszc = GUICtrlCreateMenu("?") ;创建技术支持菜单选项
GUICtrlCreateButton("安装", 10, 300, 100)
GUICtrlCreateButton("取消", 286, 300, 100)
EndFunc
; 运行界面,直到窗口被关闭
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
Case $bzhu
MsgBox($MB_SYSTEMMODAL,"回答","测试")
EndSwitch
WEnd 回复 8# chzj589
谢谢,虽然不是太明白为什么要这样写,但是已经知道怎么写了 都很历害啊 如何自定义GUICtrlCreateMenu位置
页:
[1]