[已解决]麻烦大神看下这个代码怎么优化
本帖最后由 liuyilun 于 2016-9-13 11:05 编辑自己写了个base64解码的工具,为什么监测剪贴板这个功能每次都需要激活窗口才能成功
我希望是我在别的窗口复制后,解码的窗口不用重新激活就能自动显示解码后的结果#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GUIEdit.au3>
#region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Base64解码", 623, 449, 192, 114)
$Edit1 = _GUICtrlEdit_Create($Form1, "", 60, 30, 500, 150, $ES_MULTILINE)
$Edit2 = _GUICtrlEdit_Create($Form1, "", 60, 200, 500, 150, $ES_MULTILINE)
$Button1 = GUICtrlCreateButton("解码", 60, 380, 89, 25)
$Button2 = GUICtrlCreateButton("监测模式", 200, 380, 89, 25)
$Dummy = GUICtrlCreateDummy()
GUISetState(@SW_SHOW)
$Form2 = GUICreate("Base64解码", 623, 280, 192, 114)
$Edit3 = _GUICtrlEdit_Create($Form2, "", 60, 30, 500, 150, $ES_MULTILINE)
$Button3 = GUICtrlCreateButton("返回普通模式", 60, 210, 89, 25)
$Button4 = GUICtrlCreateButton("退出", 200, 210, 89, 25)
#endregion ### END Koda GUI section ###
Local $Key = [["^a", $Dummy]]
GUISetAccelerators($Key)
;_GUICtrlEdit_SetSel($Edit1, 0, 0)
While 1
$nMsg = GUIGetMsg(1)
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
Case $Button1
If _GUICtrlEdit_GetText($Edit1) = "" Then
MsgBox(0, "", "空")
Else
$Str = _GUICtrlEdit_GetText($Edit1)
$Str = StringRegExp($Str, "code=(.*)", 1)
$Decode1 = _Base64Decode($Str)
$Decode2 = BinaryToString($Decode1, 4)
_GUICtrlEdit_SetText($Edit2, $Decode2)
EndIf
Case $Button2
GUISetState(@SW_SHOW, $Form2)
GUISetState(@SW_HIDE, $Form1)
Case $Button3
GUISetState(@SW_SHOW, $Form1)
GUISetState(@SW_HIDE, $Form2)
Case $Button4
Exit
Case $Dummy
Local $aResult = DllCall("user32.dll", "hwnd", "GetFocus")
Switch $aResult
Case $Edit1
_GUICtrlEdit_SetSel($Edit1, 0, -1)
Case $Edit2
_GUICtrlEdit_SetSel($Edit2, 0, -1)
EndSwitch
EndSwitch
If $nMsg == $Form2 Then
$Str = StringRegExp(ClipGet(), "code=(.*)", 1)
If @error = 1 Then ContinueLoop
If @error = 2 Then ContinueLoop
$Decode1 = _Base64Decode($Str)
$Decode2 = BinaryToString($Decode1, 4)
_GUICtrlEdit_SetText($Edit3, $Decode2)
EndIf
WEnd
Func _Base64Decode($Data)
Local $Opcode = "0xC81000005356578365F800E8500000003EFFFFFF3F3435363738393A3B3C3DFFFFFF00FFFFFF000102030405060708090A0B0C0D0E0F10111213141516171819FFFFFFFFFFFF1A1B1C1D1E1F202122232425262728292A2B2C2D2E2F303132338F45F08B7D0C8B5D0831D2E9910000008365FC00837DFC047D548A034384C0750383EA033C3D75094A803B3D75014AB00084C0751A837DFC047D0D8B75FCC64435F400FF45FCEBED6A018F45F8EB1F3C2B72193C7A77150FB6F083EE2B0375F08A068B75FC884435F4FF45FCEBA68D75F4668B06C0E002C0EC0408E08807668B4601C0E004C0EC0208E08847018A4602C0E00624C00A46038847028D7F038D5203837DF8000F8465FFFFFF89D05F5E5BC9C21000"
Local $CodeBuffer = DllStructCreate("byte[" & BinaryLen($Opcode) & "]")
DllStructSetData($CodeBuffer, 1, $Opcode)
Local $Ouput = DllStructCreate("byte[" & BinaryLen($Data) & "]")
Local $Ret = DllCall("user32.dll", "int", "CallWindowProc", "ptr", DllStructGetPtr($CodeBuffer), _
"str", $Data, _
"ptr", DllStructGetPtr($Ouput), _
"int", 0, _
"int", 0)
Return BinaryMid(DllStructGetData($Ouput, 1), 1, $Ret)
EndFunc ;==>_Base64Decode
$Str = StringRegExp(ClipGet(), "code=(.*)", 1)
If @error Then ContinueLoop
If $nMsg == $Form2 Then
$Decode1 = _Base64Decode($Str)
$Decode2 = BinaryToString($Decode1, 4)
_GUICtrlEdit_SetText($Edit3, $Decode2)
EndIf 好吧,我回复看看图 你不是自己写的这个么?
If $nMsg == $Form2 Then 本帖最后由 水木子 于 2016-9-13 10:09 编辑
#AccAu3Wrapper_UseX64=n
#include <GUIEdit.au3>
#include <Clipboard.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
Opt('GUIResizeMode', 802)
$hGui1 = GUICreate("Base64解码", 600, 450)
$Tab = GUICtrlCreateTab(-1, -1)
GUICtrlSetState(-1, 32 + 128)
$TabItem1 = GUICtrlCreateTabItem('TabItem1')
$Edit1 = GUICtrlCreateEdit("VGVzdA==", 20, 20, 560, 180, $ES_MULTILINE)
$Edit2 = GUICtrlCreateEdit("", 20, 250, 560, 180, $ES_MULTILINE)
$TabItem2 = GUICtrlCreateTabItem('TabItem2')
$Edit3 = GUICtrlCreateEdit("", 20, 20, 560, 180, $ES_MULTILINE)
GUICtrlCreateTabItem('')
$Checkbox1 = GUICtrlCreateCheckbox("监测模式", 30, 210, 80, 30)
$Button1 = GUICtrlCreateButton("加密", 300, 210, 80, 30)
$Button2 = GUICtrlCreateButton("解密", 400, 210, 80, 30)
$Button4 = GUICtrlCreateButton("退出", 500, 210, 80, 30)
GUISetState()
$hNext = _ClipBoard_SetViewer($hGui1)
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case -3, $Button4
_ClipBoard_ChangeChain($hGui1, $hNext)
Exit
Case $Checkbox1
If GUICtrlRead($Checkbox1) = 1 Then
WinMove($hGui1, '', Default, Default, Default, 280)
GUICtrlSetState($TabItem2, 16)
GUIRegisterMsg($WM_DRAWCLIPBOARD, "WM_DRAWCLIPBOARD")
Else
WinMove($hGui1, '', Default, Default, Default, 478)
GUICtrlSetState($TabItem1, 16)
GUIRegisterMsg($WM_DRAWCLIPBOARD, '')
EndIf
Case $Button1
$sStr = GUICtrlRead($Edit2)
If $sStr Then
$Encrypt = _Base64Encode($sStr)
GUICtrlSetData($Edit1, $Encrypt)
EndIf
Case $Button2
$sStr = GUICtrlRead($Edit1)
If $sStr Then
$Decrypt = _Base64Decode($sStr)
GUICtrlSetData($Edit2, BinaryToString($Decrypt, 4))
EndIf
EndSwitch
WEnd
Func _Base64Decode($Data)
Local $Opcode = "0xC81000005356578365F800E8500000003EFFFFFF3F3435363738393A3B3C3DFFFFFF00FFFFFF000102030405060708090A0B0C0D0E0F10111213141516171819FFFFFFFFFFFF1A1B1C1D1E1F202122232425262728292A2B2C2D2E2F303132338F45F08B7D0C8B5D0831D2E9910000008365FC00837DFC047D548A034384C0750383EA033C3D75094A803B3D75014AB00084C0751A837DFC047D0D8B75FCC64435F400FF45FCEBED6A018F45F8EB1F3C2B72193C7A77150FB6F083EE2B0375F08A068B75FC884435F4FF45FCEBA68D75F4668B06C0E002C0EC0408E08807668B4601C0E004C0EC0208E08847018A4602C0E00624C00A46038847028D7F038D5203837DF8000F8465FFFFFF89D05F5E5BC9C21000"
Local $CodeBuffer = DllStructCreate("byte[" & BinaryLen($Opcode) & "]")
DllStructSetData($CodeBuffer, 1, $Opcode)
Local $Ouput = DllStructCreate("byte[" & BinaryLen($Data) & "]")
Local $Ret = DllCall("user32.dll", "int", "CallWindowProc", "ptr", DllStructGetPtr($CodeBuffer), _
"str", $Data, _
"ptr", DllStructGetPtr($Ouput), _
"int", 0, _
"int", 0)
Return BinaryMid(DllStructGetData($Ouput, 1), 1, $Ret)
EndFunc ;==>_Base64Decode
Func _Base64Encode($Data, $LineBreak = 76)
Local $Opcode = "0x5589E5FF7514535657E8410000004142434445464748494A4B4C4D4E4F505152535455565758595A6162636465666768696A6B6C6D6E6F707172737475767778797A303132333435363738392B2F005A8B5D088B7D108B4D0CE98F0000000FB633C1EE0201D68A06880731C083F901760C0FB6430125F0000000C1E8040FB63383E603C1E60409C601D68A0688470183F90176210FB6430225C0000000C1E8060FB6730183E60FC1E60209C601D68A06884702EB04C647023D83F90276100FB6730283E63F01D68A06884703EB04C647033D8D5B038D7F0483E903836DFC04750C8B45148945FC66B80D0A66AB85C90F8F69FFFFFFC607005F5E5BC9C21000"
Local $CodeBuffer = DllStructCreate("byte[" & BinaryLen($Opcode) & "]")
DllStructSetData($CodeBuffer, 1, $Opcode)
$Data = Binary($Data)
Local $Input = DllStructCreate("byte[" & BinaryLen($Data) & "]")
DllStructSetData($Input, 1, $Data)
$LineBreak = Floor($LineBreak / 4) * 4
Local $OputputSize = Ceiling(BinaryLen($Data) * 4 / 3)
$OputputSize = $OputputSize + Ceiling($OputputSize / $LineBreak) * 2 + 4
Local $Ouput = DllStructCreate("char[" & $OputputSize & "]")
DllCall("user32.dll", "none", "CallWindowProc", "ptr", DllStructGetPtr($CodeBuffer), _
"ptr", DllStructGetPtr($Input), _
"int", BinaryLen($Data), _
"ptr", DllStructGetPtr($Ouput), _
"uint", $LineBreak)
Return DllStructGetData($Ouput, 1)
EndFunc ;==>_Base64Encode
Func WM_DRAWCLIPBOARD($hWnd, $iMsg, $iwParam, $ilParam)
Local $sText
$sText = ClipGet()
$Decrypt = _Base64Decode($sText)
GUICtrlSetData($Edit3, BinaryToString($Decrypt, 4))
ConsoleWrite($sText & @CRLF)
EndFunc ;==>WM_DRAWCLIPBOARD 回复 5# 水木子
留个脚印下来学习。 回复 5# 水木子
感谢大神,测试成功了,又学会了一招,顺便把改好的代码发一遍#region ;**** 参数创建于 ACNWrapper_GUI ****
#PRE_Icon=..\..\..\autoit3\Aut2Exe\Icons\au3.ico
#PRE_UseUpx=n
#PRE_UseX64=n
#PRE_Res_Fileversion=3.0.0.1
#PRE_Res_Fileversion_AutoIncrement=y
#PRE_Res_requestedExecutionLevel=None
#PRE_Run_Tidy=y
#endregion ;**** 参数创建于 ACNWrapper_GUI ****
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GUIEdit.au3>
#include <Clipboard.au3>
#region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Base64解码", 623, 449, 192, 114)
$Edit1 = _GUICtrlEdit_Create($Form1, "", 60, 30, 500, 150, $ES_MULTILINE)
$Edit2 = _GUICtrlEdit_Create($Form1, "", 60, 200, 500, 150, $ES_MULTILINE)
$Button1 = GUICtrlCreateButton("解码", 60, 380, 89, 25)
$Button2 = GUICtrlCreateButton("监测模式", 200, 380, 89, 25)
$Dummy = GUICtrlCreateDummy()
GUISetState(@SW_SHOW)
$Form2 = GUICreate("Base64解码", 623, 280, 192, 114)
$Edit3 = GUICtrlCreateEdit("", 60, 30, 500, 150, $ES_MULTILINE)
$Button3 = GUICtrlCreateButton("返回普通模式", 60, 210, 89, 25)
$Button4 = GUICtrlCreateButton("退出", 200, 210, 89, 25)
$hNext = _ClipBoard_SetViewer($Form2)
#endregion ### END Koda GUI section ###
Local $Key = [["^a", $Dummy]]
GUISetAccelerators($Key)
While 1
$nMsg = GUIGetMsg(1)
Switch $nMsg
Case $GUI_EVENT_CLOSE
_ClipBoard_ChangeChain($Form2, $hNext)
Exit
Case $Button1
If _GUICtrlEdit_GetText($Edit1) = "" Then
MsgBox(0, "", "空")
Else
$Str = _GUICtrlEdit_GetText($Edit1)
$Str = StringRegExp($Str, "code=(.*)", 3)
$Decode1 = _Base64Decode($Str)
$Decode2 = BinaryToString($Decode1, 4)
_GUICtrlEdit_SetText($Edit2, $Decode2)
EndIf
Case $Button2
GUISetState(@SW_SHOW, $Form2)
GUISetState(@SW_HIDE, $Form1)
Case $Button3
GUISetState(@SW_SHOW, $Form1)
GUISetState(@SW_HIDE, $Form2)
Case $Button4
Exit
Case $Dummy
Local $aResult = DllCall("user32.dll", "hwnd", "GetFocus")
Switch $aResult
Case $Edit1
_GUICtrlEdit_SetSel($Edit1, 0, -1)
Case $Edit2
_GUICtrlEdit_SetSel($Edit2, 0, -1)
EndSwitch
EndSwitch
If $nMsg == $Form2 Then
GUIRegisterMsg($WM_DRAWCLIPBOARD, "WM_DRAWCLIPBOARD")
EndIf
WEnd
Func _Base64Decode($Data)
Local $Opcode = "0xC81000005356578365F800E8500000003EFFFFFF3F3435363738393A3B3C3DFFFFFF00FFFFFF000102030405060708090A0B0C0D0E0F10111213141516171819FFFFFFFFFFFF1A1B1C1D1E1F202122232425262728292A2B2C2D2E2F303132338F45F08B7D0C8B5D0831D2E9910000008365FC00837DFC047D548A034384C0750383EA033C3D75094A803B3D75014AB00084C0751A837DFC047D0D8B75FCC64435F400FF45FCEBED6A018F45F8EB1F3C2B72193C7A77150FB6F083EE2B0375F08A068B75FC884435F4FF45FCEBA68D75F4668B06C0E002C0EC0408E08807668B4601C0E004C0EC0208E08847018A4602C0E00624C00A46038847028D7F038D5203837DF8000F8465FFFFFF89D05F5E5BC9C21000"
Local $CodeBuffer = DllStructCreate("byte[" & BinaryLen($Opcode) & "]")
DllStructSetData($CodeBuffer, 1, $Opcode)
Local $Ouput = DllStructCreate("byte[" & BinaryLen($Data) & "]")
Local $Ret = DllCall("user32.dll", "int", "CallWindowProc", "ptr", DllStructGetPtr($CodeBuffer), _
"str", $Data, _
"ptr", DllStructGetPtr($Ouput), _
"int", 0, _
"int", 0)
Return BinaryMid(DllStructGetData($Ouput, 1), 1, $Ret)
EndFunc ;==>_Base64Decode
Func WM_DRAWCLIPBOARD($hWnd, $iMsg, $iwParam, $ilParam)
Local $sText
$sText = ClipGet()
$Str = StringRegExp($sText, "code=(.*)", 3)
$Decrypt = _Base64Decode($Str)
GUICtrlSetData($Edit3, BinaryToString($Decrypt, 4))
ConsoleWrite($Str & @CRLF)
EndFunc ;==>WM_DRAWCLIPBOARD
学习了,请问一下这么长代码自动换行,是不是不能用换行符? Local $Opcode = "0xC81000005356578365F800E8500000003EFFFFFF3F3435363738393A3B3C3DFFFFFF00FFFFFF000102030405060708090A0B0C0D0E0F10111213141516171819FFFFFFFFFFFF1A1B1C1D1E1F202122232425262728292A2B2C2D2E2F303132338F45F08B7D0C8B5D0831D2E9910000008365FC00837DFC047D548A034384C0750383EA033C3D75094A803B3D75014AB00084C0751A837DFC047D0D8B75FCC64435F400FF45FCEBED6A018F45F8EB1F3C2B72193C7A77150FB6F083EE2B0375F08A068B75FC884435F4FF45FCEBA68D75F4668B06C0E002C0EC0408E08807668B4601C0E004C0EC0208E08847018A4602C0E00624C00A46038847028D7F038D5203837DF8000F8465FFFFFF89D05F5E5BC9C21000" 本帖最后由 水木子 于 2016-9-13 14:41 编辑
回复 8# fybhwsx
这样:$sText = '111' &_
'222' &_
'333' 回复 9# 水木子
知道了, 谢谢版主!
页:
[1]