Author Topic: HTML to RTF  (Read 78287 times)

guga

  • Moderator
  • Member
  • *****
  • Posts: 1451
  • Assembly is a state of art.
    • RosAsm
HTML to RTF
« on: June 08, 2013, 01:56:26 PM »
Can someone help me converting this code to assembly ?

Code: [Select]
VERSION 5.00
Object = "{3B7C8863-D78F-101B-B9B5-04021C009402}#1.2#0"; "Richtx32.ocx"
Begin VB.Form Form1
   Caption         =   "Rtf2Html"
   ClientHeight    =   8670
   ClientLeft      =   60
   ClientTop       =   345
   ClientWidth     =   13815
   LinkTopic       =   "Form1"
   ScaleHeight     =   8670
   ScaleWidth      =   13815
   StartUpPosition =   3  'Windows Default
   Begin VB.CommandButton Command2
      Caption         =   "Convertir HTML to RTF"
      BeginProperty Font
         Name            =   "Tahoma"
         Size            =   9
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   405
      Left            =   7515
      TabIndex        =   4
      Top             =   3660
      Width           =   5265
   End
   Begin VB.PictureBox picNet
      Height          =   3960
      Left            =   180
      ScaleHeight     =   3900
      ScaleWidth      =   6180
      TabIndex        =   3
      Top             =   4500
      Width           =   6240
   End
   Begin RichTextLib.RichTextBox RichTextBox1
      Height          =   2865
      Left            =   180
      TabIndex        =   2
      Top             =   1050
      Width           =   6270
      _ExtentX        =   11060
      _ExtentY        =   5054
      _Version        =   393217
      ScrollBars      =   3
      RightMargin     =   6270
      AutoVerbMenu    =   -1  'True
      FileName        =   "C:\Program Files\Microsoft Visual Studio\VB98\Rich2Html\EXEMPLE1.rtf"
      TextRTF         =   $"RTF 2 HTML 2 RTF.frx":0000
   End
   Begin VB.TextBox Text1
      Height          =   2985
      Left            =   6930
      MultiLine       =   -1  'True
      ScrollBars      =   2  'Vertical
      TabIndex        =   1
      Text            =   "RTF 2 HTML 2 RTF.frx":05D9
      Top             =   375
      Width           =   6405
   End
   Begin VB.CommandButton Command1
      Caption         =   "Convertir RTF to HTML"
      BeginProperty Font
         Name            =   "Tahoma"
         Size            =   9
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   405
      Left            =   180
      TabIndex        =   0
      Top             =   195
      Width           =   5550
   End
   Begin RichTextLib.RichTextBox RichTextBox2
      Height          =   4050
      Left            =   7125
      TabIndex        =   8
      Top             =   4485
      Width           =   6270
      _ExtentX        =   11060
      _ExtentY        =   7144
      _Version        =   393217
      ScrollBars      =   3
      RightMargin     =   6270
      AutoVerbMenu    =   -1  'True
      TextRTF         =   $"RTF 2 HTML 2 RTF.frx":05DF
   End
   Begin VB.Label Label5
      Caption         =   "--->"
      BeginProperty Font
         Name            =   "MS Sans Serif"
         Size            =   13.5
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   375
      Left            =   6510
      TabIndex        =   10
      Top             =   5790
      Width           =   510
   End
   Begin VB.Label Label4
      Caption         =   "Ceci est un un autre RichTextbox qui reçoi  le contenu du WebBrowser"
      Height          =   270
      Left            =   7125
      TabIndex        =   9
      Top             =   4155
      Width           =   5685
   End
   Begin VB.Label Label3
      Caption         =   "Ceci est la source HTML produite"
      Height          =   270
      Left            =   6930
      TabIndex        =   7
      Top             =   120
      Width           =   5685
   End
   Begin VB.Label Label2
      Caption         =   "Ceci est un replacement du contrôle WebBrowser de VB (éditable aussi):"
      Height          =   270
      Left            =   180
      TabIndex        =   6
      Top             =   4215
      Width           =   5685
   End
   Begin VB.Label Label1
      Caption         =   "Ceci est un RichTextbox qu'on peut éditer:"
      Height          =   270
      Left            =   180
      TabIndex        =   5
      Top             =   780
      Width           =   5685
   End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
