HTML Editor

Ollie
Posts: 233
Joined: Sat Dec 30, 2006 6:10 am

HTML Editor

Post by Ollie »

I want the user to setup an email template (using basic Bold, Underline, Colour functions, even imbed pics as a "nice to have") so that I can merge it with data from the database.

My thinking is that the email template will look like this:

Dear <<firstname>>

You have <<qty>> items on back order. These items will be ready on <<date>>.

Which when 'filled in' becomes:

Dear Johnny

You have 8 items on back order. These items will be ready on 2007/05/05.

Where I am stuck is giving the user a basic, easy HTML editor. Does anyone know of something I can use? I don't want to have to write an HTML editor - (I don't think I could anyway), but I feel its 'reinventing the wheel'.

All comments / advice appreciated.
Many thanks
Ollie.

Using:
xHarbour Compiler build 1.2.1 (SimpLex) (Rev. 6406)
Borland C++ 5.5.1
FWH 9.04 (2009 Apr)
User avatar
NK
Posts: 97
Joined: Sun Nov 20, 2005 4:32 pm
Location: Germany
Contact:

Re: HTML Editor

Post by NK »

Ollie wrote:I want the user to setup an email template (using basic Bold, Underline, Colour functions, even imbed pics as a "nice to have") so that I can merge it with data from the database.

My thinking is that the email template will look like this:

Dear <<firstname>>

You have <<qty>> items on back order. These items will be ready on <<date>>.

Which when 'filled in' becomes:

Dear Johnny

You have 8 items on back order. These items will be ready on 2007/05/05.

Where I am stuck is giving the user a basic, easy HTML editor. Does anyone know of something I can use? I don't want to have to write an HTML editor - (I don't think I could anyway), but I feel its 'reinventing the wheel'.

All comments / advice appreciated.
Dear Johnny,

you can write your mails with RTF and with IRUN.DLL convert to html.
1. Download irun.dll from http://www.pilotltd.com/
2. regsvr32 irun.dll /s
3. Insert this function to sour source:

DLL32 FUNCTION EXRTF2WEB( cSource AS LPSTR, ;
cDest AS LPSTR, ;
nOption AS LONG, ;
cBG AS LPSTR, ;
cTitel AS LPSTR, ;
nDPI AS LONG ) AS LONG ;
PASCAL FROM "EXRTF2WEB" LIB "IRUN.DLL"

4. Write your mail in rtf with TRichEdit() and save it to an file.
5. Convert your Mailtext from rtf to html with:
cRTFfile := "Test.rtf" // Sample
cHTMfile := "Test.htm" // Sample
EXRTF2WEB( cRTFfile, cHTMfile, 16, "FFFFFF", "Title", 72 )

it works fine and converts all fonts, bolds, understikes .....

Regards, Norbert
Ollie
Posts: 233
Joined: Sat Dec 30, 2006 6:10 am

Post by Ollie »

Sounds promising, thanks. Would it also handle imbedded pics?
Many thanks
Ollie.

Using:
xHarbour Compiler build 1.2.1 (SimpLex) (Rev. 6406)
Borland C++ 5.5.1
FWH 9.04 (2009 Apr)
User avatar
danielr cyberia®
Posts: 28
Joined: Sat Apr 28, 2007 4:06 am
Location: Venezuela

Post by danielr cyberia® »

nk, hi how are you

it's wonderfull this solutions, but i have a problem with the image resource, because the images save to wmf -windows meta file - and the html don't support this ext. i can get gif image when i change a value but don't looking well.

anybody had trying this///

i wish to use this dll or another one but with this result.

thanks a lot

daniel rivas
Best Regards- Saludos y Exitos

Daniel Rivas
User avatar
NK
Posts: 97
Joined: Sun Nov 20, 2005 4:32 pm
Location: Germany
Contact:

Post by NK »

danielr cyberia® wrote:nk, hi how are you

