'One Example Of Transform String Between TextBox
'On the Form Text1、Text2、Label1、Label2、Command1Option Explicit Private Declare Function SendMessage Lib "user32" _
Alias "SendMessageA" _
(ByVal hwnd As Long, _
ByVal wMsg As Long, _
ByVal wParam As Long, _
ByVal lParam As String) _
As Long Private Const EM_GETLINE = &HC4
Private Const EM_GETLINECOUNT = &HBA
Private Const EM_LINEFROMCHAR = &HC9
Private Const EM_LINEINDEX = &HBB
Private Const EM_LINELENGTH = &HC1
Private Const EM_REPLACESEL = &HC2 Private Sub Form_Load()
With Command1
.Caption = "Insert This Text"
.Height = 375
.Left = 120
.Top = 3000
.Width = 1455
End With With Form1
.Caption = "Enhanced Text Box Sample Project"
.Height = 4485
.Width = 6990
End With With Label1
.Height = 195
.Left = 120
.Top = 240
.Width = 3015
.WordWrap = True
End With With Label2
.Height = 255
.Left = 1800
.Top = 3360
.Width = 3135
End With With Text1
.Height = 2655
.Left = 3360
.Top = 240
.Width = 3375
End With With Text2
.Height = 285
.Left = 1680
.Top = 3000
.Width = 5055
End With End Sub Private Sub Command1_Click()
Call SendMessage(Text1.hwnd, EM_REPLACESEL, 0, Text2.Text)
Label2.Caption = "Copied text is " + Text2.Text
ShowInfo
End Sub Private Sub Text1_KeyUp(KeyCode As Integer, Shift As Integer)
ShowInfo
End Sub Private Sub Text1_MouseMove(Button As Integer, _
Shift As Integer, _
X As Single, _
Y As Single)
ShowInfo
End Sub Private Function ShowInfo()
'********************************************************************
' Purpose: Runs all the functions to get the necessary information
' in order to create the information text string. The text
' string is then displayed in the label control.
'******************************************************************** Dim strInfo As String
Dim lCurPos As Long
Dim lCurLineNum As Long, lTotLines As Long, lLineLength
Dim lNumBChar As Long
Dim sCurLine As String * 25 'Determine Cursor Position
If Text1.SelLength = 0 Then
lCurPos = Text1.SelStart
Else
lCurPos = Text1.SelStart + Text1.SelLength
End If 'Determine Line Number
lCurLineNum = SendMessage(Text1.hwnd, EM_LINEFROMCHAR, lCurPos, 0) 'Determine the Line Length
lLineLength = SendMessage(Text1.hwnd, EM_LINELENGTH, lCurPos, 0) 'Determine the number of characters in lines before current
'cursor position. Note that the number of characters includes a
'carriage return and line feed characters at the end of each
'line.
lNumBChar = SendMessage(Text1.hwnd, EM_LINEINDEX, lCurLineNum, 0) 'Determine Total number of lines
lTotLines = SendMessage(Text1.hwnd, EM_GETLINECOUNT, 0, 0) 'Determine Current Line
sCurLine = Space(25)
Call SendMessage(Text1.hwnd, EM_GETLINE, lCurLineNum, sCurLine) 'Display the information
strInfo = "Current Line: " + sCurLine + vbLf + _
"Line Length: " + CStr(lLineLength) + _
" Characters" + vbLf + _
"Line Number: " + CStr(lCurLineNum + 1) + _
" of " + CStr(lTotLines) + " Total Lines" + vbLf + _
"Cursor Position: " + CStr(lCurPos) + vbLf + _
"Total Characters in Previous Lines: " + _
CStr(lNumBChar) + vbLf + _
"Selected Length: " + CStr(Text1.SelLength) + vbLf + _
"Selected Text: " + Text1.SelText Label1.Caption = strInfo End Function
'On the Form Text1、Text2、Label1、Label2、Command1Option Explicit Private Declare Function SendMessage Lib "user32" _
Alias "SendMessageA" _
(ByVal hwnd As Long, _
ByVal wMsg As Long, _
ByVal wParam As Long, _
ByVal lParam As String) _
As Long Private Const EM_GETLINE = &HC4
Private Const EM_GETLINECOUNT = &HBA
Private Const EM_LINEFROMCHAR = &HC9
Private Const EM_LINEINDEX = &HBB
Private Const EM_LINELENGTH = &HC1
Private Const EM_REPLACESEL = &HC2 Private Sub Form_Load()
With Command1
.Caption = "Insert This Text"
.Height = 375
.Left = 120
.Top = 3000
.Width = 1455
End With With Form1
.Caption = "Enhanced Text Box Sample Project"
.Height = 4485
.Width = 6990
End With With Label1
.Height = 195
.Left = 120
.Top = 240
.Width = 3015
.WordWrap = True
End With With Label2
.Height = 255
.Left = 1800
.Top = 3360
.Width = 3135
End With With Text1
.Height = 2655
.Left = 3360
.Top = 240
.Width = 3375
End With With Text2
.Height = 285
.Left = 1680
.Top = 3000
.Width = 5055
End With End Sub Private Sub Command1_Click()
Call SendMessage(Text1.hwnd, EM_REPLACESEL, 0, Text2.Text)
Label2.Caption = "Copied text is " + Text2.Text
ShowInfo
End Sub Private Sub Text1_KeyUp(KeyCode As Integer, Shift As Integer)
ShowInfo
End Sub Private Sub Text1_MouseMove(Button As Integer, _
Shift As Integer, _
X As Single, _
Y As Single)
ShowInfo
End Sub Private Function ShowInfo()
'********************************************************************
' Purpose: Runs all the functions to get the necessary information
' in order to create the information text string. The text
' string is then displayed in the label control.
'******************************************************************** Dim strInfo As String
Dim lCurPos As Long
Dim lCurLineNum As Long, lTotLines As Long, lLineLength
Dim lNumBChar As Long
Dim sCurLine As String * 25 'Determine Cursor Position
If Text1.SelLength = 0 Then
lCurPos = Text1.SelStart
Else
lCurPos = Text1.SelStart + Text1.SelLength
End If 'Determine Line Number
lCurLineNum = SendMessage(Text1.hwnd, EM_LINEFROMCHAR, lCurPos, 0) 'Determine the Line Length
lLineLength = SendMessage(Text1.hwnd, EM_LINELENGTH, lCurPos, 0) 'Determine the number of characters in lines before current
'cursor position. Note that the number of characters includes a
'carriage return and line feed characters at the end of each
'line.
lNumBChar = SendMessage(Text1.hwnd, EM_LINEINDEX, lCurLineNum, 0) 'Determine Total number of lines
lTotLines = SendMessage(Text1.hwnd, EM_GETLINECOUNT, 0, 0) 'Determine Current Line
sCurLine = Space(25)
Call SendMessage(Text1.hwnd, EM_GETLINE, lCurLineNum, sCurLine) 'Display the information
strInfo = "Current Line: " + sCurLine + vbLf + _
"Line Length: " + CStr(lLineLength) + _
" Characters" + vbLf + _
"Line Number: " + CStr(lCurLineNum + 1) + _
" of " + CStr(lTotLines) + " Total Lines" + vbLf + _
"Cursor Position: " + CStr(lCurPos) + vbLf + _
"Total Characters in Previous Lines: " + _
CStr(lNumBChar) + vbLf + _
"Selected Length: " + CStr(Text1.SelLength) + vbLf + _
"Selected Text: " + Text1.SelText Label1.Caption = strInfo End Function
实际上就是取得句柄.然后用SendMessage传递!!
我记得有个API是获取当前输标所在位置句柄的,但忘了是哪个了。。
汗~~~
有个可以取指定位置(POINTAPI类型)句柄的API涵数可以找出这个句柄。
你 真的试验过?给网页的文本框传递?
那个可以去指定位置的句柄函数是:
Private Declare Function WindowFromPoint Lib "user32" Alias "WindowFromPoint" (ByVal xPoint As Long, ByVal yPoint As Long) As Long谢谢帮忙
假设你的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 SubPrivate 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 = "[email protected]"
End Select
ElseIf vTag.Type = "submit" Then
vTag.Click
End If
End If
Next i
End Sub
点击Command1就可以自动填表并提交了。