找回密码
 加入
搜索
查看: 7769|回复: 15

[GUI管理] 点击循环创建的控件,触发不同指令

  [复制链接]
发表于 2012-9-16 19:22:47 | 显示全部楼层 |阅读模式
本帖最后由 qq4045728 于 2012-9-17 18:20 编辑
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#region ### START Koda GUI section ### Form=

Dim $sq = 5 ;软件列表数量

$Form1 = GUICreate("列表", 481, 85 * $sq + 60, -1, -1)
$www = GUICtrlCreateLabel("点击查看更多软件", 170, 86 * $sq, 200, 17)
GUICtrlSetFont($www, 9.5, -1, 4)
GUICtrlSetColor($www, 0x0000FF)
GUICtrlSetCursor($www, 0)
GUICtrlCreateGroup("", -99, -99, 1, 1)
GUICtrlCreateLabel("上面仅列出本工具支持的软件.", 5, 86 * $sq, 165, 17)
GUICtrlSetColor(-1, 0xFF0000)

Local $systemtxt[1][3]
dim $cc=0

For $l = 1 To $sq Step 1

        If $l > 1 Then
                $s = $l - 1
                Dim $g = 85 * $s
        Else
                Dim $g = 0
        EndIf

        $txt = GUICtrlCreateLabel("xxxxxxxxxxx软件", 8, $g + 5, 303, 20)
        GUICtrlSetFont(-1, 11, 800, 0, "MS Sans Serif")
        $txt = GUICtrlCreateLabel("大小:10MB", 16, 56 + $g, 77, 17)
        $txt = GUICtrlCreateLabel("制作时间:2012.08.09", 104, 56 + $g, 126, 17)
        $txt = GUICtrlCreateLabel("MD5:70728C6D7FE68CDD71322825DA1B641C", 16, 35 + $g, 281, 17)
        GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
        GUICtrlSetColor(-1, 0xFF0000)
        ReDim $systemtxt[$cc + 1][3]
;~         ;载入控件ID到数组第一列
        $systemtxt[$cc][0] = GUICtrlCreateLabel(">>点击查看说明", 240, 56 + $g, 88, 17)
        ;载入网址到数组第二列
        $systemtxt[$cc][1] = IniRead("urllist.ini","url",$cc+1,"1")
        GUICtrlSetFont($systemtxt[$cc][0], 9.5, -1, 4)
        GUICtrlSetColor($systemtxt[$cc][0], 0x0000FF)
        GUICtrlSetCursor($systemtxt[$cc][0], 0)
        $txt = GUICtrlCreateButton("HTTP下载", 392, 32 + $g, 75, 17)
        $txt = GUICtrlCreateButton("迅雷下载", 392, 56 + $g, 75, 17)
        GUICtrlCreateLabel("", 0, 80 + $g, 485, 5, $SS_ETCHEDHORZ) ;;分割线
        
        $cc=$cc+1
Next

GUISetState(@SW_SHOW)
#endregion ### END Koda GUI section ###

While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
                Case $GUI_EVENT_CLOSE
                        Exit
                Case $www
                        ShellExecute("www.baidu.com")
                        
                ;判断用户点击控件ID
                Case  $systemtxt[0][0] To $systemtxt[$cc-1][0]
                        
                        For $i=0 To $cc-1
                                ;捕获被点击控件ID
                                If $systemtxt[$i][0]=$nMsg Then 
                                        ;控件ID标示对应网址列表序号,实现对应点击
                                        ShellExecute($systemtxt[$i][1])
;~                                         MsgBox(0,0,$i)
                                EndIf
                        Next
;~                         ShellExecute("www.baidu.com/xxxxxx")
        EndSwitch
WEnd
问题:点击控件$systemtxt[$l] 弹出对应的网址。


hnjn大牛给的代码。 顺便分享一下给大家
发表于 2012-9-16 19:34:04 | 显示全部楼层
case后面要跟指定的控件,这样做,必须指定索引的具体值
 楼主| 发表于 2012-9-16 19:50:13 | 显示全部楼层
回复 2# netegg

不知道索引的具体值有几个。 case这里要怎么写?  或者有其他办法吗?比如fun
 楼主| 发表于 2012-9-16 19:51:16 | 显示全部楼层
