本帖最后由 lpxx 于 2011-7-4 21:40 编辑
验证码例子
附件就不要下载了,费钱,附件源码已经贴出。
#include <GUIConstantsEx.au3>
$iOptOld = Opt("GUIEventOptions", 0)
Opt("GUIEventOptions", $iOptOld)
Global $Char[6], $t1[5], $t2[2], $t3[6]
Global $t5
yzm()
Func yzm()
Local $t4
$t5 = 0
$hWnd = GUICreate("验证码例子", 175, 155, -1, -1, 0x00080000)
$cBg = GUICtrlCreateLabel("", 10, 10, 150, 50)
GUICtrlSetState($cBg, 128)
GUICtrlSetBkColor($cBg, 0x000000)
$cInput = GUICtrlCreateInput("", 10, 70, 150, 20)
$cNew = GUICtrlCreateButton("刷新", 90, 95, 70)
$t4 = yzm_Create()
$cFg = GUICtrlCreateLabel("", 10, 10, 150, 50)
GUICtrlSetBkColor($cFg, -2)
GUISetState()
While 1
Switch GUIGetMsg()
Case -3
Exit
Case $cNew
yzm_Delete()
$t4 = yzm_Create()
GUICtrlSetData($cInput, $t4)
EndSwitch
WEnd
EndFunc ;==>yzm
Func yzm_Create()
Local $sCaptcha = yzm_Generate()
Local $iX = Random(15, 25, 1)
Local $iY = Random(15, 40, 1)
$t3[0] = "Arial Black"
$t3[1] = "Comic Sans MS"
$t3[2] = "Impact"
$t3[3] = "Tahoma"
$t3[4] = "System"
$t3[5] = "Verdama"
$aSplit = StringSplit($sCaptcha, "")
For $x = 0 To 5
$Char[$x] = GUICtrlCreateLabel($aSplit[$x + 1], $iX, $iY)
$iX += 20 + Random(1, 5, 1)
$iY = Random(15, 40, 1)
GUICtrlSetBkColor($Char[$x], -2)
GUICtrlSetColor($Char[$x], Random(0x808080, 0xC0C0C0))
$iNum = Random(1, 7, 1)
Switch $iNum
Case 1
$iStyle = 2 ;2
Case 2
$iStyle = 4 ;4
Case 3
$iStyle = 8 ;8
Case 4
$iStyle = 2 + 4 ;6
Case 5
$iStyle = 4 + 8 ;12
Case 6
$iStyle = 2 + 8 ;10
Case 7
$iStyle = 2 + 4 + 8 ;16
EndSwitch
GUICtrlSetFont($Char[$x], 13, Random(350, 450, 1), $iStyle, $t3[Random(0, 5, 1)])
Sleep(10)
Next
$iX = 15 + Random(1, 10, 1)
$iY = 5 + Random(1, 10, 1)
For $z = 0 To 4
$t1[$z] = GUICtrlCreateLabel("", $iX, $iY, 1, 30)
$iX += 25 + Random(1, 10, 1)
$iY = 5 + Random(1, 30, 1)
GUICtrlSetBkColor($t1[$z], Random(0x808080, 0xC0C0C0))
Next
$iX = 5 + Random(1, 25, 1)
$iY = 20 + Random(1, 10, 1)
For $b = 0 To 1
$t2[$b] = GUICtrlCreateLabel("", $iX, $iY, 130, 1)
$iX = 5 + Random(1, 10, 1)
$iY += 10 + Random(1, 10, 1)
GUICtrlSetBkColor($t2[$b], Random(0x808080, 0xC0C0C0))
Next
Return $sCaptcha
EndFunc ;==>yzm_Create
Func yzm_Delete()
For $y = 0 To 5
GUICtrlDelete($Char[$y])
Next
For $a = 0 To 4
GUICtrlDelete($t1[$a])
Next
For $c = 0 To 1
GUICtrlDelete($t2[$c])
Next
EndFunc ;==>yzm_Delete
Func yzm_Generate()
Local $sCharacters = StringSplit("BCDFGHJKLMNPQRSTVWXYZ1234567890", "")
Local $sCode = ""
For $i = 1 To 6
$sCode &= $sCharacters[Random(1, $sCharacters[0], 1)]
Next
Return $sCode
EndFunc ;==>yzm_Generate
|