把代码直接贴出来吧,免得下载浪费时间
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
Opt("GUIOnEventMode", 1) ;GUI事件响应模式
HotKeySet("{ENTER}", "_translate")
HotKeySet("{F1} ", "_empty")
HotKeySet("{F3} ", "_change")
Global $TranValue, $flag
$flag = "en%7Czh-CN"
$Form = GUICreate("Google 英汉互译工具 V0.1 - 20091025", 420, 252)
$Edit1 = GUICtrlCreateEdit("", 8, 8, 404, 100, 0x0004)
GUICtrlSetData(-1, "")
$Label = GUICtrlCreateLabel("英译汉", 8, 116, 60, 20)
GUICtrlSetFont(-1, 15)
GUICtrlSetColor(-1, 0xff0000)
GUICtrlCreateLabel("鼠标左键或回车键确认查询;鼠标右键或F3键切换语言;F1清空", 76, 120, 340, 20)
$Edit2 = GUICtrlCreateEdit("", 8, 144, 404, 100, 0x0004)
GUICtrlSetData(-1, "")
GUISetState(@SW_SHOW)
GUISetOnEvent($GUI_EVENT_CLOSE, "Gui")
GUISetOnEvent($GUI_EVENT_PRIMARYDOWN, "Gui")
GUISetOnEvent($GUI_EVENT_SECONDARYDOWN, "Gui")
While 1
Sleep(100)
WEnd
Func Gui()
Switch @GUI_CtrlId
Case $GUI_EVENT_CLOSE
Exit
Case $GUI_EVENT_PRIMARYDOWN ;鼠标主要按钮按下,即左键按下
If GUICtrlRead($Edit1) <> "" Then _translate()
Case $GUI_EVENT_SECONDARYDOWN ;鼠标次要按钮按下,即右键按下
_change()
EndSwitch
EndFunc ;==>Gui
Func _translate()
$xmlhttp = ObjCreate("Msxml2.XMLHTTP");
$xmlhttp.open("GET", "http://ajax.googleapis.com/ajax/services/language/translate?v=1.0&q=" & _UnicodeURLEncode(GUICtrlRead($Edit1)) & "&langpair=" & $flag, False)
$xmlhttp.Send
$result = StringTrimLeft($xmlhttp.responseText, 36)
$result = StringTrimRight($result, 51)
GUICtrlSetData($Edit2, $result)
EndFunc ;==>_translate
Func _empty()
GUICtrlSetData($Edit1, "")
GUICtrlSetData($Edit2, "")
GUICtrlSetState($Edit1,$GUI_FOCUS)
EndFunc ;==>_empty
Func _change()
If GUICtrlRead($Label) = "英译汉" Then
GUICtrlSetData($Label, "汉译英")
GUICtrlSetColor($Label, 0x0000ff)
$flag = "zh-CN%7Cen"
Else
GUICtrlSetData($Label, "英译汉")
GUICtrlSetColor($Label, 0xff0000)
$flag = "en%7Czh-CN"
EndIf
EndFunc ;==>_change
Func _UnicodeURLEncode($UnicodeURL) ;==>_UnicodeURLEncode
Local $UnicodeBinaryLength, $UnicodeBinary, $UnicodeBinary2
$UnicodeBinary = StringToBinary($UnicodeURL, 4)
$UnicodeBinary2 = StringReplace($UnicodeBinary, '0x', '', 1)
$UnicodeBinaryLength = StringLen($UnicodeBinary2)
Local $EncodedString, $UnicodeBinaryChar, $EncodedString
For $i = 1 To $UnicodeBinaryLength Step 2
$UnicodeBinaryChar = StringMid($UnicodeBinary2, $i, 2)
If StringInStr("$-_.+!*'(),;/?:@=&abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890", BinaryToString('0x' & $UnicodeBinaryChar, 4)) Then
$EncodedString &= BinaryToString('0x' & $UnicodeBinaryChar)
Else
$EncodedString &= '%' & $UnicodeBinaryChar
EndIf
Next
Return $EncodedString
EndFunc ;==>_UnicodeURLEncode
|