#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
Opt('MustDeclareVars', 1)
Example()
Func Example()
Local $defaultstatus = "已就緒", $status, $filemenu, $fileitem
Local $helpmenu, $saveitem, $infoitem, $exititem, $recentfilesmenu
Local $separator1, $viewmenu, $viewstatusitem, $okbutton, $cancelbutton
Local $statuslabel, $msg, $file
GUICreate("我的 GUI 選單", 300, 200)
$filemenu = GUICtrlCreateMenu("檔案(&F)")
$fileitem = GUICtrlCreateMenuItem("開啟", $filemenu)
GUICtrlSetState(-1, $GUI_DEFBUTTON)
$helpmenu = GUICtrlCreateMenu("?")
$saveitem = GUICtrlCreateMenuItem("儲存", $filemenu)
GUICtrlSetState(-1, $GUI_DISABLE)
$infoitem = GUICtrlCreateMenuItem("資訊", $helpmenu)
$exititem = GUICtrlCreateMenuItem("結束", $filemenu)
$recentfilesmenu = GUICtrlCreateMenu("最近存取過的檔案", $filemenu, 1)
$separator1 = GUICtrlCreateMenuItem("", $filemenu, 2) ; 建立分隔線
$viewmenu = GUICtrlCreateMenu("檢視", -1, 1) ; 建立於 "?" 選單前
$viewstatusitem = GUICtrlCreateMenuItem("狀態列", $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()
EndFunc ;==>Example