举例说明:运行一个VB程序,意在获取IE窗口的句柄,然后打开论坛发贴子的窗口,将光标定位到了文章内容的文本框内,此时又打开了一个文本文件,复制了一些文本,这时再用那个VB程序将剪贴板中的文本粘贴到论坛发贴的文本框中。
请问,在用VB程序粘贴时:
1.怎样确保将内容粘贴到IE窗口中,而不是文本文件窗口中
2.怎样判断发贴窗口的光标刚才是否定位在文本框中
3.怎样将剪贴板中的内容粘贴到那个文本框中
谢谢!
请问,在用VB程序粘贴时:
1.怎样确保将内容粘贴到IE窗口中,而不是文本文件窗口中
2.怎样判断发贴窗口的光标刚才是否定位在文本框中
3.怎样将剪贴板中的内容粘贴到那个文本框中
谢谢!
Dim buf As String
Dim bData() As Byte
Dim hMem As Long
Dim lSize As Long
Dim lPtr As Long
hwndowner =me.hwnd
lFormatID = 1
If (OpenClipboard(hwndowner)) Then
If (IsClipboardFormatAvailable(lFormatID) <> 0) Then
hMem = GetClipboardData(lFormatID)
If (hMem <> 0) Then
lSize = GlobalSize(hMem)
If (lSize > 0) Then
lPtr = GlobalLock(hMem)
If (lPtr <> 0) Then
ReDim bData(0 To lSize - 1) As Byte
CopyMemory bData(0), ByVal lPtr, lSize
GlobalUnlock hMem
GetClipboardDataAsString = StrConv(bData, vbUnicode)
End If
End If
End If
End If
CloseClipboard
End If
API函数声明:
Private Declare Function OpenClipboard Lib "user32" (ByVal hwnd As Long) As Long
Private Declare Function CloseClipboard Lib "user32" () As Long
Private Declare Function GetClipboardData Lib "user32" (ByVal wFormat As Long) As Long
Private Declare Function IsClipboardFormatAvailable Lib "user32" (ByVal wFormat As Long) As Long
Private Declare Function RegisterClipboardFormat Lib "user32" Alias "RegisterClipboardFormatA" (ByVal lpString As String) 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 GlobalSize Lib "kernel32" (ByVal hMem As Long) As Long
Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (lpvDest As Any, lpvSource As Any, ByVal cbCopy As Long)
Dim IEs As New ShellWindows
Dim IE
Dim s As String
s = Clipboard.GetText
For Each IE In IEs
If IE.LocationURL = "http://www.csdn.net" Then
IE.Document.body.All("name").Value = s
End If
Next
End Sub运行程序前先打开csdn首页,然后跑程序,点击command1可以将剪贴板中的内容复制到首页登录的用户框中。
我就不提供代码了...因为提供方法是最好的学习方法了...让你增加认识...