jsnewbee 发表于 2009-3-2 16:18:40

请高手帮改下源码

请高手帮改下源码
这是我写的工具栏菜单,请高手给我把重复的创建控件部分和响应部分改成循环以精减代码
高手能帮我改成Event模式就更好了
这是我的工具条界面,实现自动隐藏

[ 本帖最后由 jsnewbee 于 2009-3-3 09:52 编辑 ]

131738 发表于 2009-3-3 00:47:28

#include <WindowsConstants.au3>
#include <StaticConstants.au3>

Global $Total, $Bu = 500, $Apex = 0
Dim $Button[$Bu]

$Total = IniReadSection("_conf.ini", "LINK")

$Form1 = GUICreate("主窗体", 1000, 35, 20, 5, BitOR _
   ($WS_MINIMIZEBOX,$WS_SIZEBOX,$WS_THICKFRAME,$WS_SYSMENU,$WS_POPUP,$WS_GROUP,$WS_CLIPSIBLINGS))
$Pic1 = GUICtrlCreatePic("bg_hm.jpg", 0, 0, 1000, 35, BitOR($SS_NOTIFY,$WS_GROUP,$WS_CLIPSIBLINGS))

GUISetState()

For $i = 1 To $Total
$Button[$i] = GUICtrlCreateButton($Total[$i], $Apex+55*$i, 2, 50, 30)
Next

While 1
    Sleep(1000)
WEnd
;暂时用按钮代替!坐标你再调整!

漠北雪~狼 发表于 2009-3-3 03:22:40

优化了一下楼上的代码

#include <WindowsConstants.au3>
#include <StaticConstants.au3>
Opt("GUIOnEventMode", 1)

Global $Total, $Bu = 500, $Apex = 0
Dim $Button[$Bu]

$Form1 = GUICreate("主窗体", 1000, 35, 20, 5, BitOR _
                ($WS_MINIMIZEBOX, $WS_SIZEBOX, $WS_THICKFRAME, $WS_SYSMENU, $WS_POPUP, $WS_GROUP, $WS_CLIPSIBLINGS))
;~ $Pic1 = GUICtrlCreatePic("bg_hm.jpg", 0, 0, 1000, 35, BitOR($SS_NOTIFY, $WS_GROUP, $WS_CLIPSIBLINGS))

GUISetState()

$Total = IniReadSection("_conf.ini", "LINK")

For $i = 1 To $Total
        $Button[$i] = GUICtrlCreateButton($Total[$i], $Apex+55*$i, 2, 50, 30)
        $Button[$i] = $Total[$i]
        GUICtrlSetOnEvent($Button[$i], "B_Msg")
Next

While 1
        Sleep(1000)
WEnd

Func B_Msg()
        MsgBox(0, 0, 0)
        For $i = 1 To UBound($Button, 1) - 1
                If @GUI_CtrlId = $Button[$i] Then Run($Button[$i])
        Next
EndFunc   ;==>B_Msg

jsnewbee 发表于 2009-3-3 09:52:43

谢谢了,感谢楼上两位
页: [1]
查看完整版本: 请高手帮改下源码