在GUI上創(chuàng)建一個(gè)菜單項(xiàng)目控件。
GUICtrlCreateMenuitem ( "文本", menuID [, menuentry [, menuradioitem]] )
參數(shù)
文本 | 控件的文本。 |
menuID | 定義此子菜單要附加到的目標(biāo)菜單ID。若此值為 -1 則使用第一級(jí)菜單。 |
menuentry | [可選參數(shù)] 允許定義要?jiǎng)?chuàng)建的菜單項(xiàng)的(次序)編號(hào)。編號(hào)從0開始。 |
menuradionitem | [可選參數(shù)] 0(默認(rèn)) = 創(chuàng)建普通菜單項(xiàng),1 = 創(chuàng)建單選菜單項(xiàng) |
返回值
成功: | 返回控件標(biāo)識(shí)符(控件ID)。 |
失。 | 返回值為0。 |
注意
若要設(shè)置或修改控件的各種信息請(qǐng)查看 GUICtrlSet....
相關(guān)
GUICtrlSet..., GUIGetMsg
示例
#include <GUIConstants.au3>
GUICreate("我的 GUI 之菜單",300,200)
Global $defaultstatus = "Ready"
Global $status
$filemenu = GUICtrlCreateMenu ("文件(&F)")
$fileitem = GUICtrlCreateMenuitem ("打開(&O)",$filemenu)
GUICtrlSetState(-1,$GUI_DEFBUTTON)
$helpmenu = GUICtrlCreateMenu ("?")
$saveitem = GUICtrlCreateMenuitem ("保存(&S)",$filemenu)
GUICtrlSetState(-1,$GUI_DISABLE)
$infoitem = GUICtrlCreateMenuitem ("信息",$helpmenu)
$exititem = GUICtrlCreateMenuitem ("退出(&X)",$filemenu)
$recentfilesmenu = GUICtrlCreateMenu ("最近的文件",$filemenu,1)
$separator1 = GUICtrlCreateMenuitem ("",$filemenu,2) ; 分隔線
$viewmenu = GUICtrlCreateMenu("查看(&V)",-1,1) ; 此菜單將出現(xiàn)在 "?" 菜單之前
$viewstatusitem = GUICtrlCreateMenuitem ("狀態(tài)欄",$viewmenu)
GUICtrlSetState(-1,$GUI_CHECKED)
$okbutton = 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()
Exit