' But: ce petit programme converte du texte Rtf en code Html et vice-versa
' Auteur: vicosta (http://www.vbfrance.com)
' Notes: La gestion du clipboard n'est pas prise en charge
'        Il faut encore du code supplémentaire afin d'obtenir plus de précision

Dim WithEvents WebB As VBControlExtender
Attribute WebB.VB_VarHelpID = -1
Private Declare Sub keybd_event Lib "user32" (ByVal bVk As Byte, ByVal bScan As Byte, ByVal dwFlags&, ByVal dwExtraInfo&)

Private Sub Form_Load()
Set WebB = GetMyBrowser(picNet)
End Sub

Private Sub Command1_Click() 'Convertir RTF to HTML
    Const OLECMDEXECOPT_DODEFAULT = 0
    Const OLECMDID_SELECTALL = 17
    Const OLECMDID_PASTE = 13
RichTextBox1.SetFocus
'SendKeys "^a^c" ' ne fonctionne pas en mode IDE, alors
SSendkeys vbKeyA, True 'sélectionner et ...
SSendkeys vbKeyC, True 'copier tout
RichTextBox1.SelLength = 0
With WebB.object
    .Document.DesignMode = "On"
    .ExecWB OLECMDID_SELECTALL, OLECMDEXECOPT_DODEFAULT
     DoEvents
    .ExecWB OLECMDID_PASTE, OLECMDEXECOPT_DODEFAULT
     DoEvents
     Text1 = .Document.body.innerHTML
'    .Document.DesignMode = "Off"
End With
End Sub

Private Sub Command2_Click() 'Convertir HTML to RTF
    Const OLECMDEXECOPT_DODEFAULT = 0
    Const OLECMDID_SELECTALL = 17
    Const OLECMDID_COPY = 12
    Const OLECMDID_CLEARSELECTION = 18
With WebB.object
    .ExecWB OLECMDID_SELECTALL, OLECMDEXECOPT_DODEFAULT
     DoEvents
    .ExecWB OLECMDID_COPY, OLECMDEXECOPT_DODEFAULT
    .ExecWB OLECMDID_CLEARSELECTION, OLECMDEXECOPT_DODEFAULT
End With
RichTextBox2.SetFocus
SSendkeys vbKeyA, True 'sélectionner tout et ...
SSendkeys vbKeyV, True 'remplacer par le contenu du ClipBoard
End Sub

' petite fonction pour ne pas rajouter le contrôle WebBrowser dans ce project
'
Function GetMyBrowser(objContainer As PictureBox, Optional Url As String = "about:blank") As VBControlExtender
'On Error GoTo IEMissing
Set GetMyBrowser = objContainer.Parent.Controls.Add("Shell.Explorer", "wcIE" & Int(Timer), objContainer)
With GetMyBrowser
    .object.Navigate2 Url '  , 14&
    .Move 0, 0, objContainer.ScaleWidth, objContainer.ScaleHeight
    .Visible = True
    .object.Silent = True
End With
Exit Function
IEMissing:
MsgBox Err.Description
End Function

' la fonction vb Sendkeys provoque erreur en mode IDE, alors on la remplace par SSendkeys
'
Sub SSendkeys(Key As KeyCodeConstants, Optional Ctrl As Boolean, Optional Shift As Boolean)
Const KEYEVENTF_EXTENDEDKEY = &H1
Const KEYEVENTF_KEYUP = &H2
If Ctrl Then keybd_event vbKeyControl, 0, 0, 0
If Shift Then keybd_event vbKeyShift, 0, 0, 0
DoEvents
keybd_event Key, 0, 0, 0
DoEvents
keybd_event Key, 0, KEYEVENTF_KEYUP, 0
DoEvents
If Ctrl Then keybd_event vbKeyControl, 0, KEYEVENTF_KEYUP, 0
If Shift Then keybd_event vbKeyShift, 0, KEYEVENTF_KEYUP, 0
DoEvents
End Sub

thanks in advance
Coding in Assembly requires a mix of:
80% of brain, passion, intuition, creativity
10% of programming skills
10% of alcoholic levels in your blood.

