创建菜单项目(MenuItem)控件.
GUICtrlCreateMenuItem ( "文本", 菜单ID [, 菜单序号 [,
菜单类型]] )
文本 | 菜单项目文本. |
菜单ID | 子菜单所属主菜单的标识符. 如设为 -1, 则使用第一级菜单作为主菜. |
菜单序号 | [可选参数] 定义创建菜单项的数量. 菜单项编号从 0 开始计算. |
菜单类型 | [可选参数] 0 (默认) = 创建常规菜单项, 1 = 创建单选菜单项 |
成功: | 返回控件标识符(控件ID). |
失败: | 返回 0. |
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
_Main()
Func _Main()
Local
$iCancel,
$iExit,
$iFileItem,
$iFileMenu,
$iHelpMenu,
$iInfoItem
Local
$iRecentFilesMenu,
$iStatusLabel,
$iViewMenu,
$iViewStatusItem,
$sFilePath,
$sStatus =
"Ready"
GUICreate("我的菜单 GUI", 300, 200)
$sStatus = "准备就绪"
$iFileMenu = GUICtrlCreateMenu("文件 &F")
$iFileItem = GUICtrlCreateMenuItem("打开",
$iFileMenu)
GUICtrlSetState(-1, $GUI_DEFBUTTON)
$iHelpMenu = GUICtrlCreateMenu("?")
GUICtrlCreateMenuItem("保存",
$iFileMenu)
GUICtrlSetState(-1, $GUI_DISABLE)
$iInfoItem = GUICtrlCreateMenuItem("信息",
$iHelpMenu)
$iExit = GUICtrlCreateMenuItem("退出",
$iFileMenu)
$iRecentFilesMenu =
GUICtrlCreateMenu("最近文件", $iFileMenu, 1)
GUICtrlCreateMenuItem("",
$iFileMenu,
2) ; 创建一个分隔线
$iViewMenu = GUICtrlCreateMenu("查看", -1,
1) ; 之前创建的"?"菜单
$iViewStatusItem = GUICtrlCreateMenuItem("状态栏",
$iViewMenu)
GUICtrlSetState(-1, $GUI_CHECKED)
GUICtrlCreateButton("确定",
50, 130, 70, 20)
GUICtrlSetState(-1, $GUI_FOCUS)
$iCancel = GUICtrlCreateButton("取消",
180, 130, 70, 20)
$iStatusLabel = GUICtrlCreateLabel($sStatus, 0, 165, 300, 16, BitOR($SS_SIMPLE, $SS_SUNKEN))
GUISetState(@SW_SHOW)
While
1
Switch GUIGetMsg()
Case $GUI_EVENT_CLOSE, $iCancel, $iExit
Exit
Case $iInfoItem
MsgBox(64,
"信息", "只是一个测试...")
Case $iFileItem
$sFilePath = FileOpenDialog("选择文件...", @TempDir, "全部 (*.*)")
If @error Then
ContinueLoop
EndIf
GUICtrlCreateMenuItem($sFilePath, $iRecentFilesMenu)
Case $iViewStatusItem
If BitAND(GUICtrlRead($iViewStatusItem), $GUI_CHECKED) = $GUI_CHECKED Then
GUICtrlSetState($iViewStatusItem, $GUI_UNCHECKED)
GUICtrlSetState($iStatusLabel, $GUI_HIDE)
Else
GUICtrlSetState($iViewStatusItem, $GUI_CHECKED)
GUICtrlSetState($iStatusLabel, $GUI_SHOW)
EndIf
EndSwitch
WEnd
EndFunc ;==>_Main
provider with jb51.net (unicode) |