By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,136 Members | 1,054 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,136 IT Pros & Developers. It's quick & easy.

RTF to HTML and reverse...!

P: n/a
Good evening.

Few day ago i ask about this Object.
A very kindly replay of Sthepen Lebans give me the solution
to use ClipBoard to synthesise the Conversion, but i've some truble.

My scene:

I use a RichTextBox to write the Formatted Text, and i need
to send the content by Mail with Winsok.
To do this i need to format then Body on HTML.
On reverse when i receive HTML Mail i extract HTML message
and i put it on Web Browser control.

So now i have a question:

If i use textRTF property Control and i copy this on Clipboard it's like a
Text only and my conversion it's impossible, because the HTML format is not
available.

I register RegisterClipboardFormat("HTML Format"), but with a ClipBoard
Viewer
i can't see it like available to covert my textRTF.

If i make a Selection by mouse and copy with CTRL+C i have HTML format
available
and i can convert my RTFText on HTML....!!!

What can be my mistake..?

This is the code to copy on Clipboard, taken from Lebans Demo

First i register the new format:

CF_RTF = RegisterClipboardFormat("Rich Text Format")
CF_HTML= RegisterClipboardFormat("HTML Format")

After i copy

Function SetClipBoard(strRTF_IN As String) As Boolean
Dim hMainMem As Long
Dim lpMainMem As Long
Dim hCMem As Long

hMainMem = GlobalAlloc(GHND, Len(strRTF_IN) + 1)
lpMainMem = GlobalLock(hMainMem )
lpMainMem = lstrcpy(lpMainMem , strRTF_IN)
If GlobalUnlock(hMainMem ) = 0 Then
If OpenClipboard(0&) <> 0 Then
Call EmptyClipboard
hCMem = SetClipboardData(CF_RTF, hMainMem )
SetClipBoard = CBool(CloseClipboard)
End If
End If
End Function

Here no HTML available conversion on ClipBoard.

Thanks to all for any suggestion
--
(Alessandro Baraldi)
Nov 13 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
Sorry for not getting back to you Alessandro. I actually spent a few
hours on this issue late sunday night and was tied all of today on
business.

First the CF_HTML clipboard format requires a header.
Here is a sample.

Version:1.0
StartHTML:000000174
EndHTML:000000886
StartFragment:000000610
EndFragment:000000725
StartSelection:000000650
EndSelection:000000725
SourceURL:about:blank
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

<HTML><HEAD></HEAD>

<BODY>
<FONT face=Arial>
<FONT size=7>
<FONT style="BACKGROUND-COLOR: #000000" color=#ffffff>
<FONT size=1>
<FONT size=1>
<FONT style="BACKGROUND-COLOR: #ffffff">
<FONT color=#000000>
<STRONG>
<FONT face=Arial>
<FONT size=7>
<FONT style="BACKGROUND-COLOR: #000000" color=#ffffff>
<FONT size=1>
<FONT size=1>

<P><!--StartFragment--><FONT style="BACKGROUND-COLOR: #ffffff"><FONT
color=#0000ff>This is bold and <EM>this is
italic.</EM></FONT></FONT><!--EndFragment--></P>
</FONT>
</FONT>
</FONT>
</FONT>
</FONT>
</STRONG>
</FONT>
</FONT>
</FONT>
</FONT>
</FONT>
</FONT>
</FONT>
</BODY>
</HTML>

A doc detailing the header is here but it is for the older .9 version.
http://msdn.microsoft.com/library/de.../en-us/winui/w
inui/windowsuserinterface/dataexchange/clipboard/htmlclipboardformat.asp

VB Source code for creating the header is here:
http://support.microsoft.com/default...b;en-us;274326

Now as you have discovered you can manually cut and paste from Internet
Explorer to the RTF control. But if you programmatically build the
identical CF_HTML string you can place it on the Clipboard but you
cannot paste it into the RTF control. It would seem the application(IE)
originating the HTML is resonsible for generating the RTF string. The
Clipboard object cannot directly generate RTF from HTML. It asks the
originating appllication that places the HTML on the Clipboard to
generate the RTF string.

I swear that I have read in the bowels of the MSDN OLE documentation
that the Clipboard object can convert from HTML to RTF independant of
the application that places the HTML on the Clipboard. I have searched
but cannot find the reference. Perhaps it is an operating system
function that is not exposed but available to Microsoft applications
only. I'm sure it is out there somewhere.

