标题:下面模块中使用异步拨号,LIST显示如何何改为状态栏显示拨号过程,请高手指点
只看楼主
rogersgb
Rank: 1
等 级:新手上路
帖 子:73
专家分:0
注 册:2016-2-3
结帖率:47.37%
已结贴  问题点数:20 回复次数:2 
下面模块中使用异步拨号,LIST显示如何何改为状态栏显示拨号过程,请高手指点
Option Explicit

Public hRasConn As Long '定义一个指向RAS调用的全局句柄
Public Const APINULL = 0&
Public Const UNLEN = 256
Public Const DNLEN = 15
Public Const PWLEN = 256
Public Const RAS95_MaxPhoneNumber = 128
Public Const RAS95_MaxEntryName = 256
Private Const RAS_MaxDeviceType = 16
Private Const RAS95_MaxDeviceName = 128
Public Const RAS95_MaxCallbackNumber = RAS95_MaxPhoneNumber
Public Type RASCONN95
    dwSize As Long
    hRasConn As Long
    szEntryName(RAS95_MaxEntryName) As Byte
    szDeviceType(RAS_MaxDeviceType) As Byte
    szDeviceName(RAS95_MaxDeviceName) As Byte
End Type
Public Type RASENTRYNAME95
    dwSize As Long
    szEntryName(RAS95_MaxEntryName) As Byte
End Type
Public Type RASDIALPARAMS95
    dwSize As Long
    szEntryName(RAS95_MaxEntryName) As Byte
    szPhoneNumber(RAS95_MaxPhoneNumber) As Byte
    szCallbackNumber(RAS95_MaxCallbackNumber) As Byte
    szUserName(UNLEN) As Byte
    szPassword(PWLEN) As Byte
    szDomain(DNLEN) As Byte
End Type
'**********************************
'* RAS调用错误代号 *
'**********************************
Public Const NOT_SUPPORTED = 120&
Public Const RASBASEERROR = 600&
Public Const SUCCESS = 0&
Public Const ERROR_PORT_ALREADY_OPEN = (RASBASEERROR + 2)
Public Const ERROR_UNKNOWN = (RASBASEERROR + 35)
Public Const ERROR_REQUEST_TIMEOUT = (RASBASEERROR + 38)
Public Const ERROR_PASSWD_EXPIRED = (RASBASEERROR + 48)
Public Const ERROR_NO_DIALIN_PERMISSION = (RASBASEERROR + 49)
Public Const ERROR_SERVER_NOT_RESPONDING = (RASBASEERROR + 50)
Public Const ERROR_UNRECOGNIZED_RESPONSE = (RASBASEERROR + 52)
Public Const ERROR_NO_RESPONSES = (RASBASEERROR + 60)
Public Const ERROR_DEVICE_NOT_READY = (RASBASEERROR + 66)
Public Const ERROR_LINE_BUSY = (RASBASEERROR + 76)
Public Const ERROR_NO_ANSWER = (RASBASEERROR + 78)
Public Const ERROR_NO_CARRIER = (RASBASEERROR + 79)
Public Const ERROR_NO_DIALTONE = (RASBASEERROR + 80)
Public Const ERROR_AUTHENTICATION_FAILURE = (RASBASEERROR + 91)
Public Const ERROR_PPP_TIMEOUT = (RASBASEERROR + 118)
'**********************************
'* RAS连接状态声明 *
'**********************************
Enum RasConnState
    RASCS_OpenPort = 0
    RASCS_PortOpened             '1
    RASCS_ConnectDevice          '2
    RASCS_DeviceConnected        '3
    RASCS_AllDevicesConnected    '4
    RASCS_Authenticate           '5
    RASCS_AuthNotify             '6
    RASCS_AuthRetry
    RASCS_AuthCallback
    RASCS_AuthChangePassword
    RASCS_AuthProject
    RASCS_AuthLinkSpeed
    RASCS_AuthAck
    RASCS_ReAuthenticate
    RASCS_Authenticated
    RASCS_PrepareForCallback
    RASCS_WaitForModemReset
    RASCS_WaitForCallback
    RASCS_Projected
    RASCS_StartAuthentication  '19
    RASCS_CallbackComplete
    RASCS_LogonNetwork         '21
    RASCS_Interactive = &H1000
    RASCS_RetryAuthentication
    RASCS_CallbackSetByCaller
    RASCS_PasswordExpired
    RASCS_Connected = &H2000
    RASCS_Disconnected
