谁能搞定这个问题??怎样得到剪切板中的HTML格式的内容?? 放了三天没搞定。

qyh 2002-08-05 10:19:41
在IE里选中一些文字并拷贝,剪切板里应该是HTML格式的内容,因为HTML格式的内容可以 ^V 到FrontPage中,我想要在我的程序中得到这些HTML格式的东西,怎么办?

1、clipboard.getdata得到的只是文本内容,不是我想要的HTML内容。

http://www.csdn.net/expert/topic/923/923381.xml?temp=.4539911
...全文
101 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
qyh 2002-08-05
  • 打赏
  • 举报
回复
y1g1y1(袁飞☆曾经沧海难为水,除却VB不是云☆) :

在下对你的敬仰之情有如滔滔江水绵绵不绝!
y1g1y1 2002-08-05
  • 打赏
  • 举报
回复
http://ygyuan.3322.net/
.袁飞的 win32api 超级酷站
.袁飞打印预览控件最新版下载!
===========================================

Option Explicit

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)

Public Function GetClipboardIDForCustomFormat(ByVal sName As String) As Long
Dim wFormat As Long
wFormat = RegisterClipboardFormat(sName & Chr$(0))
If (wFormat > &HC000&) Then
GetClipboardIDForCustomFormat = wFormat
End If
End Function

Public Function GetClipboardDataAsString(ByVal hWndOwner As Long, ByVal lFormatID As Long) As String
Dim bData() As Byte
Dim hMem As Long
Dim lSize As Long
Dim lPtr As Long

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

End Function


Private Sub Command1_Click()
Dim lID As Long
Dim sText As String

' 如果没有 IE4,可以使用 "RTF Format"
lID = GetClipboardIDForCustomFormat("HTML Format")
If (lID <> 0) Then
sText = GetClipboardDataAsString(Me.hWnd, lID)
Text1.Text = sText
End If

End Sub


7,757

社区成员

发帖
与我相关
我的任务
社区描述
VB 基础类
社区管理员
  • VB基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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