Anyhow, you would seem to have two choices.

1) Use the HTML Editor on my site and forget about the RTF control.

2) Use the HTML Editor and the RTF control. If you place the MS Web
Browser control on a form you can programmatically issue the OLE
Method(Action prop = 4) to copy the contents of the control to the
Clipboard. YOu can then programmatically set focus to the RTF control
and issue a Paste command and vice versa. If you do not want to place
the Web Browser control ona form you could instantiate an instance of
Internet Explore and use it instead.

Let me know how you make out.
--

HTH
Stephen Lebans
http://www.lebans.com
Access Code, Tips and Tricks
Please respond only to the newsgroups so everyone can benefit.
"ALESSANDRO Baraldi" <ik****@libero.it> wrote in message
news:co**********@lacerta.tiscalinet.it...
Good evening.

Few day ago i ask about this Object.
A very kindly replay of Sthepen Lebans give me the solution
to use ClipBoard to synthesise the Conversion, but i've some truble.

My scene:

I use a RichTextBox to write the Formatted Text, and i need
to send the content by Mail with Winsok.
To do this i need to format then Body on HTML.
On reverse when i receive HTML Mail i extract HTML message
and i put it on Web Browser control.

So now i have a question:

If i use textRTF property Control and i copy this on Clipboard it's like a Text only and my conversion it's impossible, because the HTML format is not available.

I register RegisterClipboardFormat("HTML Format"), but with a ClipBoard Viewer
i can't see it like available to covert my textRTF.

If i make a Selection by mouse and copy with CTRL+C i have HTML format
available
and i can convert my RTFText on HTML....!!!

What can be my mistake..?

This is the code to copy on Clipboard, taken from Lebans Demo

First i register the new format:

CF_RTF = RegisterClipboardFormat("Rich Text Format")
CF_HTML= RegisterClipboardFormat("HTML Format")

After i copy

Function SetClipBoard(strRTF_IN As String) As Boolean
Dim hMainMem As Long
Dim lpMainMem As Long
Dim hCMem As Long

hMainMem = GlobalAlloc(GHND, Len(strRTF_IN) + 1)
lpMainMem = GlobalLock(hMainMem )
lpMainMem = lstrcpy(lpMainMem , strRTF_IN)
If GlobalUnlock(hMainMem ) = 0 Then
If OpenClipboard(0&) <> 0 Then
Call EmptyClipboard
hCMem = SetClipboardData(CF_RTF, hMainMem )
SetClipBoard = CBool(CloseClipboard)
End If
End If
End Function

Here no HTML available conversion on ClipBoard.

Thanks to all for any suggestion
--
(Alessandro Baraldi)


Nov 13 '05 #2

P: n/a
"Stephen Lebans" <Fo****************************************@linval id.com>
ha scritto nel messaggio
news:85**********************@ursa-nb00s0.nbnet.nb.ca...
Sorry for not getting back to you Alessandro. I actually spent a few
hours on this issue late sunday night and was tied all of today on
business.

First the CF_HTML clipboard format requires a header.
Here is a sample.

Version:1.0
StartHTML:000000174
EndHTML:000000886
StartFragment:000000610
EndFragment:000000725
StartSelection:000000650
EndSelection:000000725
SourceURL:about:blank
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

<HTML><HEAD></HEAD>

<BODY>
<FONT face=Arial>
<FONT size=7>
<FONT style="BACKGROUND-COLOR: #000000" color=#ffffff>
<FONT size=1>
<FONT size=1>
<FONT style="BACKGROUND-COLOR: #ffffff">
<FONT color=#000000>
<STRONG>
<FONT face=Arial>
<FONT size=7>
<FONT style="BACKGROUND-COLOR: #000000" color=#ffffff>
<FONT size=1>
<FONT size=1>

<P><!--StartFragment--><FONT style="BACKGROUND-COLOR: #ffffff"><FONT
color=#0000ff>This is bold and <EM>this is
italic.</EM></FONT></FONT><!--EndFragment--></P>
</FONT>
</FONT>
</FONT>
</FONT>
</FONT>
</STRONG>
</FONT>
</FONT>
</FONT>
</FONT>
</FONT>
</FONT>
</FONT>
</BODY>
</HTML>

