中国IT动力,最新最全的IT技术教程
最新100篇 | 推荐100篇 | 专题100篇 | 排行榜 | 搜索 | 在线API文档 | 网通镜像
首 页 | 程序开发 | 操作系统 | 软件应用 | 图形图象 | 网络应用 | 精文荟萃 | 教育认证 | 硬件维护 | 未整理篇 | 站长教程
ASP JS PHP工程 ASP.NET 网站建设 UML J2EESUN .NET VC VB VFP 网络维护 数据库 DB2 SQL2000 Oracle Mysql
服务器 Win2000 Office C DreamWeaver FireWorks Flash PhotoShop 上网宝典 CorelDraw 协议大全 网络安全 微软认证
硬件维护  CPU  主板  硬盘  内存  显卡  显示器  键盘鼠标  声卡音箱  打印机  机箱电源  BIOS  网卡  C#  Java  Delphi  vs.net2005
  当前位置:> 程序开发 > 编程语言 > Visual Basic > 网络
VB+API获取IE的"代理服务器"配制
作者:playyuer 时间:2001-11-03 10:47 出处:互联网 责编:chinaitpower
              摘要:VB+API获取IE的"代理服务器"配制

Option Explicit
Private Type INTERNET_PROXY_INFO
    dwAccessType    As Long
    lpszProxy       As Long
    lpszProxyBypass As Long
End Type
Private Const INTERNET_OPTION_PROXY = 38
Private Declare Function InternetSetOption Lib "wininet.dll" Alias "InternetSetOptionA" (ByVal hInternet As Long, ByVal dwOption As Long, ByRef lpBuffer As Any, ByVal dwBufferLength As Long) As Long
Private Declare Function InternetQueryOption Lib "wininet.dll" Alias "InternetQueryOptionA" (ByVal hInternet As Long, ByVal dwOption As Long, ByRef lpBuffer As Any, ByRef dwBufferLength As Long) As Long
Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (ByRef pDest As Any, ByRef pSource As Any, ByVal Length As Long)
Private Declare Function lstrcpy Lib "kernel32" Alias "lstrcpyA" (ByVal lpString1 As String, ByVal lpString2 As Long) As Long
Private Declare Function lstrlen Lib "kernel32" Alias "lstrlenA" (ByVal lpString As Any) As Long
Public Function GetProxyAddressAndPort(Optional ProxyType As String) As String
Dim ProxyInfo As INTERNET_PROXY_INFO
Dim arrBuffer() As Byte
Dim strAddress As String
Dim strBypass As String
ReDim arrBuffer(0 To 4095)
InternetQueryOption 0&, INTERNET_OPTION_PROXY, arrBuffer(0), UBound(arrBuffer) - LBound(arrBuffer) + 1
CopyMemory ProxyInfo, arrBuffer(0), LenB(ProxyInfo)
strAddress = VBA.Space(lstrlen(ProxyInfo.lpszProxy))
lstrcpy ByVal strAddress, ProxyInfo.lpszProxy
'不使用代理的地址 strBypass
strBypass = VBA.Space(lstrlen(ProxyInfo.lpszProxyBypass))
lstrcpy ByVal strBypass, ProxyInfo.lpszProxyBypass
'GetProxyAddressAndPort = VBA.Trim(VBA.Replace(strAddress, " ", ";")) ' & ";" & VBA.Replace(strBypass, " ", ";"))
GetProxyAddressAndPort = VBA.Trim(VBA.Replace(strAddress, " ", ";") & ";" & VBA.Replace(strBypass, " ", ";"))
Dim ProxyArray() As String
ProxyArray = Split(GetProxyAddressAndPort, ";")
Dim i As Integer
For i = LBound(ProxyArray) To UBound(ProxyArray)
    If ProxyArray(i) Like "*" & ProxyType & "=*" Then
       GetProxyAddressAndPort = VBA.Replace(ProxyArray(i), ProxyType & "=", "")
       Exit For
    End If
Next i
End Function

Private Sub Command1_Click()
MsgBox GetProxyAddressAndPort("http")
MsgBox GetProxyAddressAndPort("ftp")
MsgBox GetProxyAddressAndPort("gopher")
End Sub

'编程配置 IE 的 "代理服务器" 要用到 InternetSetOption
'一个例子下载:
'http://www.vbip.com/forum/files/webbrowser_proxy.zip

关闭本页
 
首页 | 投资与合作 | 服务条款 | 隐私政策 | 收藏本站 | 设为首页 | 新用户注册 | 免责声明 | 使用帮助
Copyright ©2005-2008 chinaitpower.com All rights reserved. www.chinaitpower.com 版权所有