#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <ComboConstants.au3>
#Region ### START Koda GUI section ### Form=F:\绿色软件\IE7\教程\proxy\form1.kxf
$Form1 = GUICreate("IE代理设置", 209, 139, 192, 124)
$Group1 = GUICtrlCreateGroup("", 8, 5, 193, 121)
$Label1 = GUICtrlCreateLabel("状态:", 24, 21, 40, 17)
$status = RegRead("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings", "ProxyEnable")
If $status = 0 Then
$Label2 = GUICtrlCreateLabel("代理已关闭", 62, 22, 120, 17)
Else
$Label2 = GUICtrlCreateLabel("代理已启用", 62, 22, 120, 17)
EndIf
$ip1 = RegRead("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings", "ProxyServer")
If $ip1 = '' Then
$Combo1 = GUICtrlCreateCombo('112.217.228.212:8080', 24, 45, 161, 21, BitOR($CBS_DROPDOWN, $CBS_AUTOHSCROLL))
GUICtrlSetTip($Combo1, "输入格式:IP:Port(如:112.217.228.212.8080)!")
Else
$Combo1 = GUICtrlCreateCombo('112.217.228.212:8080', 24, 45, 161, 21, BitOR($CBS_DROPDOWN, $CBS_AUTOHSCROLL))
GUICtrlSetData($Combo1, $ip1)
GUICtrlSetTip($Combo1, "输入格式:IP:Port(如:112.217.228.212.8080)!")
EndIf
GUICtrlSetState($Combo1, $GUI_EXPAND)
$Button1 = GUICtrlCreateButton("启用", 24, 85, 65, 25)
$Button2 = GUICtrlCreateButton("禁用", 117, 85, 65, 25)
$Label = GUICtrlCreateLabel("0", 230, 223, 36, 17)
GUICtrlCreateGroup("", -99, -99, 1, 1)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
Global $var
$z = 0
$var = IniReadSection(@ScriptDir & "\proxy.ini", "proxy")
If @error Then
Else
For $i = 1 To $var[0][0]
GUICtrlSetData($Combo1, $var[$i][1], 0)
GUICtrlSetData($Label, $z + 1)
$z += 1
Next
EndIf
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
Case $Button1
GUISetState(@SW_HIDE, $Form1)
$z = GUICtrlRead($Label)
$doit = GUICtrlRead($Combo1)
$ip = StringRegExpReplace($doit, ":.*", "")
$PORT = StringRegExpReplace($doit, ".*:", "")
If StringInStr($doit, ":") And StringIsDigit(StringReplace($ip, ".", "")) And StringReplace($ip, ".", "") > 0 And $PORT > 0 And StringInStr($ip, ".", 0, 3) And StringIsDigit($PORT) And Not StringInStr($ip, ".", 0, 4) Then
RegWrite("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings", "ProxyServer", "REG_SZ", $doit)
RegWrite("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings", "ProxyEnable", "REG_DWORD", 1)
$z += 1
;如何在这判断INI中已存在IP,则不在新行重复写入
IniWrite(@ScriptDir & "\proxy.ini", 'proxy', $z, $doit)
GUICtrlSetData($Label, $z + 1)
MsgBox(64, "IE代理设置", "代理启用", 2)
DllCall('WININET.DLL', 'long', 'InternetSetOption', 'int', 0, 'long', 39, 'str', 0, 'long', 0)
Exit
Else
GUISetState(@SW_HIDE, $Form1)
MsgBox(48, "IE代理设置", "输入错误,请重新输入!" & @CRLF & "输入格式:IP:Port(如:112.217.228.212.8080)!")
GUISetState(@SW_SHOW, $Form1)
EndIf
Case $Button2
GUISetState(@SW_HIDE, $Form1)
RegWrite("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings", "ProxyEnable", "REG_DWORD", 0)
MsgBox(64, "IE代理设置", "代理关闭", 2)
DllCall('WININET.DLL', 'long', 'InternetSetOption', 'int', 0, 'long', 39, 'str', 0, 'long', 0)
Exit
EndSwitch
WEnd