回复 1# kk_lee69
这样就得声明全局变量
#include <GUIConstantsEx.au3>
#include <WinAPI.au3>
#include <WindowsConstants.au3>
Opt("GUIOnEventMode", 1) ;使用事件模式
Global $BUTTON1, $BUTTON2, $B3, $B100
WinMain()
Func WinMain()
$WinMain = GUICreate("主程式")
GUISetOnEvent($GUI_EVENT_CLOSE, "_Form1Close")
$BUTTON1 = GUICtrlCreateButton('方式1', 15, 125, 100, 25)
$BUTTON2 = GUICtrlCreateButton('方式2', 125, 125, 100, 25)
$B3 = GUICtrlCreateButton('方式3', 235, 125, 100, 25)
$B100 = GUICtrlCreateButton('方式4', 15, 165, 100, 25) ;100個按鈕
GUISetState(@SW_SHOW, $WinMain)
GUIRegisterMsg($WM_COMMAND, "WM_COMMAND")
EndFunc ;==>WinMain
While 1
Sleep(20)
WEnd
Func _Form1Close()
GUIDelete()
Exit
EndFunc ;==>_Form1Close
Func WM_COMMAND($hWnd, $iMsg, $wParam, $lParam)
Local $hWndFrom = $lParam
Local $wID = _WinAPI_LoWord($wParam)
Local $iCode = _WinAPI_HiWord($wParam)
Switch $wID
Case $BUTTON1
MsgBox(0, "", "Button1", 1)
GUICtrlSetData($wID, '点击了')
Case $B3
MsgBox(0, "", "B3", 1)
GUICtrlSetData($wID, '点击了')
Case $BUTTON2
MsgBox(0, "", "Button2", 1)
GUICtrlSetData($wID, '点击了')
Case $B100
MsgBox(0, "", "B100", 1)
GUICtrlSetData($wID, '点击了')
EndSwitch
EndFunc ;==>WM_COMMAND
|