auto 发表于 2012-2-26 10:51:07

请教这段VB语句如何转换成为AU3(内嵌ie代理)

请教这段VB语句如何转换成为AU3(内嵌ie代理)
按下面的语句,倒腾半天没有结果,请教各位高手在内嵌的ie窗口如何实现代理(不要影响IE的)
例如:http://wenku.baidu.com/view/5f6c2e4ee518964bcf847c94.html?from=related

设置程序中使用的WebBrowser控件的代理,不影响系统IE浏览器

简介:'在窗口中添加一个WebBrowser浏览器控件,添加两个文件框,改名为:txtIP、txtPort,分别为代理用品的IP及端口。一个按钮控件。代码如下: Option Explicit Private Type INTERNET_PROXY_INFO dwAccessType As Long ...
关键字:设置 程序 使用 WebBrowser 控件 代理 而不影响 系统 IE 浏览器
'在窗口中添加一个WebBrowser浏览器控件,添加两个文件框,改名为:txtIP、txtPort,分别为代理用品的IP及端口。一个按钮控件。代码如下:

Option Explicit

Private Type INTERNET_PROXY_INFO
    dwAccessType    As Long
    lpszProxy       As String
    lpszProxyBypass As String
End Type

Private Const INTERNET_OPTION_PROXY = 38
Private Const INTERNET_OPTION_SETTINGS_CHANGED = 39
Private Const INTERNET_OPEN_TYPE_DIRECT = 1
Private Const INTERNET_OPEN_TYPE_PROXY = 3

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 Sub SetProxy(aStrIP As String, aStrPort As String, aBolUseProxy As Boolean)
    Dim strProxy As String
    Dim inf As INTERNET_PROXY_INFO
   
    aStrIP = Trim(aStrIP)
    aStrPort = Trim(aStrPort)
    If (aStrIP + aStrPort = "") Or Not aBolUseProxy Then
      strProxy = ""
    Else
      strProxy = "http=" + aStrIP + ":" + aStrPort
    End If
   
    If Trim(strProxy) <> "" Then

      inf.dwAccessType = INTERNET_OPEN_TYPE_PROXY
      inf.lpszProxy = strProxy
      inf.lpszProxyBypass = ""

      Call InternetSetOption(0, INTERNET_OPTION_PROXY, inf, Len(inf))
      Call InternetSetOption(0, INTERNET_OPTION_SETTINGS_CHANGED, "", 0)
    Else
      inf.dwAccessType = INTERNET_OPEN_TYPE_DIRECT
      inf.lpszProxy = ""
      inf.lpszProxyBypass = ""
   
      Call InternetSetOption(0, INTERNET_OPTION_PROXY, inf, Len(inf))
      Call InternetSetOption(0, INTERNET_OPTION_SETTINGS_CHANGED, "", 0)
    End If
End Sub

Private Sub Command1_Click()
    SetProxy txtIP.Text, txtPort.Text, True
    WebBrowser1.Navigate "http://www.any5u.com"
End Sub

Private Sub Form_Load()
    WebBrowser1.Navigate "http://www.any5u.com"
End Sub

zldfsz 发表于 2012-2-26 22:58:59

不懂,帮顶下

redapple2008 发表于 2012-2-28 16:44:44

我也帮你顶一下了。我对vbs变au3没有兴趣

auto 发表于 2012-2-28 17:49:47

回复 3# redapple2008


上面应该是vb的语句

高手有没有兴趣把这段C#转一下
#region 改变代理
      
      private static extern bool InternetSetOption(IntPtr hInternet, int dwOption, IntPtr lpBuffer, int lpdwBufferLength);

      public void RefreshIESettings(string strProxy)
      {
            const int INTERNET_OPTION_PROXY = 38;
            const int INTERNET_OPEN_TYPE_PROXY = 3;
            Struct_INTERNET_PROXY_INFO struct_IPI;
            // Filling in structure
            struct_IPI.dwAccessType = INTERNET_OPEN_TYPE_PROXY;
            struct_IPI.proxy = Marshal.StringToHGlobalAnsi(strProxy);
            struct_IPI.proxyBypass = Marshal.StringToHGlobalAnsi("local");
            // Allocating memory
            IntPtr intptrStruct = Marshal.AllocCoTaskMem(Marshal.SizeOf(struct_IPI));
            // Converting structure to IntPtr
            Marshal.StructureToPtr(struct_IPI, intptrStruct, true);
            bool iReturn = InternetSetOption(IntPtr.Zero, INTERNET_OPTION_PROXY, intptrStruct, Marshal.SizeOf(struct_IPI));
      }
      #endregion

zxxputian4 发表于 2012-2-29 11:54:19

高手,谢谢共享
页: [1]
查看完整版本: 请教这段VB语句如何转换成为AU3(内嵌ie代理)