а если мне число этих $Buttons[1] не известно их может быть и 7 и 8?
[решено] При $GUI_EVENT_CLOSE окно зависает.
Код:
Код: Выделить всё
Case $Buttons[1] To $Buttons[Ubound($Buttons)-1]Код: Выделить всё
Case $Buttons[1] To $Buttons[Ubound($Buttons)-1]Код: Выделить всё
#include <GuiConstantsEx.au3>
#include <StaticConstants.au3>
#include <ButtonConstants.au3>
#include <WindowsConstants.au3>
$iRandom = Random(3, 15, 1)
Dim $aButton[$iRandom + 1][3] = [[$iRandom]]
For $i = 1 To $iRandom
$aButton[$i][1] = $i & ' кнопка'
$aButton[$i][2] = $i & '-е действие.'
Next
$hGui = GUICreate('Test', 200, 10 * 2 + 30 * ($iRandom + 1))
$nLabel = GUICtrlCreateLabel('', 20, 10, 160, 20, $SS_CENTER)
For $i = 1 To $iRandom
$aButton[$i][0] = GUICtrlCreateButton($aButton[$i][1], 50, 10 + $i * 30, 100, 20)
Next
GUISetState()
GUIRegisterMsg($WM_COMMAND, 'WM_COMMAND')
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
EndSwitch
;For $i = 1 To $iRandom
; If $nMsg = $aButton[$i][0] Then
; GUICtrlSetData($nLabel, $aButton[$i][2])
; EndIf
;Next
WEnd
Func WM_COMMAND($hWnd, $Msg, $wParam, $lParam)
Local $nNotifyCode = BitShift($wParam, 16)
Local $nID = BitAND($wParam, 0xFFFF)
If $nNotifyCode = $BN_CLICKED Then
For $i = 1 To $iRandom
If $nID = $aButton[$i][0] Then
GUICtrlSetData($nLabel, $aButton[$i][1] & ' ---> ' & $aButton[$i][2])
EndIf
Next
EndIf
Return $GUI_RUNDEFMSG
EndFunc ;==>WM_COMMAND