本帖最后由 飘云 于 2011-3-6 15:59 编辑
回复 14# happytc
很简单啊,定义个全局变量Global $result[1],然后弹出函数的调用是有返回值的,$result=DllCall("user32.dll", "int", "TrackPopupMenuEx", "hwnd", GUICtrlGetHandle($nContextID), "int", 0x0100, "int", $moPos[0], "int", $moPos[1], "hwnd", $hWnd, "ptr", 0);弹出菜单,注意第2个参数变为0x0100,然后返回到变量$result中,最后在while循环中加入
If $result[0]=0 Then
GUIDelete()
ExitLoop
EndIf
即可
关于TrackPopupMenuEx函数具体可查看MSDN资料库中的说明
#NoTrayIcon
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
Global $result[1]
$form = GUICreate("", 100, 100, -1000, -1000, -1, -1,WinGetHandle(AutoItWinGetTitle()))
GUISetState()
$context = GUICtrlCreateContextMenu()
$item_1 = GUICtrlCreateMenuItem("System32",$context)
$item_2 = GUICtrlCreateMenuItem("My Documents",$context)
GUICtrlCreateMenuItem("",$context)
$item_3 = GUICtrlCreateMenuItem("C Drive",$context)
$item_4 = GUICtrlCreateMenuItem("D Drive",$context)
GUICtrlCreateMenuItem("",$context)
$item_5 = GUICtrlCreateMenu("Utilities",$context)
$item_6 = GUICtrlCreateMenu("Command Line",$context)
GUICtrlCreateMenuItem("",$context)
$item_7 = GUICtrlCreateMenuItem("Internet",$context)
GUICtrlCreateMenuItem("",$context)
$item_8 = GUICtrlCreateMenuItem("Configure...",$context)
ShowMenu($form,$context)
While 1
Sleep(1000)
$msg = GUIGetMsg()
Switch $msg
Case $item_1
ExitLoop
Case $item_2
MsgBox(0,0,"0k")
EndSwitch
If $result[0]=0 Then
GUIDelete()
ExitLoop
EndIf
WEnd
Func ShowMenu($hWnd, $nContextID)
Local $moPos = MouseGetPos()
$result=DllCall("user32.dll", "int", "TrackPopupMenuEx", "hwnd", GUICtrlGetHandle($nContextID), "int", 0x0100, "int", $moPos[0], "int", $moPos[1], "hwnd", $hWnd, "ptr", 0);弹出菜单
EndFunc ;==>按钮弹出菜单函数
|