End Enum
'**********************************
'* RAS API 声明 *
'**********************************
Public Declare Function lstrcpy Lib "kernel32" Alias "lstrcpyA" (lpString1 As Any, ByVal lpString2 As String) As Long
Public Declare Function RasDial Lib "rasapi32.dll" Alias "RasDialA" (lpRasDialExtensions As Any, ByVal lpszPhonebook As String, lprasdialparams As Any, ByVal dwNotifierType As Long, ByVal lpvNotifier As Long, lphRasConn As Long) As Long
Public Declare Function RasEnumConnections Lib "rasapi32.dll" Alias "RasEnumConnectionsA" (lprasconn As Any, lpcb As Long, lpcConnections As Long) As Long
Public Declare Function RasEnumEntries Lib "rasapi32.dll" Alias "RasEnumEntriesA" (ByVal reserved As String, ByVal lpszPhonebook As String, lprasentryname As Any, lpcb As Long, lpcEntries As Long) As Long
Public Declare Function RasHangUp Lib "rasapi32.dll" Alias "RasHangUpA" (ByVal hRasConn As Long) As Long

'Sleep
Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Public Function AddConnection(strNewEntryName As String, strNewPhoneNumber As String, strNewCallbackNumber As String, strNewUsername As String, strNewPassword As String, strNewDomain As String) As Integer

Dim lngRetCode As Long
Dim lngRetLstrcpy As Long
Dim lngRetHangUp As Long
Dim lprasdialparams As RASDIALPARAMS95

lprasdialparams.dwSize = 1052
lngRetLstrcpy = lstrcpy(lprasdialparams.szEntryName(0), strNewEntryName)
lngRetLstrcpy = lstrcpy(lprasdialparams.szPhoneNumber(0), strNewPhoneNumber)
lngRetLstrcpy = lstrcpy(lprasdialparams.szCallbackNumber(0), strNewCallbackNumber)
lngRetLstrcpy = lstrcpy(lprasdialparams.szUserName(0), strNewUsername)
lngRetLstrcpy = lstrcpy(lprasdialparams.szPassword(0), strNewPassword)
lngRetLstrcpy = lstrcpy(lprasdialparams.szDomain(0), strNewDomain)
Screen.MousePointer = vbHourglass '改变鼠标样式
hRasConn = 0
lngRetCode = 0
 DoEvents
'若使用以下CallBack function的方式,则RasDial()不等连线成功或失败便结束。
           lngRetCode = RasDial(ByVal APINULL, vbNullString, lprasdialparams, 0, AddressOf RasDialFunc, hRasConn) '异步通信
'若第二、三个叁数都是0则,RasDial会等连线成功或失败後才执行下一行指令
          'lngRetCode = RasDial(ByVal APINULL, vbNullString, lprasdialparams, APINULL, ByVal APINULL, hRasConn)
 DoEvents
 Screen.MousePointer = vbDefault '改变鼠标样式
If lngRetCode Then
lngRetHangUp = RasHangUp(hRasConn)
End If
AddConnection = lngRetCode
End Function
Public Function GetConnections() As Integer
Dim lngRetCode As Long
Dim lpcb As Long
Dim lpcConnections As Long
Dim intArraySize As Integer

ReDim lprasconn95(intArraySize) As RASCONN95
lprasconn95(0).dwSize = 412
lpcb = 256 * lprasconn95(0).dwSize
lngRetCode = RasEnumConnections(lprasconn95(0), lpcb, lpcConnections)

' If lngRetCode = 0 Then
' End If
GetConnections = lpcConnections
End Function
Public Sub RemoveConnection()
    Dim s As Long, L As Long, ln As Long, a$, RasConn As Long, Ret As Long

    ReDim R(255) As RASCONN95

    R(0).dwSize = 412
    s = 256 * R(0).dwSize
    L = RasEnumConnections(R(0), s, ln)
    For L = 0 To ln - 1
        a$ = StrConv(R(L).szEntryName(), vbUnicode)
        a$ = left$(a$, InStr(a$, Chr$(0)) - 1)
        RasConn = R(L).hRasConn
        '这里将挂断连接
        Ret = RasHangUp(ByVal RasConn)
        Sleep (2000)
    Next
End Sub