it's wonderfull this solutions, but i have a problem with the image resource, because the images save to wmf -windows meta file - and the html don't support this ext. i can get gif image when i change a value but don't looking well.
Please look at the new Version 1.20 on http://www.pilotltd.com/irun/index.html
IRun can generate GIF images for WMF or EMF type of images or can leave the original image depending on your selections. You can change the generated image size by determining the DPI setting for the conversion process.
Regards, Norbert
Romeo
Posts: 328
Joined: Thu Jan 25, 2007 3:53 pm
Location: Milan (Italy)

Re: HTML Editor

Post by Romeo »

hi,
CAN YOU HELP ME TO GET DPI from a generic bmp files ?
tks
Romeo
User avatar
Otto
Posts: 4470
Joined: Fri Oct 07, 2005 7:07 pm
Contact:

Re: HTML Editor

Post by Otto »

I use the mail merge function of MS WORD (Office) for this task.
Best regards,
Otto
********************************************************************
mod harbour - Vamos a la conquista de la Web
modharbour.org

********************************************************************
User avatar
Antonio Linares
Site Admin
Posts: 37481
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Contact:

Re: HTML Editor

Post by Antonio Linares »

Otto,

Would you be so kind to post an example ? thanks :-)
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Otto
Posts: 4470
Joined: Fri Oct 07, 2005 7:07 pm
Contact:

Re: HTML Editor

Post by Otto »

There is not much programming necessary in FIVEWIN .

1) I create a mail merge recipients file which is a ASCII file.

Code: Select all

dateineu := fcreate( cAppPath + "TempWord\recipients.txt",0)

This file has a header line where all the merge fields are stored and then as many data lines as recipients are.

Code: Select all

hStrg:=  'EMAIL;ANREDE;NAME;VORNAME;ZUSATZ;STRASSE;LKZ;PLZ;ORT;BRIEFANRED;TITEL;FIRMA1;FIRMA2'
The merge fields and data fields are separated by a delimiter.

2) insert data and I check that there is no delimiter inside the data.

Code: Select all

do while .not. eof()

hStrg:= ;
(STRTRAN(ALLTRIM(kunden->email   ),     ";","," ))+";"+;   
(STRTRAN(ALLTRIM(kunden->ANREDE  ),     ";","," ))+";"+;   
(STRTRAN(ALLTRIM(kunden->NAME    ),     ";","," ))+";"+;   
(STRTRAN(ALLTRIM(kunden->VORNAME    ),     ";","," ))+";"+;   
(STRTRAN(ALLTRIM(kunden->ZUSATZ     ),     ";","," ))+";"+;   
(STRTRAN(ALLTRIM(kunden->STRASSE    ),     ";","," ))+";"+;   
(STRTRAN(ALLTRIM(kunden->LKZ    ),     ";","," ))+";"+;   
(STRTRAN(ALLTRIM(kunden->PLZ    ),     ";","," ))+";"+;   
(STRTRAN(ALLTRIM(kunden->ORT     ),     ";","," ))+";"+;   
(STRTRAN(ALLTRIM(kunden->BRIEFAN    ),     ";","," ))+";"+;   
(STRTRAN(ALLTRIM(kunden->TITEL  ),     ";","," ))+";"+;   
(STRTRAN(ALLTRIM(kunden->FIRMA1  ),     ";","," ))+";"+;   
(STRTRAN(ALLTRIM(kunden->FIRMA2 ),     ";","," ))         
      

FSEEK(dateineu,0,2)
lStatus:=FWRITE(dateineu,hStrg+CRLF,)


skip
enddo      
3) I start word and open the selected mail merge letter.

Code: Select all

WinExec(PathWinword + "winword.exe" + " " + cDOCFile  )
4) Then complete it in word.


Note If you're creating merged e-mail messages or faxes, make sure that your data file includes a column for the e-mail address or fax number. You will need that column later in the process.


Best regards,
Otto
********************************************************************
mod harbour - Vamos a la conquista de la Web
modharbour.org

