回复 4# CHEARV
好象 _GUICtrlMenu_AddMenuItem()并没有返回的控件
可以用注册消息的方式,下面是更改后的代码,可以在左键点击按钮后显示菜单,点出菜单运行相应的函数:
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GuiMenu.au3>
Opt("GUIOnEventMode", 1)
#Region ### START Koda GUI section ### Form=
$hGUI = GUICreate("Form2", 413, 298, 302, 218)
GUISetOnEvent($GUI_EVENT_CLOSE, "GUIClose")
$Button1 = GUICtrlCreateButton("Button1", 168, 96, 105, 41)
GUICtrlSetOnEvent(-1, "Button1Click")
Global Enum $id1 = 1000, $id2, $id3
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
While 1
Sleep(100)
WEnd
Func Button1Click()
GUIRegisterMsg($WM_COMMAND, "WM_COMMAND")
$hMenu = _GUICtrlMenu_CreatePopup()
_GUICtrlMenu_AddMenuItem($hMenu, "菜单1", $id1)
_GUICtrlMenu_AddMenuItem($hMenu, "菜单2", $id2)
_GUICtrlMenu_AddMenuItem($hMenu, "菜单3", $id3)
_GUICtrlMenu_TrackPopupMenu($hMenu, $hGUI)
_GUICtrlMenu_DestroyMenu($hMenu)
EndFunc ;==>Button1Click
Func GUIClose()
Exit
EndFunc ;==>GUIClose
Func MyFunc1($i)
MsgBox(0, "Hello", "你点了菜单" & $i)
EndFunc ;==>MyFunc1
Func WM_COMMAND($hWnd, $iMsg, $iwParam, $ilParam)
Switch $iwParam
Case $id1
MyFunc1(1)
Case $id2
MyFunc1(2)
Case $id3
MyFunc1(3)
EndSwitch
EndFunc ;==>WM_COMMAND
|