1 | #include <GuiMenu.au3> |
---|
2 | #include <GuiConstantsEx.au3> |
---|
3 | #include <WinAPI.au3> |
---|
4 | #include <WindowsConstants.au3> |
---|
5 | |
---|
6 | Opt('MustDeclareVars', 1) |
---|
7 | |
---|
8 | Global Enum $idOpen = 1000, $idSave, $idInfo |
---|
9 | |
---|
10 | _Main() |
---|
11 | |
---|
12 | Func _Main() |
---|
13 | Local $hGUI |
---|
14 | |
---|
15 | ; Create GUI |
---|
16 | $hGUI = GUICreate("Menu", 400, 300) |
---|
17 | GUISetState() |
---|
18 | |
---|
19 | ; Register message handlers |
---|
20 | GUIRegisterMsg($WM_COMMAND, "WM_COMMAND") |
---|
21 | GUIRegisterMsg($WM_CONTEXTMENU, "WM_CONTEXTMENU") |
---|
22 | |
---|
23 | ; Loop until user exits |
---|
24 | Do |
---|
25 | Until GUIGetMsg() = $GUI_EVENT_CLOSE |
---|
26 | EndFunc ;==>_Main |
---|
27 | |
---|
28 | ; Handle WM_COMMAND messages |
---|
29 | Func WM_COMMAND($hWnd, $iMsg, $iwParam, $ilParam) |
---|
30 | Switch $iwParam |
---|
31 | Case $idOpen |
---|
32 | _WinAPI_ShowMsg ("Open") |
---|
33 | Case $idSave |
---|
34 | _WinAPI_ShowMsg ("Save") |
---|
35 | Case $idInfo |
---|
36 | _WinAPI_ShowMsg ("Info") |
---|
37 | EndSwitch |
---|
38 | EndFunc ;==>WM_COMMAND |
---|
39 | |
---|
40 | ; Handle WM_CONTEXTMENU messages |
---|
41 | Func WM_CONTEXTMENU($hWnd, $iMsg, $iwParam, $ilParam) |
---|
42 | Local $hMenu |
---|
43 | |
---|
44 | $hMenu = _GUICtrlMenu_CreatePopup () |
---|
45 | _GUICtrlMenu_InsertMenuItem ($hMenu, 0, "Open", $idOpen) |
---|
46 | _GUICtrlMenu_InsertMenuItem ($hMenu, 1, "Save", $idSave) |
---|
47 | _GUICtrlMenu_InsertMenuItem ($hMenu, 3, "", 0) |
---|
48 | _GUICtrlMenu_InsertMenuItem ($hMenu, 3, "Info", $idInfo) |
---|
49 | _GUICtrlMenu_TrackPopupMenu ($hMenu, $iwParam) |
---|
50 | _GUICtrlMenu_DestroyMenu ($hMenu) |
---|
51 | Return True |
---|
52 | EndFunc ;==>WM_CONTEXTMENU |
---|