********************************************************************
User avatar
anserkk
Posts: 1280
Joined: Fri Jun 13, 2008 11:04 am
Location: Kochi, India

Re: HTML Editor

Post by anserkk »

Ollie wrote:Where I am stuck is giving the user a basic, easy HTML editor. Does anyone know of something I can use? I don't want to have to write an HTML editor - (I don't think I could anyway), but I feel its 'reinventing the wheel'.
NK wrote:you can write your mails with RTF and with IRUN.DLL convert to html.
1. Download irun.dll from http://www.pilotltd.com/
2. regsvr32 irun.dll /s
3. Insert this function to sour source:
You can avoid using third party external DLL to convert .RTF to .Html file. This can be done using the following code

Code: Select all

#Include "FiveWin.ch"

// Word HTML format constant, used to save Rtf as Html
#DEFINE wdFormatHTML 8  
#DEFINE wdFormatFilteredHTML 10

*-------------------------------------*
Function Main()
*-------------------------------------*
Local cRtfFile,cHtmlFile
cRtfFile:="D:\Test\MyRtfFile.Rtf"
cHtmlFile:="D:\Test\MyHtmlFile"

Rtf2Html(cRtfFile,cHtmlFile)

RETURN NIL

*-------------------------------------*
Function Rtf2Html(cRtfFile,cHtmlFile)
*-------------------------------------*
Local oWordApp,oWordDoc,oError 

TRY
    oWordApp := CreateObject("Word.Application")
CATCH
    MsgInfo("MS-Word is not installed in your PC")
    Return NIL
END

//Open the RTF document
TRY
    oWordDoc:=oWordApp:Documents:Open(cRtfFile)
CATCH oError
    MsgInfo("Error. Unable to Open the File"+CRLF+oError:Description)
    oWordApp:Quit()
    Return NIL
END
 
//Save the document in HTML format
oWordDoc:SaveAs (cHtmlFile, wdFormatFilteredHTML)
 
//Free memory & resources by closing objects
oWordDoc:Close()
oWordApp:Quit()

Return NIL
If Word is not installed in your PC then the above said solution will not serve the purpose. In that case, sample VB codes are available which we can easily transfer/convert to FiveWin code and this code can be used to directly convert Rtf to Html within FiveWin itself without using any third party DLL. I hope that in future this feature will be inbuilt in the TRichEdit CLASS, so that we can have oRichEdit:Convert2Html("Html-FileName"). This will be useful for people who wish to provide customized Emailing solutions and can use RichEdit Class to format the mail draft and convert to Html and send mails.

Regards
Anser
User avatar
nageswaragunupudi
Posts: 8017
Joined: Sun Nov 19, 2006 5:22 am
Location: India
Contact:

Re: HTML Editor

Post by nageswaragunupudi »

Mr Anser
sample VB codes are available which we can easily transfer/convert to FiveWin code and this code can be used to directly convert Rtf to Html within FiveWin itself without using any third party DLL.
Can you post any such working VB code here? We can convert to FiveWin code.

Have you found any code to print RTF directly without opening in a visual control first?
Regards

G. N. Rao.
Hyderabad, India
User avatar
anserkk
Posts: 1280
Joined: Fri Jun 13, 2008 11:04 am
Location: Kochi, India

Re: HTML Editor

Post by anserkk »

Dear Mr.Rao,
Mr.Rao wrote:Have you found any code to print RTF directly without opening in a visual control first?
Not yet.
Mr.Rao wrote:Can you post any such working VB code here? We can convert to FiveWin code.
Here is the VB code which I have found on the web. I have not tested it.

Unable to paste the entire code here as it exceeds the maximum allowed characters 60,000. Please download it from the below given link
http://www2.bitstream.net/~bradyh/downl ... tmlrm.html

Regards
Anser
User avatar
anserkk
Posts: 1280
Joined: Fri Jun 13, 2008 11:04 am
Location: Kochi, India