A doc detailing the header is here but it is for the older .9 version.
http://msdn.microsoft.com/library/de.../en-us/winui/w
inui/windowsuserinterface/dataexchange/clipboard/htmlclipboardformat.asp

VB Source code for creating the header is here:
http://support.microsoft.com/default...b;en-us;274326

Now as you have discovered you can manually cut and paste from Internet
Explorer to the RTF control. But if you programmatically build the
identical CF_HTML string you can place it on the Clipboard but you
cannot paste it into the RTF control. It would seem the application(IE)
originating the HTML is resonsible for generating the RTF string. The
Clipboard object cannot directly generate RTF from HTML. It asks the
originating appllication that places the HTML on the Clipboard to
generate the RTF string.

I swear that I have read in the bowels of the MSDN OLE documentation
that the Clipboard object can convert from HTML to RTF independant of
the application that places the HTML on the Clipboard. I have searched
but cannot find the reference. Perhaps it is an operating system
function that is not exposed but available to Microsoft applications
only. I'm sure it is out there somewhere.

Anyhow, you would seem to have two choices.

1) Use the HTML Editor on my site and forget about the RTF control.

2) Use the HTML Editor and the RTF control. If you place the MS Web
Browser control on a form you can programmatically issue the OLE
Method(Action prop = 4) to copy the contents of the control to the
Clipboard. YOu can then programmatically set focus to the RTF control
and issue a Paste command and vice versa. If you do not want to place
the Web Browser control ona form you could instantiate an instance of
Internet Explore and use it instead.

Let me know how you make out.
--

HTH
Stephen Lebans
http://www.lebans.com
Access Code, Tips and Tricks
Please respond only to the newsgroups so everyone can benefit.

Hi Stephen don't warry, i redo the post also for all NG, you are very
polite.
So about it i learn some also on my week end.

I try tu use your HTML editor, but i can use it to WRITE....?
I don't know why don't accept CR(Return Key)...?

I can write only on just writed lines, i can Format in any way but no add
lines...?

So:

When i get form MIME message my Text i get it in two way:
1)TextOnly
2)Html
The users can chois in wich kind show it.

Using WeBrowser ctl to show it's very easy, i put directly HTML String on
WebBrowser
using your DEMO.

Now also TextPlain i can put on ctl.

If i can use the WebBrowser also to Write in i think THIS is the easiest
solution.

(On web i find also a RTF--->HTML parsing Code, but i don't like much use a
so
complicated solution)

What do you think about...?

Thanks again.

Alessandro
Nov 13 '05 #3

P: n/a
The inability to directly use the Enter key is an Access ActiveX host
issue. You can use Ctl + Enter. I have not tried this but perhaps you
could capture the Enter key and then use SendKeys to do a Ctl + Enter.

I agree, the WebBrowser control is the way to go.
:-)
--

HTH
Stephen Lebans
http://www.lebans.com
Access Code, Tips and Tricks
Please respond only to the newsgroups so everyone can benefit.
"ALESSANDRO Baraldi" <ik****@libero.it> wrote in message
news:co**********@lacerta.tiscalinet.it...
"Stephen Lebans" <Fo****************************************@linval id.com> ha scritto nel messaggio
news:85**********************@ursa-nb00s0.nbnet.nb.ca...
Sorry for not getting back to you Alessandro. I actually spent a few
hours on this issue late sunday night and was tied all of today on
business.

First the CF_HTML clipboard format requires a header.
Here is a sample.

Version:1.0
StartHTML:000000174
EndHTML:000000886
StartFragment:000000610
EndFragment:000000725
StartSelection:000000650
EndSelection:000000725
SourceURL:about:blank
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

<HTML><HEAD></HEAD>

<BODY>
<FONT face=Arial>
<FONT size=7>
<FONT style="BACKGROUND-COLOR: #000000" color=#ffffff>
<FONT size=1>
<FONT size=1>
<FONT style="BACKGROUND-COLOR: #ffffff">
<FONT color=#000000>
<STRONG>
<FONT face=Arial>
<FONT size=7>
<FONT style="BACKGROUND-COLOR: #000000" color=#ffffff>
<FONT size=1>
<FONT size=1>