My Code Sites:
http://rosasm.freeforums.org
http://winasm.tripod.com

TouEnMasm

  • Member
  • *****
  • Posts: 1762
    • EditMasm
Re: HTML to RTF
« Reply #1 on: June 08, 2013, 04:01:37 PM »

Seem to be just a dialog box.
create it with resed (ketilo) giving it the same controls and same sizes (same look)  and it's done.
The CreateDialogParam fonction is used to show the dialog.
You need also a waiting loop.
code for dialog box is as follow:
Code: [Select]
invoke mybox
mybox PROTO
Dlgmybox   PROTO  :DWORD,:DWORD,:DWORD,:DWORD
;################################################################
mybox  PROC
local valeurinitialisation :DWORD
jmp overtxt
zzzzmybox db "IDD_MYBOX",0 ;enlever le #define IDD_MYBOX.. dans la ressource
overtxt:
mov eax,NULL
mov valeurinitialisation,eax
invoke CreateDialogParam,Hinst, addr zzzzmybox,Hwnd,OFFSET Dlgmybox,valeurinitialisation
; invoke DialogBoxParam,Hinst, addr zzzzmybox,Hwnd,OFFSET Dlgmybox,valeurinitialisation

Findemybox:
ret
mybox endp

;################################################################

Dlgmybox  PROC uses esi edi ebx HdialBox:DWORD,uMsg:DWORD,wParam:DWORD, lParam:DWORD
Local HListBox1:DWORD
Local phrase[MAX_PATH]:BYTE

; gere les evenements
.if     uMsg == WM_INITDIALOG
return TRUE ;windows attribue le focus
;return FALSE ; la boite a defini le focus
.elseif uMsg == WM_CLOSE
invoke PostMessage,HdialBox,WM_DESTROY,NULL,NULL
.elseif uMsg == WM_DESTROY
;invoke EndDialog,HdialBox,NULL ;DialogBoxParam
invoke DestroyWindow,HdialBox ;CreateDialogParam
;invoke PostQuitMessage,NULL ;stop loop messages
.elseif uMsg == WM_COMMAND
HIWORD wParam ;controls events
mov edx,eax
LOWORD wParam ;IDentificateurs de  commandes
mov ebx,lParam ; handle du controle
.if eax == 0 ;button id ....
.elseif eax == 1
.endif
.else
mov eax,FALSE
jmp FindeDlgmybox
.endif
mov  eax,TRUE
FindeDlgmybox:
ret
Dlgmybox endp

;#########################################################################
code for messages loop

Code: [Select]
;################################################################
Message_Loop PROC
local msg:MSG
@@:
INVOKE     GetMessage, addr msg, NULL, 0, 0
.if eax == 1         ;aucune erreur accepter
INVOKE     TranslateMessage, addr msg           ;prend le message
INVOKE     DispatchMessageA , addr msg          ;envoi les messages aux fenêtres
jmp @B
.endif
FindeMessage_Loop:
mov eax,msg.wParam
ret
Message_Loop endp

and then use it

Code: [Select]
  invoke mybox
 invoke Message_Loop



Fa is a musical note to play with CL

guga

  • Moderator
  • Member
  • *****
  • Posts: 1451
  • Assembly is a state of art.
    • RosAsm
Re: HTML to RTF
« Reply #2 on: June 08, 2013, 04:14:03 PM »
Hi ToutEnMasm

tks, but how to port the OLECMDEXECOPT_DODEFAULT (Com browsers for IID_IWebBrowser2) ?

It seems it used clsidWebBrowser2 to copy the contents of a html page and paste it as a full RTF file.
Coding in Assembly requires a mix of:
80% of brain, passion, intuition, creativity
10% of programming skills
10% of alcoholic levels in your blood.

My Code Sites:
http://rosasm.freeforums.org
http://winasm.tripod.com

guga

  • Moderator
  • Member
  • *****
  • Posts: 1451
  • Assembly is a state of art.
    • RosAsm
Re: HTML to RTF
« Reply #3 on: June 08, 2013, 04:41:43 PM »
OK, i´m quite finding it (i guess)