Re: HTML Editor

Post by anserkk »

Dear Mr.Rao,
Mr.Rao wrote:Have you found any code to print RTF directly without opening in a visual control first?
As per MicroSoft site

This step-by-step article describes how to print the content of a RichTextBox control. The RichTextBox control does not provide any method to print the content of the RichTextBox. You can extend the RichTextBox class to use EM_FORMATRANGE message to send the content of a RichTextBox control to an output device such as printer.

http://support.microsoft.com/default.as ... -us;812425

Here is another code which I have come across. You may get some hint on how to proceed further. It seems that this VB Code is making use of EM_FORMATRANGE as suggested by Microsoft.

This function allows you to set margins when printing the contents of a rich text box. The margin parameters are set in inches.

Declarations

Code: Select all

Option Explicit

Private Type Rect
   Left As Long
   Top As Long
   Right As Long
   Bottom As Long
End Type

Private Type CHARRANGE
  cpMin As Long
  cpMax As Long
End Type

Private Type FORMATRANGE
  hdc As Long
  hdcTarget As Long
  rc As Rect
  rcPage As Rect
  chrg As CHARRANGE
End Type

Private Const WM_USER As Long = &H400
Private Const EM_FORMATRANGE As Long = WM_USER + 57
Private Const EM_SETTARGETDEVICE As Long = WM_USER + 72
Private Const PHYSICALOFFSETX As Long = 112
Private Const PHYSICALOFFSETY As Long = 113

Private Declare Function GetDeviceCaps Lib "gdi32" _ 
   (ByVal hdc As Long, ByVal nIndex As Long) As Long
   
Private Declare Function SendMessage Lib "USER32" _
  Alias "SendMessageA" (ByVal hWnd As Long, ByVal msg As Long, _
  ByVal wp As Long, lp As Any) As Long
Code :

Code: Select all

Public Function PrintRTFWithMargins(RTFControl As Object, _
   ByVal LeftMargin As Single, ByVal TopMargin As Single, _
   ByVal RightMargin As Single, ByVal BottomMargin As Single) _
   As Boolean
   
'********************************************************8
'PURPOSE: Prints Contents of RTF Control with Margins

'PARAMETERS:
    'RTFControl: RichTextBox Control For Printing
    'LeftMargin: Left Margin in Inches
    'TopMargin: TopMargin in Inches
    'RightMargin: RightMargin in Inches
    'BottomMargin: BottomMargin in Inches

'***************************************************************

On Error GoTo ErrorHandler


'*************************************************************
'I DO THIS BECAUSE IT IS MY UNDERSTANDING THAT
'WHEN CALLING A SERVER DLL, YOU CAN RUN INTO
'PROBLEMS WHEN USING EARLY BINDING WHEN A PARAMETER
'IS A CONTROL OR A CUSTOM OBJECT.  IF YOU JUST PLUG THIS INTO
'A FORM, YOU CAN DECLARE RTFCONTROL AS RICHTEXTBOX
'AND COMMENT OUT THE FOLLOWING LINE