回复 2# netegg

不知道索引的具体值有几个。 case这里要怎么写?  或者有其他办法吗?比如fun
发表于 2012-9-16 19:58:07 | 显示全部楼层
一看代码就知道楼主你刚开始学习,你得先从帮助那理解下那些简单的例子,才可以再尝试搞些自己的东西的啊!

控件变量想只用一个代表一堆,这实在是太没经过学习理解了!
发表于 2012-9-16 20:03:02 | 显示全部楼层
For $l = 1 To $sq Step 1


;这下面的数量循环,有什么意义?
;最后还不是只得到一个结果,之前的运算全被后面的冲没了!
If $l > 1 then
        $s = $l - 1 
        Dim $g = 85 * $s
else
    Dim $g = 0
endif

;这下面的控件变量$txt,你到底想给那个控件用?
$txt = GUICtrlCreateLabel("xxxxxxxxxxx软件", 8,$g +5, 303, 20)
GUICtrlSetFont(-1, 11, 800, 0, "MS Sans Serif")
$txt = GUICtrlCreateLabel("大小:10MB", 16, 56 + $g, 77, 17)
$txt = GUICtrlCreateLabel("制作时间:2012.08.09", 104, 56 + $g, 126, 17)
$txt = GUICtrlCreateLabel("MD5:70728C6D7FE68CDD71322825DA1B641C", 16, 35 + $g, 281, 17)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
GUICtrlSetColor(-1, 0xFF0000)

;这个本来要动态赋值的控件数组,在这完全没动!
$systemtxt[$l] = GUICtrlCreateLabel(">>点击查看说明", 240, 56 + $g, 88, 17)
GUICtrlSetFont($systemtxt[$l],9.5, -1 ,4)
GUICtrlSetColor($systemtxt[$l], 0x0000FF)
GUICtrlSetCursor($systemtxt[$l],0)      

;又是两个$txt!!!
$txt = GUICtrlCreateButton("HTTP下载", 392, 32 + $g, 75, 17)
$txt = GUICtrlCreateButton("迅雷下载", 392, 56 + $g, 75, 17)
 楼主| 发表于 2012-9-16 20:13:35 | 显示全部楼层
本帖最后由 qq4045728 于 2012-9-16 20:16 编辑

回复 6# liongodmien

呵呵。你压根不知道我的思路。这还是只是一个样本。因为思路还没搞通。那么认真去写太浪费精力了。
帮忙下吧。我那个问题怎么解决
发表于 2012-9-16 20:35:11 | 显示全部楼层
本帖最后由 netegg 于 2012-9-16 20:39 编辑

[au3]#include <GUIConstantsEx.au3>

Example()

Func Example()
        Local $msg, $button[4]
        GUICreate("My GUI Button") ; 创建一个对话框,并居中显示

        For $i = 1 To 3
               
                $button[$i]= GUICtrlCreateButton($i, 100, 10 + $i * 20, 50, 16)
        Next
        GUISetState() ; 显示有两个按钮的对话框

        ; 运行界面,直到窗口被关闭
        While 1
                $msg = GUIGetMsg()
                Select
                        Case $msg = $GUI_EVENT_CLOSE
                                ExitLoop
                        Case $msg = $button[1]
                                MsgBox(0,0,'button[1]') ; 点击按钮 1
                        Case $msg = $button[2]
                                MsgBox(0,0,'button[2]') ; 点击按钮 2
                        Case $msg = $button[3]
                                MsgBox(0,0,'button[3]') ; 点击按钮 3
                EndSelect
#cs
                Switch $msg
                        Case  $GUI_EVENT_CLOSE
                                ExitLoop
                        Case $button[1]
                                MsgBox(0,0,'button[1]') ; 点击按钮 1
                        Case $button[2]
                                MsgBox(0,0,'button[2]') ; 点击按钮 2
                        Case $button[3]
                                MsgBox(0,0,'button[3]') ; 点击按钮 3
#ce                EndSelect

        WEnd
EndFunc   ;==>Example
[/au3]
发表于 2012-9-16 20:49:16 | 显示全部楼层
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#region ### START Koda GUI section ### Form=