.ExecWB OLECMDID_SELECTALL, OLECMDEXECOPT_DODEFAULT seems to be equivalent to:

Code: [Select]

[OLECMDEXECOPT_DODEFAULT: D$ 0]
[IWEBBROWSER2_QUERYSTATUSWB 0D4]

iCall IWEBBROWSER2_QUERYSTATUSWB D$BrowserPointer, &OLECMDID_SELECTALL, OLECMDEXECOPT_DODEFAULT

Coding in Assembly requires a mix of:
80% of brain, passion, intuition, creativity
10% of programming skills
10% of alcoholic levels in your blood.

My Code Sites:
http://rosasm.freeforums.org
http://winasm.tripod.com

TouEnMasm

  • Member
  • *****
  • Posts: 1762
    • EditMasm
Re: HTML to RTF
« Reply #4 on: June 09, 2013, 03:05:24 AM »
The only valuable information i see in this source is that he use Richtx32.ocx.
Download it first.
Try to install it
Try to get is typelib, an idl file.
It can be a work to do that.

A good soluce,download a free one
HTMLtoRTF Converter Pro 3.0.0 (build October 27th, 2008).
Fa is a musical note to play with CL

jj2007

  • Member
  • *****
  • Posts: 13300
  • Assembly is fun ;-)
    • MasmBasic
Re: HTML to RTF
« Reply #5 on: June 09, 2013, 03:59:24 AM »
Hi Guga,

If you just want character formatting, then EM_GETCHARFORMAT with SCF_SELECTION is the way to go. I use it to export code snippets in TechniColorTM to this forum, but it's not a big deal to do the same in HTML.

guga

  • Moderator
  • Member
  • *****
  • Posts: 1451
  • Assembly is a state of art.
    • RosAsm
Re: HTML to RTF
« Reply #6 on: June 09, 2013, 04:42:43 AM »
Hi JJ

good idea, but this works mainly for copying from RTF to RTF. I was thinking on a way to copy the contents of a  html (I mean, what we see on the screen) and paste it as RTF without having to make a HTML parser for it.  I read on a  Forum that internally on the Ole com data there is a way  to  export html to rtf directly, but it seems to be undocumented.

On my previous thread, we can register a new clipboard format to get the html contents. On this way, it is possible to make a parser for it. But, the goal is not to use a parser at all, just let ole com do all the work.
Coding in Assembly requires a mix of:
80% of brain, passion, intuition, creativity
10% of programming skills
10% of alcoholic levels in your blood.

My Code Sites:
http://rosasm.freeforums.org
http://winasm.tripod.com

Dubby

  • Member
  • **
  • Posts: 60
Re: HTML to RTF
« Reply #7 on: June 09, 2013, 05:12:40 AM »
ahh.. finally I understand it partially.. I'm not a VB guy..

Ok so there are 2 "text boxes" which the first is the html box and the other is RTF box right?
and there are two button which convert RTF to HTML and vice versa... right...?

and I just found this MSDN page. I'm sure that it'll be useful:
http://msdn.microsoft.com/en-us/library/aa752127(v=vs.85).aspx

sorry I cannot go further,,,  :(

hope this helps...

jj2007

  • Member
  • *****
  • Posts: 13300
  • Assembly is fun ;-)
    • MasmBasic
Re: HTML to RTF
« Reply #8 on: June 09, 2013, 06:48:00 AM »
Check Converting between RTF and HTML, it looks promising smells of .not, unfortunately :icon_mrgreen:

But this works fine, provided you have MS Word:

include \masm32\MasmBasic\MasmBasic.inc        ; download

RtfClip$ MACRO MbLimit
  push rv(RegisterClipboardFormat, "Rich Text Format")
  push MbBufSize/4
  call MbClipP
  EXITM <MbC:>
