#include <GuiMenu.au3>
#include <Array.au3>
Opt('GUIOnEventMode', 1)
Local $aNum[4] = [1, 2, 3, 4]
GUICreate('右键菜单动态建立 by afan', 200, 100)
GUISetOnEvent(-3, '_Exit')
GUISetState()
$iLb = GUICtrlCreateLabel('', 50, 10, 60, 12)
GUIRegisterMsg(0x0111, '_WM_COMMAND')
GUIRegisterMsg(0x007B, '_WM_CONTEXTMENU')
While 1
Sleep(100)
WEnd
Func _Exit()
Exit
EndFunc ;==>_Exit
Func _WM_COMMAND($hWnd, $iMsg, $iwParam)
Switch $iwParam
Case 1000 To 1004
$ix = _ArraySearch($aNum, Number($iwParam) - 1000)
_ArrayDelete($aNum, $ix)
GUICtrlSetData($iLb, GUICtrlRead($iLb) & Number($iwParam) - 1000)
Case 1008
Dim $aNum[4] = [1, 2, 3, 4]
GUICtrlSetData($iLb, '')
EndSwitch
EndFunc ;==>_WM_COMMAND
Func _WM_CONTEXTMENU($hWnd)
Local $hMenu = _GUICtrlMenu_CreatePopup()
For $i = 0 To UBound($aNum) - 1
_GUICtrlMenu_AddMenuItem($hMenu, $aNum[$i], 1000 + $aNum[$i])
Next
_GUICtrlMenu_AddMenuItem($hMenu, '')
_GUICtrlMenu_AddMenuItem($hMenu, '重置', 1008)
_GUICtrlMenu_TrackPopupMenu($hMenu, $hWnd)
_GUICtrlMenu_DestroyMenu($hMenu)
EndFunc ;==>_WM_CONTEXTMENU
|