Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
RTF text
#1
How can I use a hiperlink or colour text in a Rich Edit Control?
#2
Read about rich edit controls in MSDN Library.

Colors:
Send EM_EXSETSEL message to select text, then EM_SETCHARFORMAT to apply formatting.

Links:
With EM_SETCHARFORMAT use CHARFORMAT2, and set CFE_LINK effect;
Process EN_LINK messages.
See also EM_SETEVENTMASK.
#3
Is possible to use RTF format in a STR variable and then to use ShowText?
#4
Save to a temporary file.

Do you know rtf syntax for links? I did not find it.
#5
Me too,

can you showme a little example of to use EM_SETCHARFORMAT, EN_LINK...?
#6
Function dlg_rich_text

Code:
Copy      Help
\Dialog_Editor
function# hDlg message wParam lParam
if(hDlg) goto messages

def EN_LINK 0x070b
def ENM_LINK 0x04000000
def CFM_COLOR 0x40000000
def CFM_LINK 0x20
def CFE_LINK 0x00000020
def SCF_SELECTION 1
type CHARFORMAT2 cbSize dwMask dwEffects yHeight yOffset crTextColor !bCharSet !bPitchAndFamily !szFaceName[LF_FACESIZE] @wWeight @sSpacing crBackColor lcid dwReserved @sStyle @wKerning !bUnderlineType !bAnimation !bRevAuthor !bReserved1
type ENLINK NMHDR'nmhdr msg wParam lParam CHARRANGE'chrg

str controls = "3"
str rea3
rea3="simple text red text link[]"
if(!ShowDialog("dlg_rich_text" &dlg_rich_text &controls)) ret

;BEGIN DIALOG
;0 "" 0x10C80A44 0x100 0 0 223 135 "Form"
;1 Button 0x54030001 0x4 120 116 48 14 "OK"
;2 Button 0x54030000 0x4 170 116 48 14 "Cancel"
;3 RichEdit20A 0x54233044 0x200 4 4 216 104 ""
;END DIALOG
;DIALOG EDITOR: "" 0x2010800 "*" ""


ret
;messages
sel message
,case WM_INITDIALOG
,DT_Init(hDlg lParam)
,
,int re=id(3 hDlg)
,CHARRANGE cr
,CHARFORMAT2 cf.cbSize=sizeof(CHARFORMAT2)
,;red text
,cr.cpMin=12
,cr.cpMax=20
,SendMessage(re EM_EXSETSEL 0 &cr)
,cf.dwMask=CFM_COLOR
,cf.crTextColor=0xff
,SendMessage(re EM_SETCHARFORMAT SCF_SELECTION &cf)
,;link
,cr.cpMin=21
,cr.cpMax=25
,SendMessage(re EM_EXSETSEL 0 &cr)
,cf.dwMask=CFM_LINK
,cf.dwEffects=CFE_LINK
,SendMessage(re EM_SETCHARFORMAT SCF_SELECTION &cf)
,;enable events
,SendMessage(re EM_SETEVENTMASK 0 ENM_LINK)
,;remove selection
,SendMessage(re EM_SETSEL 0 0)
,
,ret 1
,case WM_DESTROY DT_DeleteData(hDlg)
,case WM_COMMAND goto messages2
,case WM_NOTIFY goto messages3
ret
;messages2
sel wParam
,case IDOK DT_Ok hDlg
,case IDCANCEL DT_Cancel hDlg
ret 1
;messages3
NMHDR* n=+lParam
sel n.code
,case EN_LINK
,ENLINK* el=+n
,if(el.msg=WM_LBUTTONUP)
,,out "a link clicked at %i-%i" el.chrg.cpMin el.chrg.cpMax

Function dlg_rich_text2
Code:
Copy      Help
\Dialog_Editor
function# hDlg message wParam lParam
if(hDlg) goto messages

def EN_LINK 0x070b
def ENM_LINK 0x04000000
def EM_AUTOURLDETECT (WM_USER+91)
type ENLINK NMHDR'nmhdr msg wParam lParam CHARRANGE'chrg

str controls = "3"
str rea3
rea3="simple text[]http://www.quickmacros.com[]"
if(!ShowDialog("dlg_rich_text2" &dlg_rich_text2 &controls)) ret

;BEGIN DIALOG
;0 "" 0x10C80A44 0x100 0 0 223 135 "Form"
;1 Button 0x54030001 0x4 120 116 48 14 "OK"
;2 Button 0x54030000 0x4 170 116 48 14 "Cancel"
;3 RichEdit20A 0x54233044 0x200 4 4 216 104 ""
;END DIALOG
;DIALOG EDITOR: "" 0x2010800 "*" ""


ret
;messages
sel message
,case WM_INITDIALOG
,
,int re=id(3 hDlg)
,;let autodetect URL
,SendMessage(re EM_AUTOURLDETECT 1 0)
,;enable events
,SendMessage(re EM_SETEVENTMASK 0 ENM_LINK)
,
,DT_Init(hDlg lParam)
,
,ret 1
,case WM_DESTROY DT_DeleteData(hDlg)
,case WM_COMMAND goto messages2
,case WM_NOTIFY goto messages3
ret
;messages2
sel wParam
,case IDOK DT_Ok hDlg
,case IDCANCEL DT_Cancel hDlg
ret 1
;messages3
NMHDR* n=+lParam
sel n.code
,case EN_LINK
,ENLINK* el=+n
,if(el.msg=WM_LBUTTONUP)
,,TEXTRANGE tr
,,tr.chrg=el.chrg
,,tr.lpstrText=_s.all(tr.chrg.cpMax-tr.chrg.cpMin)
,,_s.fix(SendMessage(id(3 hDlg) EM_GETTEXTRANGE 0 &tr))
,,run _s
#7
Thanks.

but for me (except for links) it's easier to use:


Code:
Copy      Help
str a="{\rtf1\ansi\ansicpg1252\deff0\deflang3082{\fonttbl{\f0\fswiss\fcharset0 Arial;}}[]{\colortbl ;\red255\green0\blue0;\red0\green255\blue0;\red0\green0\blue255;}[]\viewkind4\uc1\pard\f0\fs20 This is a test \cf1 red \cf0\i cursive \b\i0 bold \cf2 green \cf3 blue \cf0\b0 normal \ul underline\ulnone , ...\par[]\par[]\pard\qc This is a center text\par[]\par[]\pard\qr and this is a right text\par[]\par[]\pard\fs28 This is a 14 size \fs20\par[]\par[]and this is normal.\par[]}"
out a
ShowText "" a
#8
I did not know. I use EM_STREAMIN.


Forum Jump:


Users browsing this thread: 1 Guest(s)