how to write to clipboard in CF_HTML

L

Luca Villa

How can I write to clipboard in CF_HTML format (not TEXT format) using
Javascript or another FF/IE compatible language?

I have an equivalent Visual Basic Code which does this but it
obviously cannot be used in FF/IE..

Here is the Visual Basic code:

_____
' Set HTML into the drop source's IDataObject
Private Sub SetHTMLData(Data As DataObject, htmlData As String)

Dim cf As Integer
Dim byteArray() As Byte
Dim ch As String
Dim i As Long

' Normalize the atom returned from RegisterClipboardFormat
If CF_HTML > 32767 Then
cf = 65536 - CF_HTML
cf = -cf
Else
cf = CF_HTML
End If

' Allocate an array of bytes to hold the HTML
ReDim byteArray(0 To Len(htmlData))

' Copy the data from the BSTR into the byte array
For i = 1 To Len(htmlData)
ch = Mid(htmlData, i, 1)
byteArray(i - 1) = Asc(ch)
Next

' Set the data into the IDataObject and set the clipboard format
Data.SetData byteArray, cf

End Sub
_____
 
W

w_a_x_man

How can I write to clipboard in CF_HTML format (not TEXT format) using
Javascript or another FF/IE compatible language?

I have an equivalent Visual Basic Code which does this but it
obviously cannot be used in FF/IE..

Here is the Visual Basic code:

_____
' Set HTML into the drop source's IDataObject
Private Sub SetHTMLData(Data As DataObject, htmlData As String)

Dim cf As Integer
Dim byteArray() As Byte
Dim ch As String
Dim i As Long

' Normalize the atom returned from RegisterClipboardFormat
If CF_HTML > 32767 Then
cf = 65536 - CF_HTML
cf = -cf
Else
cf = CF_HTML
End If

' Allocate an array of bytes to hold the HTML
ReDim byteArray(0 To Len(htmlData))

' Copy the data from the BSTR into the byte array
For i = 1 To Len(htmlData)
ch = Mid(htmlData, i, 1)
byteArray(i - 1) = Asc(ch)
Next

' Set the data into the IDataObject and set the clipboard format
Data.SetData byteArray, cf

End Sub
_____
 
W

w_a_x_man

How can I write to clipboard in CF_HTML format (not TEXT format) using
Javascript or another FF/IE compatible language?

I have an equivalent Visual Basic Code which does this but it
obviously cannot be used in FF/IE..

Here is the Visual Basic code:

_____
' Set HTML into the drop source's IDataObject
Private Sub SetHTMLData(Data As DataObject, htmlData As String)

Dim cf As Integer
Dim byteArray() As Byte
Dim ch As String
Dim i As Long

' Normalize the atom returned from RegisterClipboardFormat
If CF_HTML > 32767 Then
cf = 65536 - CF_HTML
cf = -cf
Else
cf = CF_HTML
End If

' Allocate an array of bytes to hold the HTML
ReDim byteArray(0 To Len(htmlData))

' Copy the data from the BSTR into the byte array
For i = 1 To Len(htmlData)
ch = Mid(htmlData, i, 1)
byteArray(i - 1) = Asc(ch)
Next

' Set the data into the IDataObject and set the clipboard format
Data.SetData byteArray, cf

End Sub
_____

This won't work in a browser.
Using SpiderMonkey and jslibs:

LoadModule('jswinshell')

clipboard = "Gadzooks!"
 
L

Luca Villa

Does SpiderMonkey and/or jslibs work in a browser? can they write to
the CF_HTML clipboard format?
 
T

Thomas 'PointedEars' Lahn

Luca said:
How can I write to clipboard in CF_HTML format (not TEXT format) using
Javascript or another FF/IE compatible language?

Short answer: Probably you can't.

Long answer:

Whatever CF_HTML format is, it is essentially a sequence of bytes. So yes,
given a programming language you can construct that sequence of bytes.
Whether you can write it to the clipboard is a different matter and depends
on the runtime environment, of course. Usually users have to grant
permission before you can access their clipboard, and the window system has
to support it.
I have an equivalent Visual Basic Code which does this but it
obviously cannot be used in FF/IE..

Here is the Visual Basic code:

This is a newsgroup about programming languages, thank you very much.


PointedEars
 
L

Luca Villa

Thomas said:
Short answer: Probably you can't.

Long answer:

Whatever CF_HTML format is, it is essentially a sequence of bytes.

Unfortunately I don't think that it's just a different sequence of
bytes. It seems a different version of the clipboard that needs to be
addressed specifically when writing to the clipboard.

In fact, when you make a copy to clipboard of a piece of a webpage
that you're seeing in Internet Explorer or Firefox, it fills the TEXT
format of the clipboard with the visible text and it fills the CF_HTML
format of the clipboard with the original source html.
They seems two separate versions of the clipboard filled separately.
 
T

Thomas 'PointedEars' Lahn

Luca said:
Unfortunately I don't think that it's just a different sequence of
bytes. It seems a different version of the clipboard that needs to be
addressed specifically when writing to the clipboard.

A quick Google search reveals:

,-<http://msdn.microsoft.com/en-us/library/aa767917(VS.85).aspx>
|
| [...]
| CF_HTML is entirely text format and uses the transformation format UTF-8.
| It includes a description, a context, and within the context, the
| fragment. [...]

Looks like a sequence of bytes/characters to me.

Either way, the parts of my reply that you snipped still apply, and how to
write to the clipboard in a specific runtime environment is off-topic here.


PointedEars
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,682
Members
48,796
Latest member
Greg L.

Latest Threads

Top