#include <GuiMenu.au3>

_Main()
_Example()

Func _Main()
	Local $hWnd, $hMain, $hFile, $tInfo

	; Запуск блокнота
	Run("notepad.exe")
	$hWnd = WinWaitActive("[CLASS:Notepad]")
	$hMain = _GUICtrlMenu_GetMenu($hWnd)
	$hFile = _GUICtrlMenu_GetItemSubMenu($hMain, 0)

	; Установить / получить информацию о меню "Файл"
	$tInfo = _GUICtrlMenu_GetMenuInfo($hFile)
	Writeln("Стиль меню ............: " & DllStructGetData($tInfo, "Style"))
	Writeln("Макс. высота меню .....: " & DllStructGetData($tInfo, "YMax"))
	Writeln("Кисть фона меню .......: " & DllStructGetData($tInfo, "hBack"))
	Writeln("Menu context help ID ..: " & DllStructGetData($tInfo, "ContextHelpID"))
	Writeln("Ассоциат. значение ....: " & DllStructGetData($tInfo, "MenuData"))
	Writeln("")
	$tInfo = DllStructCreate($tagMENUINFO)
	DllStructSetData($tInfo, "Size", DllStructGetSize($tInfo))
	DllStructSetData($tInfo, "Mask", BitOR($MIM_HELPID, $MIM_MAXHEIGHT, $MIM_MENUDATA))
	DllStructSetData($tInfo, "YMax", 100)
	DllStructSetData($tInfo, "ContextHelpID", 1234)
	DllStructSetData($tInfo, "MenuData", 4567)
	_GUICtrlMenu_SetMenuInfo($hFile, $tInfo)
	$tInfo = _GUICtrlMenu_GetMenuInfo($hFile)
	Writeln("Стиль меню ............: " & DllStructGetData($tInfo, "Style"))
	Writeln("Макс. высота меню .....: " & DllStructGetData($tInfo, "YMax"))
	Writeln("Кисть фона меню .......: " & DllStructGetData($tInfo, "hBack"))
	Writeln("Menu context help ID ..: " & DllStructGetData($tInfo, "ContextHelpID"))
	Writeln("Ассоциат. значение ....: " & DllStructGetData($tInfo, "MenuData"))
	Writeln("")

EndFunc   ;==>_Main

; Записывает строку текста в блокнот
Func Writeln($sText)
	ControlSend("[CLASS:Notepad]", "", "Edit1", $sText & @CR)
EndFunc   ;==>Writeln


Func _Example()
	Local $iButton, $tPoint, $aPos, $ContMenu, $hGui

	$hGui = GUICreate('Моя программа', 250, 260)
	$iButton = GUICtrlCreateButton('v', 220, 10, 22, 22)
	GUISetState()
	Send('{space}')
	While 1
		Switch GUIGetMsg()
			Case $iButton
					$ContMenu = GUICtrlCreateContextMenu($iButton)
					_SetMenuColor(-1, 0xAAFFFF) ; Устанавливаем цвет меню
					For $i = 1 To 7
						GUICtrlCreateMenuItem('Пункт ' & $i, $ContMenu)
					Next
					$aPos = ControlGetPos($hGui, "", $iButton)
					$tPoint = DllStructCreate("int X;int Y")
					DllStructSetData($tPoint, "X", $aPos[0] + $aPos[2])
					DllStructSetData($tPoint, "Y", $aPos[1] + $aPos[3])
					_WinAPI_ClientToScreen($hGui, $tPoint)
					_GUICtrlMenu_TrackPopupMenu(GUICtrlGetHandle($ContMenu), $hGui, DllStructGetData($tPoint, "X"), DllStructGetData($tPoint, "Y"), 2)
					$tPoint = 0
					GUICtrlDelete($ContMenu)
			Case -3
				Exit
		EndSwitch
	WEnd
EndFunc

Func _SetMenuColor($nMenuID, $nColor)
	Local $tInfo, $hBrush
	$hBrush = _WinAPI_CreateSolidBrush($nColor)
	$tInfo = DllStructCreate($tagMENUINFO)
	DllStructSetData($tInfo, 1, DllStructGetSize($tInfo))
	DllStructSetData($tInfo, 2, BitOR($MIM_APPLYTOSUBMENUS, $MIM_BACKGROUND, $MIM_STYLE))
	DllStructSetData($tInfo, 3, $MNS_NOCHECK)
	DllStructSetData($tInfo, 5, $hBrush)
	_GUICtrlMenu_SetMenuInfo(GUICtrlGetHandle($nMenuID), $tInfo)
	; _WinAPI_DeleteObject($hBrush)
EndFunc   ;==>_SetMenuColor