#include <WindowsConstants.au3>
#include <MenuConstants.au3>
#include <GUIConstantsEx.au3>
Global $k = 0
GUIRegisterMsg($WM_MENUSELECT, "WM_MENUSELECT")
$Gui = GUICreate("WM_MENUSELECT", 590, 270)
GUICtrlCreateLabel('Функция WM_MENUSELECT срабатывает в момент выбора главного или контекстного меню и его пунктов.', 5, 5, 380, 34)
$FileMenu = GUICtrlCreateMenu('&File')
GUICtrlCreateMenuItem('Открыть', $FileMenu)
GUICtrlSetState(-1, $GUI_CHECKED)
GUICtrlCreateMenuItem('Сохранить', $FileMenu)
GUICtrlSetState(-1, $GUI_DISABLE)
GUICtrlCreateMenuItem('Выход', $FileMenu)
$HelpMenu = GUICtrlCreateMenu('Справка')
GUICtrlCreateMenuItem('Web', $HelpMenu)
GUICtrlCreateMenuItem('Поддержка', $HelpMenu)

$statist = GUICtrlCreateLabel('', 425, 40, 165, 234)

$ContMenu = GUICtrlCreateContextMenu()
GUICtrlCreateMenuItem('Удалить', $ContMenu)
GUICtrlCreateMenuItem('Выход', $ContMenu)

GUISetState()

Do
Until GUIGetMsg() = -3

Func WM_MENUSELECT($hWnd, $Msg, $wParam, $lParam)
	Local $ID = BitAND($wParam, 0xFFFF) ; _WinAPI_LoWord
	Local $Flags = BitShift($wParam, 16) ; _WinAPI_HiWord
	$k += 1
	WinSetTitle($Gui, '', 'Вызов ' & $k)
	Local $info = ''
	If BitAND($Flags, $MF_CHECKED) Then $info &= 'MF_CHECKED' & @CRLF
	If BitAND($Flags, $MF_DISABLED) Then $info &= 'MF_DISABLED' & @CRLF
	If BitAND($Flags, $MF_GRAYED) Then $info &= 'MF_GRAYED' & @CRLF
	If BitAND($Flags, $MF_HILITE) Then $info &= 'MF_HILITE' & @CRLF
	If BitAND($Flags, $MF_MOUSESELECT) Then $info &= 'MF_MOUSESELECT' & @CRLF
	If BitAND($Flags, $MF_OWNERDRAW) Then $info &= 'MF_OWNERDRAW' & @CRLF
	If BitAND($Flags, $MF_POPUP) Then $info &= 'MF_POPUP' & @CRLF
	If BitAND($Flags, $MF_SYSMENU) Then $info &= 'MF_SYSMENU' & @CRLF

	GUICtrlSetData($statist, _
			'Дескриптор = ' & $lParam & @CRLF & _
			'ID = ' & $ID & @CRLF & _
			'Flags:' & $Flags & @CRLF & $info)
EndFunc