zhwu530 发表于 2012-3-23 10:52:09

还是内嵌IE 问题,程序卡死。

最近需要。在论坛翻了一下但运行下面的代码 程序会卡死。请懂的帮忙解决下。#include "GUIConstantsEx.au3"
#include <GuiStatusBar.au3>
#include <IE.au3>

Dim $Text, $Text2 = ""
Local $aParts =
Global $DEFAULTINPUTDATA_1 = "如 www.baidu.com 或baidu.com"
Global $MARk_1 = 0, $NONEAACTIVECOLOR = 0xC0C0C0
$GUIMain = GUICreate("Test", 588, 449)
GUICtrlCreateGroup("", 5, 3, 577, 105)
GUICtrlCreateLabel("网址 Http://", 18, 26, 80, 17)
$IEAdd = GUICtrlCreateInput($DEFAULTINPUTDATA_1, 90, 20, 401, 21)
$hStatus = _GUICtrlStatusBar_Create($GUIMain)
_GUICtrlStatusBar_SetParts($hStatus, $aParts)
GUICtrlSetColor(-1, 0xC0C0C0)
$OpenIE = GUICtrlCreateButton("打开", 500, 18, 70, 25)
GUICtrlCreateLabel("ADSL账号:", 18, 54, 68, 17)
$Adslaccount = GUICtrlCreateInput("", 90, 48, 141, 21)
GUICtrlCreateLabel("密码:", 240, 54, 40, 17)
$Adslpassword = GUICtrlCreateInput("", 280, 48, 121, 21, 0x0020)
$Adsl = GUICtrlCreateLabel("测试...", 410, 52, 35, 25)
GUICtrlSetFont(-1, 8, 400, 4, "MS Sans Serif")
GUICtrlSetColor(-1, 0x0000FF)
GUICtrlSetCursor(-1, 0)
GUICtrlCreateLabel("每间隔", 18, 83, 40, 17)
$TimeSec = GUICtrlCreateInput("10", 55, 79, 30, 18)
GUICtrlCreateLabel("秒, 自动刷新", 88, 83, 75, 17)
$Checkbox1 = GUICtrlCreateCheckbox("每次清除Cookies,", 168, 81, 120, 17)
GUICtrlCreateLabel("刷", 292, 83, 16, 17)
$TimeNum = GUICtrlCreateInput("", 305, 79, 49, 18)
GUICtrlCreateLabel("次停止", 355, 83, 40, 17)
$Began = GUICtrlCreateButton("开始", 450, 55, 51, 45)
$stop = GUICtrlCreateButton("停止", 516, 55, 51, 45)
GUICtrlSetState($stop, $GUI_DISABLE)
GUISetState()
$oIE = _IECreateEmbedded()
GUICtrlCreateObj($oIE, 5, 110, 577, 318)
$EventObject = ObjEvent($oIE, "IEEvent_", "DWebBrowserEvents")
If @error Then Exit MsgBox(0, "错误!", "不可使用COM接口 'DWebBrowserEvents'. 错误代码: " & Hex(@error, 8))


While 1
        $msg = GUIGetMsg()
        _CheckInput($GUIMain, $IEAdd, "如 www.baidu.com 或baidu.com", $DEFAULTINPUTDATA_1, $MARk_1)
        If GUICtrlRead($IEAdd) = "" Or GUICtrlRead($IEAdd) = $DEFAULTINPUTDATA_1 Then
                If BitAND(GUICtrlGetState($Began), $gui_enable) Then
                        GUICtrlSetState($Began, $GUI_DISABLE)
                EndIf
        Else
                If BitAND(GUICtrlGetState($Began), $GUI_DISABLE) Then
                        GUICtrlSetState($Began, $gui_enable)
                EndIf
        EndIf
        If $msg = $GUI_EVENT_CLOSE Then
                $EventObject.Stop ; 不再接收事件
                $EventObject = 0 ; 关闭Event Object
                $oIE = 0 ; 清除内存
                GUIDelete()
                Exit
        EndIf
        If $msg = $GUI_EVENT_MINIMIZE Then GUISetState(@SW_HIDE)
        If $msg = $Began Then
                GUICtrlSetState($Began, $GUI_DISABLE)
                GUICtrlSetState($stop, $gui_enable)
                If GUICtrlRead($TimeSec) < 5 Then
                        $TimeS = 5
                Else
                        $TimeS = GUICtrlRead($TimeSec)
                EndIf
                AdlibReg($TimeS, GUICtrlRead($TimeNum))
        EndIf
