高分请教:如何实现IE表单自动完成?

Herro 2002-01-03 01:53:18
我的软件中附带了一个微型的浏览器,为方便用户登陆社区,需要实现自动完成登陆表单。请问如何实现?(不是地址栏URL自动完成)
...全文
165 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
sonicdater 2002-01-12
  • 打赏
  • 举报
回复
'希望 你能从下面的 代码中 得到 启发 :)

Private Declare Function SendMessage Lib "User32" Alias "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Integer, ByVal wParam As Integer, lParam As Any) As Long
Const LB_FINDSTRING = &H18F
Dim byKey As Boolean' is list1_click Event activated by a key press ?
Dim byCode As Boolean' is text1_change Event activated by code ?


Private Sub Form_Load()
' init some things ...
' first, hide list
List1.Visible = False
' set list position
List1.Top = Text1.Top + Text1.Height
List1.Left = Text1.Left
List1.Width = Text1.Width
' set list in front of all objects
List1.ZOrder
' then, let's populate the listbox with
' random strings


For i = 0 To 10000
a$ = ""


For j = 0 To 8
a$ = a$ & Chr$(Int(Rnd(1) * 26 + 65))
Next
List1.AddItem a$
Next
End Sub


Private Sub List1_Click()
' overrides any "list1.visible=false" ev
' ent-driven code ...
List1.Visible = True
' if the listindex changed because of a
' key press, we don't need to move the car
' et


If byKey = True Then
' we need to store the caret position be
' cause
' it'll be zero when we'll update the te
' xt
n = Text1.SelStart
Else
n = 0
End If
' change text box contents according to
' item selected
byCode = True' avoids calling text1_change Event
Text1.Text = List1.List(List1.ListIndex)
byCode = False
' let's change the selected text
Text1.SelStart = n
Text1.SelLength = Len(Text1.Text) - n
End Sub


Private Sub Text1_Change()
' if we come from list1_click event, exi
' t at once
If byCode = True Then Exit Sub


If Len(Text1.Text) <> 0 Then
' show the list
List1.Visible = True
' store caret position
n = Text1.SelStart
byKey = True
' find the listindex of the first occure
' nce of text1.text in listbox1
p = SendMessage(List1.hWnd, LB_FINDSTRING, -1, ByVal Left$(Text1.Text, n))


If p >= 0 Then


If p <> List1.ListIndex Then
List1.ListIndex = p
Else
List1_Click
End If
Else
' it wasn't found in listbox1 so we don'
' t need what's after the caret anymore
byCode = True
Text1.Text = Left$(Text1.Text, n)
Text1.SelStart = n
byCode = False
End If
byKey = False
Else
' hide the list if text1.text is empty
List1.Visible = False
End If
End Sub


Private Sub Text1_DblClick()
' hides/unhides list1 on double click
' this is a very nice trick (fast too) t
' o avoid using IF x=true THEN x=false ELS
' E x=true
' remember that TRUE=-1 and FALSE=0
' X = -X - 1 switches from 0 to -1 and -
' 1 to 0 nicely :-)
List1.Visible = -List1.Visible - 1
End Sub


Private Sub Text1_Keydown(KeyCode As Integer, Shift As Integer)
' LSTEP = how many items are scrolled do
' wn/up when pressing pgup/pgdn
' a constant here but this can certainly
' be computed though
Const LSTEP = 10


Select Case KeyCode
Case vbKeyUp' move up the list
List1.ListIndex = IIf(List1.ListIndex = 0, 0, List1.ListIndex - 1)
KeyCode = 0
Case vbKeyDown ' move down the list
List1.ListIndex = IIf(List1.ListCount - 1 = List1.ListIndex, List1.ListCount - 1, List1.ListIndex + 1)
KeyCode = 0
Case vbKeyPageUp' scroll up more items
n = List1.ListIndex - LSTEP
If n < 0 Then n = 0
List1.ListIndex = n
Case vbKeyPageDown ' scroll down more items
n = List1.ListIndex + LSTEP
If n > List1.ListCount - 1 Then n = List1.ListCount - 1
List1.ListIndex = n
Case vbKeyReturn
' when Enter is pressed, make it behave
' like Tab key
SendKeys "{TAB}", True
End Select
End Sub


Private Sub Text1_LostFocus()
' focus goes somewhere else, so hide lis
' tbox
List1.Visible = False
End Sub
Bardo 2002-01-12
  • 打赏
  • 举报
回复
Document.form.submit
Herro 2002-01-12
  • 打赏
  • 举报
回复
不是,IE可以实现自动完成,但WebBrowser控件本身好像没有这功能。我想实现它。
sonicdater 2002-01-04
  • 打赏
  • 举报
回复
在 注册表 中 有修改的 地方,不知你是不是 这个 意思?
Herro 2002-01-04
  • 打赏
  • 举报
回复
有人会么? 谢了
Herro 2002-01-03
  • 打赏
  • 举报
回复
不是通过WebBrowser1.Document,我需要调用IE本身的自动完成功能,就是填一个字母就会出来侯选列表。
TechnoFantasy 2002-01-03
  • 打赏
  • 举报
回复
可以引用MSHTML对页面进行分析并填写内容:

假设你的HTML页面表单代码如下:
<form method="POST" action="http://chen/dll/chat/chatmain.exe/RegUser">
<p>请填写下面表单注册(*项为必添项)</p>
<p>*姓名<input type="text" name="Name" size="20"></p>
<p>*昵称<input type="text" name="NickName" size="20"></p>
<p>电子邮件<input type="text" name="EMail" size="20"></p>
<p>*密码<input type="text" name="Password" size="20"></p>
<p><input type="submit" value="提交" name="B1"><input type="reset" value="全部重写" name="B2"></p>
</form>
注意其中元素的type、Name、value属性。然后VB中的代码如下:
Private Sub Command1_Click()
WebBrowser1.Navigate "http://chen/chat/newuser.htm"
End Sub

Private Sub WebBrowser1_DocumentComplete(ByVal pDisp As Object, URL As Variant)
Dim vDoc, vTag
Dim i As Integer

Set vDoc = WebBrowser1.Document
List1.Clear
For i = 0 To vDoc.All.length - 1
If UCase(vDoc.All(i).tagName) = "INPUT" Then
Set vTag = vDoc.All(i)
If vTag.Type = "text" Or vTag.Type = "password" Then
List1.AddItem vTag.Name
Select Case vTag.Name
Case "Name"
vTag.Value = "IMGod"
Case "NickName"
vTag.Value = "IMGod"
Case "Password"
vTag.Value = "IMGodpass"
Case "EMail"
vTag.Value = "IMGod@paradise.com"
End Select
ElseIf vTag.Type = "submit" Then
vTag.Click
End If
End If
Next i
End Sub
点击Command1就可以自动填表并提交了。
junglerover 2002-01-03
  • 打赏
  • 举报
回复
在表单上嵌一个控件,然后用控件来往表单的各个域里填充值。
只要你分析过这个表单的结构,就应该不难做到。
当然,你不是要做到自动完成任意的登录表单吧?
junglerover 2002-01-03
  • 打赏
  • 举报
回复
原来通过WebBrowser.Document果然可以访问到WEBBROWSER里面的文档对象,
是我多虑了。
楼上说得对。

742

社区成员

发帖
与我相关
我的任务
社区描述
VB 版八卦、闲侃,联络感情地盘,禁广告帖、作业帖
社区管理员
  • 非技术类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