Ticket #1337: _GUICtrlMenu_CreatePopup.au3

File _GUICtrlMenu_CreatePopup.au3, 1.3 KB (added by danielkza2@…, 14 years ago)

_GUICtrlMenu_CreatePopup Example

Line 
1#include <GuiMenu.au3>
2#include <GuiConstantsEx.au3>
3#include <WinAPI.au3>
4#include <WindowsConstants.au3>
5
6Opt('MustDeclareVars', 1)
7
8Global Enum $idOpen = 1000, $idSave, $idInfo
9
10_Main()
11
12Func _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
26EndFunc   ;==>_Main
27
28; Handle WM_COMMAND messages
29Func 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
38EndFunc   ;==>WM_COMMAND
39
40; Handle WM_CONTEXTMENU messages
41Func 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
52EndFunc   ;==>WM_CONTEXTMENU