本帖最后由 飘云 于 2011-3-8 13:34 编辑
另外,如果只是想要点一下就消失的话,其实是不用循环的,循环的作用是保留GUI,你只是需要一个功能选择,选完关闭的效果,那么循环就没意义了,当菜单处于弹出状态时,脚本是被暂停的
#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)
Switch $result[0]
Case 0
MsgBox(0,"","未选择项目")
Case $item_1
MsgBox(0,"","选择了System32")
Case $item_2
MsgBox(0,"","选择了My Documents")
Case Else
MsgBox(0,"","选择了其它")
EndSwitch
GUIDelete()
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 ;==>按钮弹出菜单函数
|