创建菜单(Menu)控件.
GUICtrlCreateMenu ( "子菜单文本" [, 菜单ID [, 菜单序号]]
)
子菜单文本 | 子菜单文本. |
菜单ID | [可选参数] 子菜单所属主菜单的标识符. 如设为 -1, 则使用第一级菜单作为主菜单. |
菜单序号 | [可选参数] 定义创建菜单项的数量. 菜单项序号从 0 开始计算. |
成功: | 返回控件标识符(控件ID). |
失败: | 返回 0. |
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
Example()
Func Example()
Local
$defaultstatus =
"准备就绪",
$filemenu,
$fileitem
Local $helpmenu, $infoitem, $exititem, $recentfilesmenu
Local $viewmenu, $viewstatusitem , $cancelbutton
Local
$statuslabel,
$msg, $file
GUICreate("我的菜单 GUI", 300, 200)
$filemenu = GUICtrlCreateMenu("文件 &F")
$fileitem = GUICtrlCreateMenuItem
("打开", $filemenu)
GUICtrlSetState(-1, $GUI_DEFBUTTON)
$helpmenu = GUICtrlCreateMenu("?")
GUICtrlCreateMenuItem ("保存",
$filemenu)
GUICtrlSetState(-1, $GUI_DISABLE)
$infoitem = GUICtrlCreateMenuItem
("信息", $helpmenu)
$exititem = GUICtrlCreateMenuItem
("退出", $filemenu)
$recentfilesmenu = GUICtrlCreateMenu("最近的文件", $filemenu, 1)
GUICtrlCreateMenuItem ("",
$filemenu,
2) ; 创建一个分隔线
$viewmenu = GUICtrlCreateMenu("查看", -1,
1) ; 之前创建的"?"菜单
$viewstatusitem = GUICtrlCreateMenuItem ("状态栏",
$viewmenu)
GUICtrlSetState(-1, $GUI_CHECKED)
GUICtrlCreateButton("确定",
50, 130, 70, 20)
GUICtrlSetState(-1, $GUI_FOCUS)
$cancelbutton = GUICtrlCreateButton("取消",
180, 130, 70, 20)
$statuslabel = GUICtrlCreateLabel($defaultstatus, 0, 165, 300, 16, BitOR($SS_SIMPLE, $SS_SUNKEN))
GUISetState()
While
1
$msg = GUIGetMsg()
If $msg = $fileitem Then
$file =
FileOpenDialog("选择文件...", @TempDir, "所有文件 (*.*)")
If @error
<> 1
Then GUICtrlCreateMenuItem ($file,
$recentfilesmenu)
EndIf
If $msg = $viewstatusitem Then
If BitAND(GUICtrlRead($viewstatusitem ), $GUI_CHECKED) = $GUI_CHECKED Then
GUICtrlSetState($viewstatusitem , $GUI_UNCHECKED)
GUICtrlSetState($statuslabel, $GUI_HIDE)
Else
GUICtrlSetState($viewstatusitem , $GUI_CHECKED)
GUICtrlSetState($statuslabel, $GUI_SHOW)
EndIf
EndIf
If $msg = $GUI_EVENT_CLOSE Or $msg = $cancelbutton Or $msg = $exititem Then ExitLoop
If $msg = $infoitem Then MsgBox(0, "信息", "只是一个测试...")
WEnd
GUIDelete()
EndFunc ;==>Example
provider with jb51.net (unicode) |