Public Sub RasDialFunc(ByVal unMsg As Long, ByVal ConnState As Long, ByVal dwError As Long)
Dim strmsg As String
Select Case ConnState

    Case RASCS_OpenPort
        strmsg = "正在打开端口……"
    Case RASCS_PortOpened
        strmsg = "端口已打开。"
    Case RASCS_ConnectDevice
        strmsg = "正在连接设备"
    Case RASCS_DeviceConnected
        strmsg = "设备已连接。"
    'Case RASCS_AllDevicesConnected
    '    strmsg= "所有设备均已连接。"
    Case RASCS_Authenticate
        strmsg = "验证用户名及密码……"
    Case RASCS_AuthNotify
        strmsg = "RASCS_AuthNotify"
    Case RASCS_AuthRetry
        strmsg = "RASCS_AuthRetry"
    Case RASCS_AuthCallback
        strmsg = "RASCS_AuthCallback"
    Case RASCS_AuthChangePassword
        strmsg = "RASCS_AuthChangePassword"
    Case RASCS_AuthProject
        strmsg = "RASCS_AuthProject"
    Case RASCS_AuthLinkSpeed
        strmsg = "RASCS_AuthLinkSpeed"
    Case RASCS_AuthAck
        strmsg = "RASCS_AuthAck"
    Case RASCS_ReAuthenticate
        strmsg = "RASCS_ReAuthenticate"
    Case RASCS_Authenticated
        strmsg = "RASCS_Authenticated"
    Case RASCS_PrepareForCallback
        strmsg = "RASCS_PrepareForCallback"
    Case RASCS_WaitForModemReset
        strmsg = "RASCS_WaitForModemReset"
    Case RASCS_WaitForCallback
        strmsg = "RASCS_WaitForCallback"
    Case RASCS_Projected
        strmsg = "RASCS_Projected"
    Case RASCS_StartAuthentication
        strmsg = "RASCS_StartAuthentication"
    Case RASCS_CallbackComplete
        strmsg = "RASCS_CallbackComplete"
    Case RASCS_LogonNetwork
        strmsg = "RASCS_LogonNetwork"
    Case RASCS_Interactive
        strmsg = "RASCS_Interactive"
    Case RASCS_RetryAuthentication
        strmsg = "RASCS_RetryAuthentication"
    Case RASCS_CallbackSetByCaller
        strmsg = "RASCS_CallbackSetByCaller"
    Case RASCS_PasswordExpired
        strmsg = "RASCS_PasswordExpired"
    Case RASCS_Connected
        strmsg = "连接成功!"
= False
= True
Form1.Timer1.Enabled = True
If Form1.Option1.Value = True Then
Shell "C:\Program Files\Internet Explorer\iexplore.exe http://100.0.0.1:8001/ctais2/wssb/login.jsp?number=" & Form1.Text3.Text & "&password=" & Form1.Text4.Text, vbMaximizedFocus
Else
Shell "C:\Program Files\Internet Explorer\iexplore.exe http://100.0.0.7:8000/ctais2/wssb/login.jsp?number=" & Form1.Text3.Text & "&password=" & Form1.Text4.Text, vbMaximizedFocus
End If
    Case RASCS_Disconnected
        strmsg = "连接已断开!"
        
End Select

Select Case dwError
     
    Case ERROR_PORT_ALREADY_OPEN
        strmsg = "错误,端口已经打开!"
    Case ERROR_UNKNOWN
        strmsg = "未知的错误!"
    Case ERROR_REQUEST_TIMEOUT
        strmsg = "错误,请求超时!"
    Case ERROR_PASSWD_EXPIRED
        strmsg = "错误,您的密码错误!"
    Case ERROR_NO_DIALIN_PERMISSION
        strmsg = "错误,没有拨号音!"
    Case ERROR_SERVER_NOT_RESPONDING
        strmsg = "错误,拨入的远程计算机没有响应!"
    Case ERROR_UNRECOGNIZED_RESPONSE
        strmsg = "错误,未知的响应!"
    Case ERROR_NO_RESPONSES
        strmsg = "错误,没有响应!"
    Case ERROR_DEVICE_NOT_READY
        strmsg = "错误,设备没有准备好!"
    Case ERROR_LINE_BUSY
        strmsg = "错误,占线!"
    Case ERROR_NO_ANSWER
        strmsg = "错误,服务器无应答!"
    Case ERROR_NO_CARRIER
        strmsg = "错误,没有载波信号!"
    Case ERROR_NO_DIALTONE
        strmsg = "错误,没有拨号音!"
    Case ERROR_AUTHENTICATION_FAILURE
        strmsg = "用户名密码出错!"
    Case ERROR_PPP_TIMEOUT
        strmsg = "PPP接入超时。"
    Case 633
        strmsg = "错误,网络设备不存在或没打开电源!"
    Case 623
        strmsg = "错误,请建立新连接!"
    Case Else
        If dwError <> 0 Then strmsg = "拨号失败,重拨!"
        
End Select
Form1.List1.AddItem strmsg
Form1.List1.ListIndex = Form1.List1.NewIndex
End Sub
搜索更多相关主题的帖子: 状态栏 如何 
2016-02-29 12:36
wmf2014
Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19
等 级:贵宾
威 望:216
帖 子:2039
专家分:11273
注 册:2014-12-6
得分:10 
看你发了很多次了,为什么不发整个工程文件?这样大神们比较方便帮你弄得,估计不是太复杂。

能编个毛线衣吗?
2016-02-29 13:06
风吹过b
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:贵宾
威 望:364
帖 子:4912
专家分:29900
注 册:2008-10-15
得分:10 
因为我也用了这个模块,用 了后,发现状态提示混乱,也没办法解决中,所以也郁闷中。
无能为力啊。


授人于鱼,不如授人于渔
早已停用QQ了
2016-02-29 22:04



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-462023-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.120533 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved