創(chuàng)建菜單項(xiàng)目(MenuItem)控件.
GUICtrlCreateMenuItem ( "文本", 菜單ID [, 菜單序號(hào) [,
菜單類(lèi)型]] )
文本 | 菜單項(xiàng)目文本. |
菜單ID | 子菜單所屬主菜單的標(biāo)識(shí)符. 如設(shè)為 -1, 則使用第一級(jí)菜單作為主菜. |
菜單序號(hào) | [可選參數(shù)] 定義創(chuàng)建菜單項(xiàng)的數(shù)量. 菜單項(xiàng)編號(hào)從 0 開(kāi)始計(jì)算. |
菜單類(lèi)型 | [可選參數(shù)] 0 (默認(rèn)) = 創(chuàng)建常規(guī)菜單項(xiàng), 1 = 創(chuàng)建單選菜單項(xiàng) |
成功: | 返回控件標(biāo)識(shí)符(控件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 = "準(zhǔn)備就緒"
$iFileMenu = GUICtrlCreateMenu("文件 &F")
$iFileItem = GUICtrlCreateMenuItem("打開(kāi)",
$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) ; 創(chuàng)建一個(gè)分隔線
$iViewMenu = GUICtrlCreateMenu("查看", -1,
1) ; 之前創(chuàng)建的"?"菜單
$iViewStatusItem = GUICtrlCreateMenuItem("狀態(tài)欄",
$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,
"信息", "只是一個(gè)測(cè)試...")
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) |