回复 1# lsszmj
论坛上有.
这是我以前收藏的. 原来是左键菜单, 现在改成右键了.
#include <GuiConstants.au3>
$Gui = GUICreate("test")
$Edit = GUICtrlCreateEdit("", 20, 20)
$DummyMenu = GUICtrlCreateDummy()
$ContextMenu = GUICtrlCreateContextMenu($DummyMenu)
$MenuItem1 = GUICtrlCreateMenuItem("菜单1", $ContextMenu)
$MenuItem2 = GUICtrlCreateMenuItem("菜单2", $ContextMenu)
GUICtrlCreateMenuItem("", $ContextMenu)
$ExitMenuItem = GUICtrlCreateMenuItem("退出", $ContextMenu)
GUISetState()
While 1
$CurInfo = GUIGetCursorInfo($Gui)
$Msg = GUIGetMsg()
Select
Case $Msg = -3
Exit
Case $CurInfo[3] = 1 And $CurInfo[4] = $Edit
ShowMenu($Gui, $ContextMenu)
Case $msg = $ExitMenuItem
Exit
EndSelect
WEnd
; Show a menu in a given GUI window which belongs to a given GUI ctrl
Func ShowMenu($hWnd, $nContextID)
Local $hMenu = GUICtrlGetHandle($nContextID)
$arPos = MouseGetPos()
Local $x = $arPos[0]
Local $y = $arPos[1]
DllCall("user32.dll", "int", "TrackPopupMenuEx", "hwnd", $hMenu, "int", 0, "int", $x, "int", $y, "hwnd", $hWnd, "ptr", 0)
EndFunc
Func _exit()
Exit
EndFunc
左键菜单:Case $CurInfo[2] = 1 And $CurInfo[4] = $Edit
ShowMenu($Gui, $ContextMenu)
|