If Not TypeOf RTFControl Is RichTextBox Then Exit Function
'**************************************************************
   
   Dim lngLeftOffset As Long
   Dim lngTopOffSet As Long
   Dim lngLeftMargin As Long
   Dim lngTopMargin As Long
   Dim lngRightMargin As Long
   Dim lngBottomMargin As Long
   
   Dim typFr As FORMATRANGE
   Dim rectPrintTarget As Rect
   Dim rectPage As Rect
   Dim lngTxtLen As Long
   Dim lngPos As Long
   Dim lngRet As Long
   Dim iTempScaleMode As Integer
   
   iTempScaleMode = Printer.ScaleMode
   
   ' needed to get a Printer.hDC
   Printer.Print ""
   Printer.ScaleMode = vbTwips

   ' Get the offsets to printable area in twips
   lngLeftOffset = Printer.ScaleX(GetDeviceCaps(Printer.hdc, _
      PHYSICALOFFSETX), vbPixels, vbTwips)
   lngTopOffSet = Printer.ScaleY(GetDeviceCaps(Printer.hdc, _
      PHYSICALOFFSETY), vbPixels, vbTwips)

   ' Get Margins in Twips
   lngLeftMargin = InchesToTwips(LeftMargin) - lngLeftOffset
   lngTopMargin = InchesToTwips(TopMargin) - lngTopOffSet
   lngRightMargin = (Printer.Width - _
       InchesToTwips(RightMargin)) - lngLeftOffset
   
    lngBottomMargin = (Printer.Height - _
         InchesToTwips(BottomMargin)) - lngTopOffSet

   ' Set printable area rect
   rectPage.Left = 0
   rectPage.Top = 0
   rectPage.Right = Printer.ScaleWidth
   rectPage.Bottom = Printer.ScaleHeight

   ' Set rect in which to print, based on margins passed in
   rectPrintTarget.Left = lngLeftMargin
   rectPrintTarget.Top = lngTopMargin
   rectPrintTarget.Right = lngRightMargin
   rectPrintTarget.Bottom = lngBottomMargin

   ' Set up the printer for this print job
   typFr.hdc = Printer.hdc 'for rendering
   typFr.hdcTarget = Printer.hdc 'for formatting
   typFr.rc = rectPrintTarget
   typFr.rcPage = rectPage
   typFr.chrg.cpMin = 0
   typFr.chrg.cpMax = -1

   ' Get length of text in the RichTextBox Control
   lngTxtLen = Len(RTFControl.Text)

   ' print page by page
   Do
      ' Print the page by sending EM_FORMATRANGE message
      'Allows you to range of text within a specific device
      'here, the device is the printer, which must be specified
      'as hdc and hdcTarget of the FORMATRANGE structure
      
      lngPos = SendMessage(RTFControl.hWnd, EM_FORMATRANGE, _
        True, typFr)
  
       If lngPos >= lngTxtLen Then Exit Do  'Done
       typFr.chrg.cpMin = lngPos ' Starting position next page
      Printer.NewPage             ' go to next page
      Printer.Print ""   'to get hDC again
      typFr.hdc = Printer.hdc
      typFr.hdcTarget = Printer.hdc
   Loop

   ' Done
   Printer.EndDoc

   ' This frees memory
   lngRet = SendMessage(RTFControl.hWnd, EM_FORMATRANGE, _
     False, Null)
   Printer.ScaleMode = iTempScaleMode
   PrintRTFWithMargins = True
   Exit Function
   
ErrorHandler:
   Err.Raise Err.Number, , Err.Description
   
End Function

Private Function InchesToTwips(ByVal Inches As Single) As Single
    InchesToTwips = 1440 * Inches
End Function
Regards
Anser
User avatar
nageswaragunupudi
Posts: 8017
Joined: Sun Nov 19, 2006 5:22 am
Location: India
Contact:

Re: HTML Editor

Post by nageswaragunupudi »

Mr Anser

Thanks for all the trouble you have taken at my request.

Once we open an RTF document in a control, FWH RichEdit control also allows us to print.

What I have been looking is whether we can print RTF without opening in a VISUAL control first.

My purpose is this: I have a table with some columns containing RTF data. Can I show RTF in xbrowse, like multiline memo, without opening a control in that cell and whether i can print the formatted content in a cell using Report.

I shall go through the code you posted and link you provided.

Thanks again
Regards

G. N. Rao.
Hyderabad, India
StefanHaupt
Posts: 824
Joined: Thu Oct 13, 2005 7:39 am
Location: Germany

Re: HTML Editor

Post by StefanHaupt »

Nages,

there is also a "Windowless Richtedit Control", which may solve your problem.

http://msdn.microsoft.com/en-us/library ... 85%29.aspx
kind regards
Stefan
Post Reply