ENDM

        Init
        MsgBox 0, cStyle$("Copy some formatted text\nfrom your browser,\nmake sure MS Word is running,\nthen click OK here"), "Html to RTF converter:", MB_OKCANCEL
        .if eax==IDOK
                SendWordCommands INIT        ; prepare a DDE session; MS Word must be running
                .if eax
                        SendWordCommands "[AppHide:ScreenUpdating 0:FileNewDefault:EditPaste:EditSelectAll:EditCopy:FileClose 2:AppMinimize]"
                        SendWordCommands EXIT        ; finish DDE session
                        Let esi=RtfClip$()
                        MsgBox 0, Left$(esi, 1000), "Does it look nice? Then paste it ...", MB_OK
                .else
                        MsgBox 0, "MS Word doesn't answer", "Sorry", MB_OK
                .endif
        .endif
        Exit
end start
« Last Edit: June 09, 2013, 08:17:23 AM by jj2007 »

guga

  • Moderator
  • Member
  • *****
  • Posts: 1451
  • Assembly is a state of art.
    • RosAsm
Re: HTML to RTF
« Reply #9 on: June 09, 2013, 08:26:42 AM »
great work JJ

buyt, i guess i found the starting point yo an automated HTML o RTF and vice-versa.

There is something called encapsulated html inside a rtf file.
http://msdn.microsoft.com/en-us/library/ee204432%28v=exchg.80%29.aspx

It seems to be completelly browser independent. I just found this and will see if this algorithm is already coded inside one of the OS dlls. I remember seeing this inside cdosys.dll, but i´m not sure yet.

« Last Edit: June 09, 2013, 09:33:18 AM by guga »
Coding in Assembly requires a mix of:
80% of brain, passion, intuition, creativity
10% of programming skills
10% of alcoholic levels in your blood.

My Code Sites:
http://rosasm.freeforums.org
http://winasm.tripod.com

guga

  • Moderator
  • Member
  • *****
  • Posts: 1451
  • Assembly is a state of art.
    • RosAsm
Re: HTML to RTF
« Reply #10 on: June 09, 2013, 08:57:05 AM »
Ok, i guess it is really cdosys.dll.

This file contains the code to encapsulate HTML to RTF and vice-versa. It was coded as a library, most probably belonging to outlook2003. There is a file called rtfhtml.dll from outlook2003 that is exactly a converter "Outlook RTF/HTML Converter". The problem is how to use this thing. Since i didn´t found any documentation for all of this yet, except the huge pdfs archives from M$

Also, here seems a valid information for converting back from RTF to HTMLand compressed RTF
http://ruby-msg.googlecode.com/svn/trunk/lib/mapi/rtf.rb
Coding in Assembly requires a mix of:
80% of brain, passion, intuition, creativity
10% of programming skills
10% of alcoholic levels in your blood.

My Code Sites:
http://rosasm.freeforums.org
http://winasm.tripod.com

TouEnMasm

  • Member
  • *****
  • Posts: 1762
    • EditMasm
Re: HTML to RTF
« Reply #11 on: June 09, 2013, 10:34:15 PM »

Have a look also on the clipbboard formats .I have an aplly who change html to rtf and rtf to html just changing the clipbaord format.
That seems to easy ...
Fa is a musical note to play with CL

jj2007

  • Member
  • *****
  • Posts: 13300
  • Assembly is fun ;-)
    • MasmBasic
Re: HTML to RTF
« Reply #12 on: June 09, 2013, 10:57:36 PM »

Have a look also on the clipbboard formats .I have an aplly who change html to rtf and rtf to html just changing the clipbaord format.
That seems to easy ...

Post it, please :t

TouEnMasm

  • Member
  • *****
  • Posts: 1762
    • EditMasm
Re: HTML to RTF
« Reply #13 on: June 09, 2013, 11:18:56 PM »
It's a c++ free code I find very well done.
Don't cry it's in french.
http://www.cppfrance.com//code.aspx?ID=54692
In case who you couldn't compile it,i post the executable.

I have posted also an richedit editor (source of mine) who use OLE to insert image in rtf.He accept also to do a little job with Html and can made a first step in the problem.
 
http://masm32.com/board/index.php?topic=646.msg5283#msg5283
Fa is a musical note to play with CL

jj2007

  • Member
  • *****
  • Posts: 13300
  • Assembly is fun ;-)
    • MasmBasic
Re: HTML to RTF
« Reply #14 on: June 09, 2013, 11:45:22 PM »
In case who you couldn't compile it,i post the executable.

No conversion HTML to RTF here: