找回密码
 加入
搜索
查看: 2624|回复: 7

ListBox无法读取数据???

[复制链接]
发表于 2009-1-27 08:39:42 | 显示全部楼层 |阅读模式
;==============================================
UDPStartup()
HotKeySet("{F7}","sends")
#include <GUIConstants.au3>
#Include <GuiListBox.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
;==============================================
#NoTrayIcon
$g_szVersion = "TR Server 1.0"
If WinExists($g_szVersion) Then Exit ; 此脚本已经运行了
AutoItWinSetTitle($g_szVersion)        
;----------------------------------------------

$socket = UDPOpen(@IPAddress1, 30000)
If @error <> 0 Then Exit
Dim $Msg

#Region GUI
$MAINGUI = GUICreate("TR-NET SEND 服务器端 V1.0", 641, 481, 223, 141)
$Group1 = GUICtrlCreateGroup("输入命令:", 8, 380, 617, 89)
$sends = GUICtrlCreateButton("发送(F7)", 560, 400, 57, 57)
$commands02 = GUICtrlCreateEdit("", 16, 400, 537, 57, BitOR($ES_AUTOVSCROLL,$ES_AUTOHSCROLL,$ES_WANTRETURN,$WS_VSCROLL))
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Group2 = GUICtrlCreateGroup("消息列表", 8, 256, 513, 113)
$MessageList = GUICtrlCreateList("", 16, 272, 497, 85,BitOR($ES_AUTOVSCROLL,$ES_AUTOHSCROLL,$ES_WANTRETURN,$WS_VSCROLL,$LBS_NOTIFY))
;--------------------
$file = FileOpen("Message.txt", 0)
While 1
    $line = FileReadLine($file)
    If @error = -1 Then ExitLoop
        _GUICtrlListBox_AddString ( $MessageList, $line )
Wend
;--------------------

GUICtrlCreateGroup("", -99, -99, 1, 1)
$add        = GUICtrlCreateButton("添加",528,330,97,35)
$Group3 = GUICtrlCreateGroup("发送方式:", 528, 256, 97, 65)
$Radio1 = GUICtrlCreateRadio("NET SEND", 536, 280, 81, 17)
$Radio2 = GUICtrlCreateRadio("S/C 模式", 536, 300, 65, 17)
GUICtrlSetState(-1, $GUI_CHECKED)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Group4 = GUICtrlCreateGroup("发送范围:", 8, 160, 617, 89)
$Radio3 = GUICtrlCreateRadio("单一 IP:", 24, 184, 89, 17)
GUICtrlSetState(-1, $GUI_CHECKED)
$Radio4 = GUICtrlCreateRadio("消息群发:", 24, 216, 89, 17)
$Input1 = GUICtrlCreateInput(@IPAddress1, 120, 184, 105, 21)
$Input2 = GUICtrlCreateInput("", 120, 216, 105, 21)
GUICtrlSetState(-1,$GUI_DISABLE)
$Input3 = GUICtrlCreateInput("", 249, 216, 103, 21)
GUICtrlSetState(-1,$GUI_DISABLE)
;---------------------
$ip=@IPAddress1
GUICtrlSetData($Input2,StringLeft($ip,StringInStr($ip,".",0,-1)) & "1")
GUICtrlSetData($Input3,StringLeft($ip,StringInStr($ip,".",0,-1)) & "255")
;---------------------

$Label1 = GUICtrlCreateLabel("到", 232, 224, 16, 17)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$about = GUICtrlCreateEdit("", 8, 8, 617, 145, BitOR($ES_AUTOVSCROLL,$ES_AUTOHSCROLL,$ES_WANTRETURN,$WS_VSCROLL))
GUICtrlSetData(-1, "说明:" & @CRLF & "使用 NET SEND 方式发送无需客户端,只需在主机和分机上面打开Message(消息)服务.缺点是只能发送一行消息"& @CRLF & _ 
                                        "客户端运行一次即可实现自启动,无需再添加注册表"& @CRLF & _
                                        "可以定义程序目录下面的Message.txt中的内容来实现预定义文本."& @CRLF & _
                                        "使用S/C 模式时,需要不断建立连接,理论上没有NET SEND模式快."& @CRLF & _
                                        "使用NET SEND 模式时,需要不断调用外部程序,理论上没有S/C模式快."& @CRLF & _                                        
                                        "要获得最新版本,请联系thesnow:"& @CRLF & @CRLF & _
                                        "QQ:133333542"& @CRLF & _
                                        "MAIL:Rundll@126.com")
GUICtrlSetState(-1, $GUI_DISABLE)
GUISetState(@SW_SHOW)
#EndRegion GUI


While 1
        Switch GUIGetMsg()
                Case $GUI_EVENT_CLOSE
                        Exit
                Case $sends
                        Sends()
                Case $add
;                        _GUICtrlListBox_SetCurSel ($MessageList, 3)
                        $Msg = _GUICtrlListBox_GetSelItemsText ( $MessageList )
                        MsgBox(16, "ttt", $Msg[0])
                        If (Not IsArray($Msg)) Then
                                MsgBox(16, "我晕!~~~", "你没有选择列表项目,你还添加什么?晕!~~~~")
                        Else
                                For $i = 1 To $Msg[0]
                                        GUICtrlSetData($commands02,$Msg[1])
                                Next
                        EndIf
        EndSwitch
WEnd


Func Sends()
if BitAND(GUICtrlRead($radio1), $GUI_CHECKED) = $GUI_CHECKED Then
        if BitAND(GUICtrlRead($radio3), $GUI_CHECKED) = $GUI_CHECKED Then
                _RunDOS("net send " & GUICtrlRead($Input1) & ' "' & GUICtrlRead($commands02) & '"')
        Else
                $ip=@IPAddress1
                $ip=StringLeft($ip,StringInStr($ip,".",0,-1))
                for $i = 1 to 255
                if Ping($ip & $i,50) = 0 then 
                        ToolTip("无法连接到:" & $ip & $i,0,0)
                        ContinueLoop
                EndIf
                _RunDOS("net send " & $ip & $i & ' "' & GUICtrlRead($commands02) & '"')
                ToolTip("发送消息到:" & $ip & $i,0,0)
                Next
                ToolTip("")
        EndIf
Else
        if BitAND(GUICtrlRead($radio3), $GUI_CHECKED) = $GUI_CHECKED Then
                $socket = UDPOpen(GUICtrlRead($Input1), 30000)
                If @error <> 0 Then Exit
                $myMsg=UnicodeHex(@HOUR & ":" & @MIN & ":" & @SEC & ":" & @CRLF & GUICtrlRead($commands02))
                $status = UDPSend($socket, $myMsg)
                GUICtrlSetData($commands02, "")
                If $status = 0 then 
                        MsgBox(32, "错误", "发送消息错误.错误代号为: " & @error)
                EndIf
                UDPCloseSocket($socket)
        Else
                $ip=@IPAddress1
                $ip=StringLeft($ip,StringInStr($ip,".",0,-1))
                for $i = 1 to 255
                if Ping($ip & $i,50) = 0 then 
                        ToolTip("无法连接到:" & $ip & $i,0,0)
                        ContinueLoop
                EndIf
                        $socket = UDPOpen($ip & $i, 30000)
                        If @error <> 0 Then Exit
                        $myMsg=UnicodeHex(@HOUR & ":" & @MIN & ":" & @SEC & ":" & @CRLF & GUICtrlRead($commands02))
                        $status = UDPSend($socket, $myMsg)
                        GUICtrlSetData($commands02, "")
                        If $status = 0 then 
                                MsgBox(32, "错误", "发送消息错误.错误代号为: " & @error)
                        EndIf
                        UDPCloseSocket($socket)                        
                ToolTip("发送消息到:" & $ip & $i,0,0)
                Next
                ToolTip("")
        EndIf        
EndIf
EndFunc


Func OnAutoItExit()
    UDPCloseSocket($socket)
    UDPShutdown()
EndFunc

Func UnicodeHex($string)
        Local $char
        Local $code
        Local $all=""
                For $i = 1 to StringLen($string)
                        $char = StringMid($string, $i, 1)
                        $code = Hex(Ascw($char),4)
                        $code =StringRight($code,2) & StringLeft($code,2) 
                        $all=$all & " " & $code
                Next
        Return $all
EndFunc
Func _RunDOS($sCommand)
        Return RunWait(@ComSpec & " /C " & $sCommand, "", @SW_HIDE)
EndFunc   ;==>_RunDOS



用MsgBox(16, "ttt", $Msg[0]) 读取到的数据永远是0,但用_GUICtrlListBox_SetCurSel ($MessageList, 3)设置选择项目又很正常的,不知是什么原因,请高手指教了!!!
发表于 2009-1-27 10:13:35 | 显示全部楼层
$MessageList = GUICtrlCreateList("", 16, 272, 497, 85,BitOR($LBS_STANDARD, $LBS_EXTENDEDSEL))
 楼主| 发表于 2009-1-28 20:54:00 | 显示全部楼层
还是不行,用以下代码:
GUICtrlCreateList("", 16, 272, 497, 85,BitOR($LBS_EXTENDEDSEL,$ES_WANTRETURN,$WS_VSCROLL,$LBS_NOTIFY))

