gogo023 发表于 2010-3-2 11:13:25

已经自己解决了。。怎么分别读取数组BUTTON。

本帖最后由 gogo023 于 2010-3-2 13:13 编辑

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=
Dim $Button
$Form1 = GUICreate("Form1", 462, 97, -1, -1)
$Button = GUICtrlCreateButton("Button1", 16, 8, 75, 25)
$Button = GUICtrlCreateButton("Button2", 104, 8, 75, 25)
$Button = GUICtrlCreateButton("Button3", 192, 8, 75, 25)
$Button = GUICtrlCreateButton("Button4", 280, 8, 75, 25)
$Button = GUICtrlCreateButton("Button5", 368, 8, 75, 25)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
                Case $GUI_EVENT_CLOSE
                        Exit

        EndSwitch
WEnd
上面这段代码,我想实现。分别点击BUTTON按件。
数组不变,怎么读取和实现。点击按键后都是不同的作用。。

afan 发表于 2010-3-2 11:34:43

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=
Dim $Button
$Form1 = GUICreate("Form1", 462, 97, -1, -1)
$Button = GUICtrlCreateButton("Button1", 16, 8, 75, 25)
$Button = GUICtrlCreateButton("Button2", 104, 8, 75, 25)
$Button = GUICtrlCreateButton("Button3", 192, 8, 75, 25)
$Button = GUICtrlCreateButton("Button4", 280, 8, 75, 25)
$Button = GUICtrlCreateButton("Button5", 368, 8, 75, 25)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
        $nMsg = GUIGetMsg()
        For $i = 1 To 5
                Switch $nMsg
                        Case $GUI_EVENT_CLOSE
                                Exit
                        Case $Button[$i]
                                MsgBox(0, 0, 'Button' & $i)
                EndSwitch
        Next
WEndp.s, 以前写过一个批量创建控件的udf,今天如有空就整理下,顺便加上在消息循环或事件模式调用的例子

yangdai 发表于 2010-3-2 21:07:19

本帖最后由 yangdai 于 2010-3-2 21:14 编辑

想看看樓主的解法
----------------------------
這樣也可以湊合用
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=
Dim $Button
$Form1 = GUICreate("Form1", 462, 97, -1, -1)
$Button = GUICtrlCreateButton("Button1", 16, 8, 75, 25)
$Button = GUICtrlCreateButton("Button2", 104, 8, 75, 25)
$Button = GUICtrlCreateButton("Button3", 192, 8, 75, 25)
$Button = GUICtrlCreateButton("Button4", 280, 8, 75, 25)
$Button = GUICtrlCreateButton("Button5", 368, 8, 75, 25)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

Do
    $msg = GUIGetMsg()
    if $msg >0 then      
       if ControlGetFocus("")then
          MsgBox(0, 0, ControlGetFocus(""))      
       endif   
    endif
Until $msg = $GUI_EVENT_CLOSE

gogo023 发表于 2010-3-3 16:23:38

我改变了模式,换了个方法。#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
Opt("GUIOnEventMode", 1)
#Region ### START Koda GUI section ### Form=
Dim $Button
$Form1 = GUICreate("Form1", 462, 97, -1, -1)
        GUISetOnEvent($GUI_EVENT_CLOSE, "GUI_CLOSE")
$Button = GUICtrlCreateButton("Button1", 16, 8, 75, 25)
        GUICtrlSetOnEvent(-1, "GUI_Button")
$Button = GUICtrlCreateButton("Button2", 104, 8, 75, 25)
        GUICtrlSetOnEvent(-1, "GUI_Button")
$Button = GUICtrlCreateButton("Button3", 192, 8, 75, 25)
        GUICtrlSetOnEvent(-1, "GUI_Button")
$Button = GUICtrlCreateButton("Button4", 280, 8, 75, 25)
        GUICtrlSetOnEvent(-1, "GUI_Button")
$Button = GUICtrlCreateButton("Button5", 368, 8, 75, 25)
        GUICtrlSetOnEvent(-1, "GUI_Button")
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
        Sleep(10)
WEnd

Func GUI_CLOSE()
        Switch @GUI_CtrlId
                Case $GUI_EVENT_CLOSE
                        Exit
        EndSwitch
EndFunc       

Func GUI_Button()
        Switch @GUI_CtrlId
                Case $Button
                        MsgBox(0,0,GUICtrlRead($Button))
                Case $Button
                        MsgBox(0,0,GUICtrlRead($Button))
                Case $Button
                        MsgBox(0,0,GUICtrlRead($Button))
                Case $Button
                        MsgBox(0,0,GUICtrlRead($Button))
                Case $Button
                        MsgBox(0,0,GUICtrlRead($Button))                       
        EndSwitch
EndFunc       

afan 发表于 2010-3-3 16:28:12

回复 5# gogo023


    27-30行可以用4个字符代替'Exit'
页: [1]
查看完整版本: 已经自己解决了。。怎么分别读取数组BUTTON。