Цитата:
Цитата malev
как сделать меню с элементами цикле (ПунктМеню1, ПунктМеню2, ПунктМеню3) и чтобы для каждого была своя обработка »
|
Изменённый пример из справки:
Код:
#include <GUIConstantsEx.au3>
#include <ButtonConstants.au3>
;
$hGUI = GUICreate("My GUI", 170, 40)
$OptionsBtn = GUICtrlCreateButton("&Options", 10, 10, 70, 20, $BS_FLAT)
; At first create a dummy control for the options and a contextmenu for it
$OptionsDummy = GUICtrlCreateDummy()
$OptionsContext = GUICtrlCreateContextMenu($OptionsDummy)
$OptionsCommon = GUICtrlCreateMenuItem("Common", $OptionsContext)
$OptionsFile = GUICtrlCreateMenuItem("File", $OptionsContext)
GUICtrlCreateMenuItem("", $OptionsContext)
$OptionsExit = GUICtrlCreateMenuItem("Exit", $OptionsContext)
$HelpBtn = GUICtrlCreateButton("&Help", 90, 10, 70, 20, $BS_FLAT)
; Create a dummy control and a contextmenu for the help too
$HelpDummy = GUICtrlCreateDummy()
$HelpContext = GUICtrlCreateContextMenu($HelpDummy)
$HelpWWW = GUICtrlCreateMenuItem("Website", $HelpContext)
GUICtrlCreateMenuItem("", $HelpContext)
$HelpAbout = GUICtrlCreateMenuItem("About...", $HelpContext)
GUISetState()
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $OptionsExit, $GUI_EVENT_CLOSE
If $nMsg = $OptionsExit Then MsgBox(64, 'Title', "[Exit] item selected.", 0, $hGUI)
ExitLoop
Case $OptionsCommon
MsgBox(64, 'Common...', "[Common] item selected.", 0, $hGUI)
Case $OptionsFile
MsgBox(64, 'File...', "[File] item selected.", 0, $hGUI)
Case $OptionsBtn
ShowMenu($hGUI, $nMsg, $OptionsContext)
Case $HelpBtn
ShowMenu($hGUI, $nMsg, $HelpContext)
Case $HelpWWW
MsgBox(64, "WWW...", "www.autoitscript.com", 0, $hGUI)
ShellExecute("www.autoitscript.com")
Case $HelpAbout
MsgBox(64, "About...", "GUICtrlGetHandle-Sample", 0, $hGUI)
EndSwitch
WEnd
; Show a menu in a given GUI window which belongs to a given GUI ctrl
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]
ClientToScreen($hWnd, $x, $y)
TrackPopupMenu($hWnd, $hMenu, $x, $y)
EndFunc ;==>ShowMenu
; Convert the client (GUI) coordinates to screen (desktop) coordinates
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)
; release Struct not really needed as it is a local
$stPoint = 0
EndFunc ;==>ClientToScreen
; Show at the given coordinates (x, y) the popup menu (hMenu) which belongs to a given GUI window (hWnd)
Func TrackPopupMenu($hWnd, $hMenu, $x, $y)
DllCall("user32.dll", "int", "TrackPopupMenuEx", "hwnd", $hMenu, "int", 0, "int", $x, "int", $y, "hwnd", $hWnd, "ptr", 0)
EndFunc ;==>TrackPopupMenu
|