Dim $sq = 5, $systemtxt[$sq], $g ;软件列表数量

$Form1 = GUICreate("列表", 481, 85 * $sq + 60, -1, -1)
$www = GUICtrlCreateLabel("点击查看更多软件", 170, 86 * $sq, 200, 17)
GUICtrlSetFont($www, 9.5, -1, 4)
GUICtrlSetColor($www, 0x0000FF)
GUICtrlSetCursor($www, 0)
GUICtrlCreateGroup("", -99, -99, 1, 1)
GUICtrlCreateLabel("上面仅列出本工具支持的软件.", 5, 86 * $sq, 165, 17)
GUICtrlSetColor(-1, 0xFF0000)

For $l = 1 To $sq
        $s = $l - 1
        $g = 85 * $s

        GUICtrlCreateLabel("xxxxxxxxxxx软件", 8, $g + 5, 303, 20)
        GUICtrlSetFont(-1, 11, 800, 0, "MS Sans Serif")
        GUICtrlCreateLabel("大小:10MB", 16, 56 + $g, 77, 17)
        GUICtrlCreateLabel("制作时间:2012.08.09", 104, 56 + $g, 126, 17)
        GUICtrlCreateLabel("MD5:70728C6D7FE68CDD71322825DA1B641C", 16, 35 + $g, 281, 17)
        GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
        GUICtrlSetColor(-1, 0xFF0000)
        $systemtxt[$s] = GUICtrlCreateLabel(">>点击查看说明", 240, 56 + $g, 88, 17)
        GUICtrlSetFont(-1, 9.5, -1, 4)
        GUICtrlSetColor(-1, 0x0000FF)
        GUICtrlSetCursor(-1, 0)
        $txt = GUICtrlCreateButton("HTTP下载", 392, 32 + $g, 75, 17)
        $txt = GUICtrlCreateButton("迅雷下载", 392, 56 + $g, 75, 17)
        GUICtrlCreateLabel("", 0, 80 + $g, 485, 5, $SS_ETCHEDHORZ) ;;分割线
Next

GUISetState(@SW_SHOW)
#endregion ### END Koda GUI section ###


While 1
        Switch GUIGetMsg()
                Case -3
                        Exit
                        
                Case $www
                        ShellExecute("www.baidu.com")
                        
                Case $systemtxt[0] To $systemtxt[$sq - 1]
                        ShellExecute("www.baidu.com/xxxxxx")
        EndSwitch
WEnd
太久没写东西了,都不大会写了
发表于 2012-9-16 20:50:29 | 显示全部楼层
回复 7# qq4045728


    就算只是个思路,也不能太乱啊,这会更加影响深入思考
发表于 2012-9-16 20:52:37 | 显示全部楼层
回复 9# liongodmien

case ... to 好像不行,lz不是说要不同按钮执行不同命令吗
发表于 2012-9-16 20:55:07 | 显示全部楼层
回复  liongodmien

case ... to 好像不行,lz不是说要不同按钮执行不同命令吗
netegg 发表于 2012-9-16 20:52



    我只是按楼主的代码改写的,既然他说我不明白他的思路(其实我也不想明白,因为我不搞这个东东),所以就按他原来的改成可用就算了,如果要细分,在下一级再CASE
发表于 2012-9-16 21:06:51 | 显示全部楼层
回复 12# liongodmien
其实我怀疑lz自己都不清楚到底要做什么
 楼主| 发表于 2012-9-17 10:54:00 | 显示全部楼层
回复 13# netegg


    我的问题是:$systemtxt[$l] = GUICtrlCreateLabel    这个文本控件数量不确定有多少个。然后点击$systemtxt[$l] = GUICtrlCreateLabel 控件触发不同指令
发表于 2012-9-17 11:10:36 | 显示全部楼层
本帖最后由 netegg 于 2012-9-17 11:19 编辑

回复 14# qq4045728
控件数量不确定,那请问控件是怎么创建的
[au3]Dim $sq = 5 ;软件列表数量
....
For $l = 1 To $sq Step 1
...[/au3]
按你的代码,请问这个怎么不确定了?
您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2024-5-18 18:39 , Processed in 0.090251 second(s), 24 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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