#include <GUIConstantsEx.au3>
#include <ButtonConstants.au3>
Local $hGui, $OptionsBtn, $OptionsDummy, $OptionsContext, $OptionsCommon, $OptionsFile, $msg ;定义变量,常量,或创建数组
Local $OptionsExit ;定义变量,常量,或创建数组
$hGui = GUICreate("AU3", 300, 200);主窗体
$Icon3 = GUICtrlCreateIcon("H:\AU3\AU3安装包\20170318\Images\2\chk1.ico", -1, 32, 120, 16, 16) ;1
$Checkbox3 = GUICtrlCreateCheckbox("中国人民银行", 56, 120, 115, 17)
$aa = GUICtrlCreateLabel("左键菜单", 20, 185, 70, 20, $BS_FLAT);菜单项 位置可自义
$OptionsDummy = GUICtrlCreateDummy();创建虚拟(Dummy)控件
$OptionsContext = GUICtrlCreateContextMenu($OptionsDummy) ;创建控件或 GUI 的上下文菜单主控件
$OptionsCommon = GUICtrlCreateMenuItem("中国人民解放军", $OptionsContext);子菜单项
$OptionsFile = GUICtrlCreateMenuItem("中国人民银行", $OptionsContext);子菜单项
GUICtrlCreateMenuItem("", $OptionsContext) ;行隔断符长线,放在什么地方就是什么地方的分界线
$OptionsExit = GUICtrlCreateMenuItem("退出示例", $OptionsContext) ;子菜单项 要修改的选项变量,常量,或数组
GUISetState()
While 1
$msg = GUIGetMsg()
Switch $msg
Case $OptionsExit, $GUI_EVENT_CLOSE
ExitLoop
Case $aa
ShowMenu($hGui, $msg, $OptionsContext)
EndSwitch
WEnd
GUIDelete()
Func ShowMenu($hWnd, $CtrlID, $nContextID)
Local $arPos, $x, $y
Local $hMenu = GUICtrlGetHandle($nContextID)
$arPos = ControlGetPos($hWnd, "", $CtrlID)
$x = $arPos[0]
$y = $arPos[1] + $arPos[3] ;吸附位置[3]
ClientToScreen($hWnd, $x, $y)
TrackPopupMenu($hWnd, $hMenu, $x, $y)
EndFunc
Func ClientToScreen($hWnd, ByRef $x, ByRef $y)
Local $stPoint = DllStructCreate("int;int")
DllStructSetData($stPoint, 1, $x)
DllStructSetData($stPoint, 2, $y)
DllCall("user32.dll", "int", "ClientToScreen", "hwnd", $hWnd, "ptr", DllStructGetPtr($stPoint))
$x = DllStructGetData($stPoint, 1)
$y = DllStructGetData($stPoint, 2)
$stPoint = 0
EndFunc
Func TrackPopupMenu($hWnd, $hMenu, $x, $y)
DllCall("user32.dll", "int", "TrackPopupMenuEx", "hwnd", $hMenu, "int", 0, "int", $x, "int", $y, "hwnd", $hWnd, "ptr", 0)
EndFunc
左键效果,只是有时候会不在想要的范围内