有时正常有时不正常,但读取两三次后就出错,自动退出,不知道为什么,真郁闷,编译版为:3.2.13.7
发表于 2009-1-30 12:46:55 | 显示全部楼层
不是在2楼跟你说了吗?一定要完整的代码你才知道怎么改?
UDPStartup()
HotKeySet("{F7}","sends")
#include <GUIConstants.au3>
#Include <GuiListBox.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
;==============================================
#NoTrayIcon
$g_szVersion = "TR Server 1.0"
If WinExists($g_szVersion) Then Exit ; 此脚本已经运行了
AutoItWinSetTitle($g_szVersion)        
;----------------------------------------------

$socket = UDPOpen("@IPAddress1", 30000)
If @error <> 0 Then Exit
Dim $Msg

#Region GUI
$MAINGUI = GUICreate("TR-NET SEND 服务器端 V1.0", 641, 481, 223, 141)
$Group1 = GUICtrlCreateGroup("输入命令:", 8, 380, 617, 89)
$sends = GUICtrlCreateButton("发送(F7)", 560, 400, 57, 57)
$commands02 = GUICtrlCreateEdit("", 16, 400, 537, 57, BitOR($ES_AUTOVSCROLL,$ES_AUTOHSCROLL,$ES_WANTRETURN,$WS_VSCROLL))
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Group2 = GUICtrlCreateGroup("消息列表", 8, 256, 513, 113)
$MessageList = GUICtrlCreateList("", 16, 272, 497, 85,BitOR($LBS_STANDARD, $LBS_EXTENDEDSEL))
GUISetState(@SW_SHOW)
;--------------------
$file = FileOpen("Message.txt", 0)
While 1
    $line = FileReadLine($file)
    If @error = -1 Then ExitLoop
        _GUICtrlListBox_AddString ( $MessageList, $line )
Wend
;--------------------

GUICtrlCreateGroup("", -99, -99, 1, 1)
$add        = GUICtrlCreateButton("添加",528,330,97,35)
$Group3 = GUICtrlCreateGroup("发送方式:", 528, 256, 97, 65)
$Radio1 = GUICtrlCreateRadio("NET SEND", 536, 280, 81, 17)
$Radio2 = GUICtrlCreateRadio("S/C 模式", 536, 300, 65, 17)
GUICtrlSetState(-1, $GUI_CHECKED)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Group4 = GUICtrlCreateGroup("发送范围:", 8, 160, 617, 89)
$Radio3 = GUICtrlCreateRadio("单一 IP:", 24, 184, 89, 17)
GUICtrlSetState(-1, $GUI_CHECKED)
$Radio4 = GUICtrlCreateRadio("消息群发:", 24, 216, 89, 17)
$Input1 = GUICtrlCreateInput(@IPAddress1, 120, 184, 105, 21)
$Input2 = GUICtrlCreateInput("", 120, 216, 105, 21)
GUICtrlSetState(-1,$GUI_DISABLE)
$Input3 = GUICtrlCreateInput("", 249, 216, 103, 21)
GUICtrlSetState(-1,$GUI_DISABLE)
;---------------------
$ip=@IPAddress1
GUICtrlSetData($Input2,StringLeft($ip,StringInStr($ip,".",0,-1)) & "1")
GUICtrlSetData($Input3,StringLeft($ip,StringInStr($ip,".",0,-1)) & "255")
;---------------------

$Label1 = GUICtrlCreateLabel("到", 232, 224, 16, 17)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$about = GUICtrlCreateEdit("", 8, 8, 617, 145, BitOR($ES_AUTOVSCROLL,$ES_AUTOHSCROLL,$ES_WANTRETURN,$WS_VSCROLL))
GUICtrlSetData(-1, "说明:" & @CRLF & "使用 NET SEND 方式发送无需客户端,只需在主机和分机上面打开Message(消息)服务.缺点是只能发送一行消息"& @CRLF & _ 
                                        "客户端运行一次即可实现自启动,无需再添加注册表"& @CRLF & _
                                        "可以定义程序目录下面的Message.txt中的内容来实现预定义文本."& @CRLF & _
                                        "使用S/C 模式时,需要不断建立连接,理论上没有NET SEND模式快."& @CRLF & _
                                        "使用NET SEND 模式时,需要不断调用外部程序,理论上没有S/C模式快."& @CRLF & _                                        
                                        "要获得最新版本,请联系thesnow:"& @CRLF & @CRLF & _
                                        "QQ:133333542"& @CRLF & _
                                        "MAIL:Rundll@126.com")
GUICtrlSetState(-1, $GUI_DISABLE)
GUISetState(@SW_SHOW)
#EndRegion GUI


