如何用vb获取指定网页的验证码啊?(可以用webbrowser)
2011年07月08日
如何用vb获取指定网页的验证码啊?(可以用webbrowser)
在vb中建立一个image,如何让验证码显示在image里面啊?
满意答案:
在窗体上建立一个text1,一个command1,还有picVlCode和intGetVlCode.
窗体代码如下:
Private Sub Command1_Click()
GetVlCode
End Sub
'-----------------------------------------------
'- 获取验证码(GetVlCode)
'-----------------------------------------------
Private Sub GetVlCode()
On Error Resume Next
Dim Buff() As Byte
'验证码地址
intGetVlCode.URL = Text1.Text
'以二进制方式存入buff数组
Buff() = intGetVlCode.OpenURL(, icByteArray)
With picVlCode
'绘制成图片对象
.Picture = PictureFromBits(Buff())
'描绘到picturebox
.PaintPicture .Picture, 0, 0, .Width, .Height, 0, 0, .ScaleWidth, .ScaleHeight
End With
End Sub
模块代码:
'-----------------------------------
' 转换验证码图片
'-----------------------------------
Public Enum CBoolean
CFalse = 0
CTrue = 1
End Enum
Private Const S_OK = 0
Private Declare Function CreateStreamOnHGlobal Lib "ole32" _
(ByVal hGlobal As Long, _
ByVal fDeleteOnRelease As CBoolean, _
ppstm As Any) As Long
Private Declare Function OleLoadPicture Lib "olepro32" _
(pStream As Any, _
ByVal lSize As Long, _
ByVal fRunmode As CBoolean, _
riid As GUID, _
ppvObj As Any) As Long
Public Type GUID
dwData1 As Long
wData2 As Integer
wData3 As Integer
abData4(7) As Byte
End Type
Private Declare Function CLSIDFromString Lib "ole32" (ByVal lpsz As Any, pclsid As GUID) As Long
Private Const sIID_IPicture = "{7BF80980-BF32-101A-8BBB-00AA00300CAB}"
Private Const GMEM_MOVEABLE = &H2
Private Declare Function GlobalAlloc Lib "KERNEL32" (ByVal uFlags As Long, ByVal dwBytes As Long) As Long
Private Declare Function GlobalLock Lib "KERNEL32" (ByVal hMem As Long) As Long
Private Declare Function GlobalUnlock Lib "KERNEL32" (ByVal hMem As Long) As Long
Private Declare Function GlobalFree Lib "KERNEL32" (ByVal hMem As Long) As Long
Private Declare Sub MoveMemory Lib "KERNEL32" Alias "RtlMoveMemory" (pDest As Any, pSource As Any, ByVal dwLength As Long)
Public Function PictureFromBits(abPic() As Byte) As IPicture
Dim nLow As Long
Dim cbMem As Long
Dim hMem As Long
Dim lpMem As Long
Dim IID_IPicture As GUID
Dim istm As stdole.IUnknown
Dim ipic As IPicture
On Error GoTo Out
nLow = LBound(abPic)
On Error GoTo 0
cbMem = (UBound(abPic) - nLow) + 1
hMem = GlobalAlloc(GMEM_MOVEABLE, cbMem)
If hMem Then
lpMem = GlobalLock(hMem)
If lpMem Then
MoveMemory ByVal lpMem, abPic(nLow), cbMem
Call GlobalUnlock(hMem)
If (CreateStreamOnHGlobal(hMem, CTrue, istm) = S_OK) Then
If (CLSIDFromString(StrPtr(sIID_IPicture), IID_IPicture) = S_OK) Then
Call OleLoadPicture(ByVal ObjPtr(istm), cbMem, CFalse, IID_IPicture, PictureFromBits)
End If
End If
End If
End If
Out:
End Function
例子给你写好了,加Q,传你,给分,谢谢。
追问:
你q多少?我加你
补充:138001655
相关问题:
vb 用WebBrowser打开网页
VB 打开指定网页
WebBrowser打开的网页上的图片地址 VB
vb中的WebBrowser的保存网页
VB 如何添加一个简单网页WebBrowser ,急
转载来自于:如何用vb获取指定网页的验证码啊?(可以用webbrowser)