WEnd
Func IEEvent_StatusTextChange($Text)
        If $Text <> '' And StringLeft($Text, 4) = "http" Then $Text2 = $Text
        _GUICtrlStatusBar_SetText($hStatus, $Text)
EndFunc   ;==>IEEvent_StatusTextChange
Func AdlibReg($Time, $TimeMember)
        Local $t, $ti, $i = 0, $decTime = 1
        Local $begin = TimerInit()
        While 1
                If $msg = $stop Then ExitLoop
               
;                 If $i = $TimeMember Or $TimeMember <> "" Then
;                         GUICtrlSetState($stop, $GUI_DISABLE)
;                         GUICtrlSetState($Began, $gui_enable)
;                         _GUICtrlStatusBar_SetText($hStatus, "已停止", 2)
;                         ExitLoop
;                 Else               
                $oIE.Navigate("http://" & GUICtrlRead($IEAdd))
                Sleep(1000)
                GUISwitch($GUIMain)
      _GUICtrlStatusBar_SetText($hStatus, _GetInternetIP(), 1)               
                $ti = Int(TimerDiff($begin) / 1000)
                MsgBox(0,$begin,$ti)
                If $ti >= $decTime Then
                        $decTime += 1
                        _GUICtrlStatusBar_SetText($hStatus, $Time - $ti, 2)
                        Sleep($Time&"000")
                EndIf
                If GUICtrlRead($Adslaccount) And GUICtrlRead($Adslaccount) <> "" Then
                        RunWait(@ComSpec & " /c rasdial 宽带连接 /disconnect", "", 0)
                        RunWait(@ComSpec & " /c rasdial 宽带连接 " & GUICtrlRead($Adslaccount) & " " & GUICtrlRead($Adslpassword), "", @SW_HIDE)
                EndIf
                $i = $i + 1
                _GUICtrlStatusBar_SetText($hStatus, $i, 3)       
        WEnd
EndFunc   ;==>AdlibReg
Func _CheckInput($hWnd, $ID, $InputDefText, ByRef $DefaultInputData, ByRef $Mark)
        If $Mark = 0 And _IsFocused($hWnd, $ID) And $DefaultInputData = $InputDefText Then
                $Mark = 1
                GUICtrlSetData($ID, "")
                GUICtrlSetColor($ID, 0x000000)
                $DefaultInputData = ""
        ElseIf $Mark = 1 And Not _IsFocused($hWnd, $ID) And $DefaultInputData = "" And GUICtrlRead($ID) = "" Then
                $Mark = 0
                $DefaultInputData = $InputDefText
                GUICtrlSetData($ID, $DefaultInputData)
                GUICtrlSetColor($ID, $NONEAACTIVECOLOR)
        EndIf
EndFunc   ;==>_CheckInput
Func _IsFocused($hWnd, $nCID)
        Return ControlGetHandle($hWnd, '', $nCID) = ControlGetHandle($hWnd, '', ControlGetFocus($hWnd))
EndFunc   ;==>_IsFocused
Func _GetInternetIP()
        Local $ip
        $ip = InetRead("http://www.aamailsoft.com/getip.php", 1)
        $ip = BinaryToString($ip)
        If StringStripWS($ip, 8) <> "" Then
                Return $ip
        Else
                Return "0.0.0.0"
        EndIf
EndFunc   ;==>_GetInternetIP

lxzan 发表于 2012-3-23 12:01:30

这代码是用来做什么的?

zcx880517 发表于 2012-3-23 12:02:43

回复 1# zhwu530


    点击开始后无法停止。

zhwu530 发表于 2012-3-23 15:12:09

本帖最后由 zhwu530 于 2012-3-23 21:20 编辑

这东西没技术含量大神们都不愿出手?

自己改了下 停止 那里还是弄不好。。。。。 !


要达到上图中描述的那样 搞了一天了还没解决。。。大神们帮帮 5 。。
我那些代码都是网上东拼西凑的,
要不哪位大神按图上的帮我弄个。。。。

user3000 发表于 2012-3-23 15:43:38

问题出现在 AdliReg 函数里, 它有个'死'循环!

zhwu530 发表于 2012-3-23 16:06:03

该怎么做才能解决这个问题呢
页: [1]
查看完整版本: 还是内嵌IE 问题,程序卡死。