<P><!--StartFragment--><FONT style="BACKGROUND-COLOR: #ffffff"><FONT
color=#0000ff>This is bold and <EM>this is
italic.</EM></FONT></FONT><!--EndFragment--></P>
</FONT>
</FONT>
</FONT>
</FONT>
</FONT>
</STRONG>
</FONT>
</FONT>
</FONT>
</FONT>
</FONT>
</FONT>
</FONT>
</BODY>
</HTML>

A doc detailing the header is here but it is for the older .9 version. http://msdn.microsoft.com/library/de.../en-us/winui/w inui/windowsuserinterface/dataexchange/clipboard/htmlclipboardformat.asp
VB Source code for creating the header is here:
http://support.microsoft.com/default...b;en-us;274326

Now as you have discovered you can manually cut and paste from Internet Explorer to the RTF control. But if you programmatically build the
identical CF_HTML string you can place it on the Clipboard but you
cannot paste it into the RTF control. It would seem the application(IE) originating the HTML is resonsible for generating the RTF string. The Clipboard object cannot directly generate RTF from HTML. It asks the
originating appllication that places the HTML on the Clipboard to
generate the RTF string.

I swear that I have read in the bowels of the MSDN OLE documentation
that the Clipboard object can convert from HTML to RTF independant of the application that places the HTML on the Clipboard. I have searched but cannot find the reference. Perhaps it is an operating system
function that is not exposed but available to Microsoft applications
only. I'm sure it is out there somewhere.

Anyhow, you would seem to have two choices.

1) Use the HTML Editor on my site and forget about the RTF control.

2) Use the HTML Editor and the RTF control. If you place the MS Web
Browser control on a form you can programmatically issue the OLE
Method(Action prop = 4) to copy the contents of the control to the
Clipboard. YOu can then programmatically set focus to the RTF control and issue a Paste command and vice versa. If you do not want to place the Web Browser control ona form you could instantiate an instance of Internet Explore and use it instead.

Let me know how you make out.
--

HTH
Stephen Lebans
http://www.lebans.com
Access Code, Tips and Tricks
Please respond only to the newsgroups so everyone can benefit.

Hi Stephen don't warry, i redo the post also for all NG, you are very
polite.
So about it i learn some also on my week end.

I try tu use your HTML editor, but i can use it to WRITE....?
I don't know why don't accept CR(Return Key)...?

I can write only on just writed lines, i can Format in any way but no

add lines...?

So:

When i get form MIME message my Text i get it in two way:
1)TextOnly
2)Html
The users can chois in wich kind show it.

Using WeBrowser ctl to show it's very easy, i put directly HTML String on WebBrowser
using your DEMO.

Now also TextPlain i can put on ctl.

If i can use the WebBrowser also to Write in i think THIS is the easiest solution.

(On web i find also a RTF--->HTML parsing Code, but i don't like much use a so
complicated solution)

What do you think about...?

Thanks again.

Alessandro


Nov 13 '05 #4

P: n/a
"Stephen Lebans" <Fo****************************************@linval id.com>
ha scritto nel messaggio
news:OR**********************@ursa-nb00s0.nbnet.nb.ca...
The inability to directly use the Enter key is an Access ActiveX host
issue. You can use Ctl + Enter. I have not tried this but perhaps you
could capture the Enter key and then use SendKeys to do a Ctl + Enter.

I agree, the WebBrowser control is the way to go.
:-)
--

HTH
Stephen Lebans
http://www.lebans.com
Access Code, Tips and Tricks
Please respond only to the newsgroups so everyone can benefit.

Good Evening Stephen.
When i talk you about EnterKey was due to test also your Code
on "A2KSHTMLver17" the HTML Editor.

I see that you implement on Form_KeyDown the Return Key.

The problem was that work only if i put a BreakPoint on Event.

This is a STRANGE thing, very strange....!

So if i try to use KeyDown(ReturnKey) don't work, if i put a breakPoint
on Code before "Call SendEnterKey(Me.hWnd)" when i return on FormView
is Perfect....!!!!!

With a SendKeys ("^{ENTER}"), true absolutly negative solution for
the STACK Memory Space....!!!

I'm going likely mad...?
Or is my PC...?

;-)

--
@Alex (Alessandro Baraldi)
---------------------------------------------------------------------------
http://www.sitocomune.com/
http://www.mantuanet.it/alessandro.baraldi/
---------------------------------------------------------------------------
Nov 13 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.