创建菜单
#Include <GuiMenu.au3>
_GUICtrlMenu_CreateMenu([$iStyle = 8])
$iStyle | [可选参数] 菜单样式. 可以是一或多个下列值: 1 - 鼠标移出菜单10秒后,菜单自动结束 2 - 为复选标记和位图保留同样的空间 4 - 菜单项目是 OLE 撤销目标或拖动源 8 - 无模式菜单 16 - 项目左侧不保留复选标记空间 32 - 菜单属主接收 WM_MENUCOMMAND 消息,而不是 WM_COMMAND 选择消息 |
成功: | 返回新建菜单句柄 |
失败: | 返回 0 |
在MSDN中搜索
#include <GuiMenu.au3>
#include <GUIConstantsEx.au3>
#include <WinAPI.au3>
#include <WindowsConstants.au3>
Global $iMemo
Global Enum $idNew = 1000, $idOpen, $idSave, $idExit, $idCut, $idCopy, $idPaste, $idAbout
_Main()
Func _Main()
Local $hGUI, $hFile, $hEdit, $hHelp, $hMain
; 创建 GUI
$hGUI = GUICreate("Menu", 400, 300)
; Create File menu
$hFile = _GUICtrlMenu_CreateMenu()
_GUICtrlMenu_InsertMenuItem($hFile, 0, "&New", $idNew)
_GUICtrlMenu_InsertMenuItem($hFile, 1, "&Open", $idOpen)
_GUICtrlMenu_InsertMenuItem($hFile, 2, "&Save", $idSave)
_GUICtrlMenu_InsertMenuItem($hFile, 3, "", 0)
_GUICtrlMenu_InsertMenuItem($hFile, 4, "E&xit", $idExit)
; Create Edit menu
$hEdit = _GUICtrlMenu_CreateMenu()
_GUICtrlMenu_InsertMenuItem($hEdit, 0, "&Cut", $idCut)
_GUICtrlMenu_InsertMenuItem($hEdit, 1, "C&opy", $idCopy)
_GUICtrlMenu_InsertMenuItem($hEdit, 2, "&Paste", $idPaste)
; Create Help menu
$hHelp = _GUICtrlMenu_CreateMenu()
_GUICtrlMenu_InsertMenuItem($hHelp, 0, "&About", $idAbout)
; Create Main menu
$hMain = _GUICtrlMenu_CreateMenu()
_GUICtrlMenu_InsertMenuItem($hMain, 0, "&File", 0, $hFile)
_GUICtrlMenu_InsertMenuItem($hMain, 1, "&Edit", 0, $hEdit)
_GUICtrlMenu_InsertMenuItem($hMain, 2, "&Help", 0, $hHelp)
; Set window menu
_GUICtrlMenu_SetMenu($hGUI, $hMain)
; 创建 memo 控件
$iMemo = GUICtrlCreateEdit("", 2, 2, 396, 276, 0)
GUICtrlSetFont($iMemo, 9, 400, 0, "Courier New")
GUISetState()
; 循环直到用户退出
GUIRegisterMsg($WM_COMMAND, "WM_COMMAND")
; 循环直到用户退出
Do
Until GUIGetMsg() = $GUI_EVENT_CLOSE
EndFunc ;==>_Main
; Handle menu commands
Func WM_COMMAND($hWnd, $iMsg, $iwParam, $ilParam)
#forceref $hWnd, $iMsg, $ilParam
Switch _WinAPI_LoWord($iwParam)
Case $idNew
MemoWrite("New")
Case $idOpen
MemoWrite("Open")
Case $idSave
MemoWrite("Save")
Case $idExit
Exit
Case $idCut
MemoWrite("Cut")
Case $idCopy
MemoWrite("Copy")
Case $idPaste
MemoWrite("Paste")
Case $idAbout
MemoWrite("About")
EndSwitch
Return $GUI_RUNDEFMSG
EndFunc ;==>WM_COMMAND
; 写入消息到 memo
Func MemoWrite($sMessage)
GUICtrlSetData($iMemo, $sMessage & @CRLF, 1)
EndFunc ;==>MemoWrite