While 1
        Switch GUIGetMsg()
                Case $GUI_EVENT_CLOSE
                        Exit
                Case $sends
                        Sends()
                Case $add
;                        _GUICtrlListBox_SetCurSel ($MessageList, 3)
                        $Msg = _GUICtrlListBox_GetSelItemsText ( $MessageList )
                        MsgBox(16, "ttt", $Msg[0])
                        If (Not IsArray($Msg)) Then
                                MsgBox(16, "我晕!~~~", "你没有选择列表项目,你还添加什么?晕!~~~~")
                        Else
                                For $i = 1 To $Msg[0]
                                        GUICtrlSetData($commands02,$Msg[1])
                                Next
                        EndIf
        EndSwitch
WEnd


Func Sends()
if BitAND(GUICtrlRead($radio1), $GUI_CHECKED) = $GUI_CHECKED Then
        if BitAND(GUICtrlRead($radio3), $GUI_CHECKED) = $GUI_CHECKED Then
                _RunDOS("net send " & GUICtrlRead($Input1) & ' "' & GUICtrlRead($commands02) & '"')
        Else
                $ip=@IPAddress1
                $ip=StringLeft($ip,StringInStr($ip,".",0,-1))
                for $i = 1 to 255
                if Ping($ip & $i,50) = 0 then 
                        ToolTip("无法连接到:" & $ip & $i,0,0)
                        ContinueLoop
                EndIf
                _RunDOS("net send " & $ip & $i & ' "' & GUICtrlRead($commands02) & '"')
                ToolTip("发送消息到:" & $ip & $i,0,0)
                Next
                ToolTip("")
        EndIf
Else
        if BitAND(GUICtrlRead($radio3), $GUI_CHECKED) = $GUI_CHECKED Then
                $socket = UDPOpen(GUICtrlRead($Input1), 30000)
                If @error <> 0 Then Exit
                $myMsg=UnicodeHex(@HOUR & ":" & @MIN & ":" & @SEC & ":" & @CRLF & GUICtrlRead($commands02))
                $status = UDPSend($socket, $myMsg)
                GUICtrlSetData($commands02, "")
                If $status = 0 then 
                        MsgBox(32, "错误", "发送消息错误.错误代号为: " & @error)
                EndIf
                UDPCloseSocket($socket)
        Else
                $ip=@IPAddress1
                $ip=StringLeft($ip,StringInStr($ip,".",0,-1))
                for $i = 1 to 255
                if Ping($ip & $i,50) = 0 then 
                        ToolTip("无法连接到:" & $ip & $i,0,0)
                        ContinueLoop
                EndIf
                        $socket = UDPOpen($ip & $i, 30000)
                        If @error <> 0 Then Exit
                        $myMsg=UnicodeHex(@HOUR & ":" & @MIN & ":" & @SEC & ":" & @CRLF & GUICtrlRead($commands02))
                        $status = UDPSend($socket, $myMsg)
                        GUICtrlSetData($commands02, "")
                        If $status = 0 then 
                                MsgBox(32, "错误", "发送消息错误.错误代号为: " & @error)
                        EndIf
                        UDPCloseSocket($socket)                        
                ToolTip("发送消息到:" & $ip & $i,0,0)
                Next
                ToolTip("")
        EndIf        
EndIf
EndFunc


Func OnAutoItExit()
    UDPCloseSocket($socket)
    UDPShutdown()
EndFunc

Func UnicodeHex($string)
        Local $char
        Local $code
        Local $all=""
                For $i = 1 to StringLen($string)
                        $char = StringMid($string, $i, 1)
                        $code = Hex(Ascw($char),4)
                        $code =StringRight($code,2) & StringLeft($code,2) 
                        $all=$all & " " & $code
                Next
        Return $all
EndFunc
Func _RunDOS($sCommand)
        Return RunWait(@ComSpec & " /C " & $sCommand, "", @SW_HIDE)
EndFunc   ;==>_RunDOS
 楼主| 发表于 2009-1-30 20:29:34 | 显示全部楼层
老大,你有没有测试过呢,我怎么还是不行啊。
发表于 2009-1-30 22:54:34 | 显示全部楼层
有问题?出错在第几行?
 楼主| 发表于 2009-1-31 15:47:03 | 显示全部楼层
编译没有问题,运行也没有问题,但把list中的数据添加到$commands02中时,有时正确 ,有时不正确,反正一般情况下只要添加两三次就会因为出错而自动退出程序,没有任何提示的,
发表于 2009-1-31 15:58:43 | 显示全部楼层
4#的代码测试过,除了死循环外其它一切正常
您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2024-9-23 07:30 , Processed in 0.076587 second(s), 22 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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