Ticket #986: _b.au3

File _b.au3, 2.5 KB (added by c.haslam, 13 years ago)

Clearer example

Line 
1#include <GuiMenu.au3>
2#include <GuiConstantsEx.au3>
3#include <WinAPI.au3>
4#include <WindowsConstants.au3>
5
6Opt('MustDeclareVars', 1)
7
8Global $iMemo
9Global Enum $idNew = 1000, $idOpen, $idSave, $idExit, $idCut, $idCopy, $idPaste, $idAbout
10
11_Main()
12
13Func _Main()
14    Local $hGUI, $hFile, $hEdit, $hHelp, $hMain,$hMenu
15
16    ; Create GUI
17    $hGUI = GUICreate("Menu", 400, 300)
18
19    ; Create File menu
20    $hFile = _GUICtrlMenu_CreateMenu ()
21    _GUICtrlMenu_InsertMenuItem ($hFile, 0, "&New", $idNew)
22    _GUICtrlMenu_InsertMenuItem ($hFile, 1, "&Open", $idOpen)
23    _GUICtrlMenu_InsertMenuItem ($hFile, 2, "&Save", $idSave)
24    _GUICtrlMenu_InsertMenuItem ($hFile, 3, "", 0)
25    _GUICtrlMenu_InsertMenuItem ($hFile, 4, "E&xit", $idExit)
26
27    ; Create Edit menu
28    $hEdit = _GUICtrlMenu_CreateMenu ()
29    _GUICtrlMenu_InsertMenuItem ($hEdit, 0, "&Cut", $idCut)
30    _GUICtrlMenu_InsertMenuItem ($hEdit, 1, "C&opy", $idCopy)
31    _GUICtrlMenu_InsertMenuItem ($hEdit, 2, "&Paste", $idPaste)
32
33    ; Create Help menu
34    $hHelp = _GUICtrlMenu_CreateMenu ()
35    _GUICtrlMenu_InsertMenuItem ($hHelp, 0, "&About", $idAbout)
36
37    ; Create Main menu
38    $hMain = _GUICtrlMenu_CreateMenu ()
39    _GUICtrlMenu_InsertMenuItem ($hMain, 0, "&File", 0, $hFile)
40    _GUICtrlMenu_InsertMenuItem ($hMain, 1, "&Edit", 0, $hEdit)
41    _GUICtrlMenu_InsertMenuItem ($hMain, 2, "&Help", 0, $hHelp)
42
43    ; Set window menu
44    $hMenu = _GUICtrlMenu_SetMenu ($hGUI, $hMain)
45         
46         _GUICtrlMenu_EnableMenuItem($hFile,$idOpen,1,False)
47
48    ; Create memo control
49    $iMemo = GUICtrlCreateEdit("", 2, 2, 396, 276, 0)
50    GUICtrlSetFont($iMemo, 9, 400, 0, "Courier New")
51    GUISetState()
52
53    ; Loop until user exits
54    GUIRegisterMsg($WM_COMMAND, "WM_COMMAND")
55
56    ; Loop until user exits
57    Do
58    Until GUIGetMsg() = $GUI_EVENT_CLOSE
59EndFunc   ;==>_Main
60
61; Handle menu commands
62Func WM_COMMAND($hWnd, $iMsg, $iwParam, $ilParam)
63    Switch _WinAPI_LoWord ($iwParam)
64        Case $idNew
65            MemoWrite("New")
66        Case $idOpen
67            MemoWrite("Open")
68        Case $idSave
69            MemoWrite("Save")
70        Case $idExit
71            Exit
72        Case $idCut
73            MemoWrite("Cut")
74        Case $idCopy
75            MemoWrite("Copy")
76        Case $idPaste
77            MemoWrite("Paste")
78        Case $idAbout
79            MemoWrite("About")
80    EndSwitch
81    Return $GUI_RUNDEFMSG
82EndFunc   ;==>WM_COMMAND
83
84; Write message to memo
85Func MemoWrite($sMessage)
86    GUICtrlSetData($iMemo, $sMessage & @CRLF, 1)
87 EndFunc   ;==>MemoWrite