找回密码
 加入
搜索
查看: 3508|回复: 4

[网络通信] 已经自己解决了。。怎么分别读取数组BUTTON。

[复制链接]
发表于 2010-3-2 11:13:25 | 显示全部楼层 |阅读模式
本帖最后由 gogo023 于 2010-3-2 13:13 编辑
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=
Dim $Button[6]
$Form1 = GUICreate("Form1", 462, 97, -1, -1)
$Button[1] = GUICtrlCreateButton("Button1", 16, 8, 75, 25)
$Button[2] = GUICtrlCreateButton("Button2", 104, 8, 75, 25)
$Button[3] = GUICtrlCreateButton("Button3", 192, 8, 75, 25)
$Button[4] = GUICtrlCreateButton("Button4", 280, 8, 75, 25)
$Button[5] = 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按件。
数组不变,怎么读取和实现。点击按键后都是不同的作用。。
发表于 2010-3-2 11:34:43 | 显示全部楼层
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=
Dim $Button[6]
$Form1 = GUICreate("Form1", 462, 97, -1, -1)
$Button[1] = GUICtrlCreateButton("Button1", 16, 8, 75, 25)
$Button[2] = GUICtrlCreateButton("Button2", 104, 8, 75, 25)
$Button[3] = GUICtrlCreateButton("Button3", 192, 8, 75, 25)
$Button[4] = GUICtrlCreateButton("Button4", 280, 8, 75, 25)
$Button[5] = 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
WEnd
p.s, 以前写过一个批量创建控件的udf,今天如有空就整理下,顺便加上在消息循环或事件模式调用的例子
发表于 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[6]
$Form1 = GUICreate("Form1", 462, 97, -1, -1)
$Button[1] = GUICtrlCreateButton("Button1", 16, 8, 75, 25)
$Button[2] = GUICtrlCreateButton("Button2", 104, 8, 75, 25)
$Button[3] = GUICtrlCreateButton("Button3", 192, 8, 75, 25)
$Button[4] = GUICtrlCreateButton("Button4", 280, 8, 75, 25)
$Button[5] = 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

评分

参与人数 1金钱 +25 贡献 +2 收起 理由
afan + 25 + 2

查看全部评分

 楼主| 发表于 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[6]
$Form1 = GUICreate("Form1", 462, 97, -1, -1)
        GUISetOnEvent($GUI_EVENT_CLOSE, "GUI_CLOSE")
$Button[1] = GUICtrlCreateButton("Button1", 16, 8, 75, 25)
        GUICtrlSetOnEvent(-1, "GUI_Button")
$Button[2] = GUICtrlCreateButton("Button2", 104, 8, 75, 25)
        GUICtrlSetOnEvent(-1, "GUI_Button")
$Button[3] = GUICtrlCreateButton("Button3", 192, 8, 75, 25)
        GUICtrlSetOnEvent(-1, "GUI_Button")
$Button[4] = GUICtrlCreateButton("Button4", 280, 8, 75, 25)
        GUICtrlSetOnEvent(-1, "GUI_Button")
$Button[5] = 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[1]
                        MsgBox(0,0,GUICtrlRead($Button[1]))
                Case $Button[2]
                        MsgBox(0,0,GUICtrlRead($Button[2]))
                Case $Button[3]
                        MsgBox(0,0,GUICtrlRead($Button[3]))
                Case $Button[4]
                        MsgBox(0,0,GUICtrlRead($Button[4]))
                Case $Button[5]
                        MsgBox(0,0,GUICtrlRead($Button[5]))                        
        EndSwitch
EndFunc        
发表于 2010-3-3 16:28:12 | 显示全部楼层
回复 5# gogo023


    27-30行可以用4个字符代替'Exit'
您需要登录后才可以回帖 登录 | 加入

本版积分规则

QQ|手机版|小黑屋|AUTOIT CN ( 鲁ICP备19019924号-1 )谷歌 百度

GMT+8, 2024-11-1 07:12 , Processed in 0.081119 second(s), 23 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表