News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

RTF Control question

Started by guga, July 08, 2014, 06:24:08 AM

Previous topic - Next topic

guga

Hi guys

What is the RTF control message to change the view mode when you try to export a RTF file from a RichEdit Control?

I mean, in general, when you streamout the rtf contents from the control, the default mode is set to draft. "viewkind4" Accordying to RTF specifications.

But...how to programmatically change it ? I couldnĀ“t find the correct "EM_xxx" message

Quote from: from RTF specifications
\viewkindN   An integer (0 through 5) that represents the view mode of the document.
0   None
1   Page Layout view
2   Outline view
3   Master Document view
4   Draft view
5   Online Layout view


Also....how to change the background color to be displayed when export ? I mean the color of the whole document as when you are viewing in viewmode in M$Word and not only the back color for the texts (words)

This mnimalistic RTF example shows what are the tokens

{\rtf1\ansi\ansicpg1252\deff0\deflang1033\deflangfe1041{\fonttbl{\f0\froman\fprq2\fcharset0 Times New Roman;}}
{\colortbl ;\red255\green255\blue255;}
{\*\generator Msftedit 5.41.21.2509;}\viewkind5\uc1{\*\background{\shp{\*\shpinst
{\sp{\sn fillType}{\sv 0}}
{\sp{\sn fillColor}{\sv 0}}
{\sp{\sn fillBackColor}{\sv 0}}
{\sp{\sn fillFocus}{\sv 0}}
{\sp{\sn fillBlip}{\sv {\pict\wmetafile0\picscalex1\picscaley1
}}}}}}
\pard\cf1\f0\fs24 Testing\par
\par
}


"fillbackcolor" is the color the whole background in viewmode5 ???
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

jj2007

Hi Guga,

With
      invoke SendMessage, hRtf, EM_SETBKGNDCOLOR, 0, 0E0E0CCh      ; BGR

you can set the documents background colour. It seems that e.g. {\sp{\sn fillColor}{\sv 16776960}} can override this message, while the fillBackColor has apparently no effect.

viewkind will be ignored by the control, instead you can set fonts programmatically.

guga

Hi JJ

yes, this is what i did, but when exporting, the background color are not being displayed.

I made a small function to control fonts and colors under a simple structure that the user control. It displays properly on the richedit control the background color, but when trying to export the background is gone.

The main functions is something like this:


;;
                SetRTFFont

                This function controls all effects of a given font inside a richedit control

                Arguments
                hRTF: Handle to the RichEdit Control
                RTF_Sruct: A pointer to a RTF_SETUP structure to configurate the used font and color.
;;

Proc SetRTFFont:
    Arguments @hRTF, @RTF_Struct
    Structure @ChrFmt 84, @ChrFmt_cbSizeDis 0, @ChrFmt_dwMaskDis 4, @ChrFmt_dwEffectsDis 8, @ChrFmt_yHeightDis 12, @ChrFmt_yOffsetDis 16, @ChrFmt_crTextColorDis 20,
                          @ChrFmt_bCharSetDis 24, @ChrFmt_bPitchAndFamilyDis 25, @ChrFmt_szFaceNameDis 26, @ChrFmt__wPad2Dis 58, @ChrFmt_wWeightDis 60,
                          @ChrFmt_sSpacingDis 62, @ChrFmt_crBackColorDis 64, @ChrFmt_lcidDis 68, @ChrFmt_dwReservedDis 72, @ChrFmt_sStyleDis 76,
                          @ChrFmt_wKerningDis 78, @ChrFmt_bUnderlineTypeDis 80, @ChrFmt_bAnimationDis 81, @ChrFmt_bRevAuthorDis 82, @ChrFmt_bReserved1Dis 83

    Uses esi, edi, ebx, ecx, eax, edx

    mov esi D@RTF_Struct
    call 'GDI32.GetStockObject' &DEFAULT_GUI_FONT
    call 'USER32.SendMessageA' D@hRTF &WM_SETFONT, eax, &FALSE
    call 'USER32.SendMessageA' D@hRTF, &EM_SETBKGNDCOLOR, 0, D$esi+RTF_SETUP.ControlBackColorDis <----- This works, but does not exports if i create a RTF file:(:(:(
    call 'GDI32.CreateFontA' D$esi+RTF_SETUP.nHeightDis, D$esi+RTF_SETUP.nWidthDis, D$esi+RTF_SETUP.nEscapementDis, D$esi+RTF_SETUP.nOrientationDis, D$esi+RTF_SETUP.fnWeightDis,
                             D$esi+RTF_SETUP.fdwItalicDis, D$esi+RTF_SETUP.fdwUnderlineDis, D$esi+RTF_SETUP.fdwStrikeOutDis, D$esi+RTF_SETUP.fdwCharSetDis,
                             D$esi+RTF_SETUP.fdwOutputPrecisionDis, D$esi+RTF_SETUP.fdwClipPrecisionDis, D$esi+RTF_SETUP.fdwQualityDis, D$esi+RTF_SETUP.fdwPitchAndFamilyDis,
                             D$esi+RTF_SETUP.lpszFaceDis

    mov ebx eax ; our font handle
    call 'USER32.SendMessageA' D@hRTF, &WM_SETFONT, eax, &TRUE
    call ZeroMemory D@ChrFmt, 84
    mov D@ChrFmt_cbSizeDis 84
    mov D@ChrFmt_dwMaskDis &CFM_COLOR
    move D@ChrFmt_crTextColorDis D$esi+RTF_SETUP.FontColorDis
    call 'USER32.SendMessageA' D@hRTF, &EM_SETCHARFORMAT, &SCF_ALL, D@ChrFmt
   
    ;call 'USER32.SendMessageA' D@hRTF, &EM_GETEDITSTYLE, 0, 0
    ;call 'USER32.SendMessageA' D@hRTF, &EM_SETEDITSTYLE, &SES_EXTENDBACKCOLOR, &SES_EXTENDBACKCOLOR ; &EM_SCROLLCARET
    ; SES_EXTENDBACKCOLOR

    call ZeroMemory D@ChrFmt, 84
    mov D@ChrFmt_cbSizeDis 84
    mov D@ChrFmt_dwMaskDis &CFM_BACKCOLOR
    move D@ChrFmt_crBackColorDis D$esi+RTF_SETUP.ControlBackColorDis
    call 'USER32.SendMessageA' D@hRTF, &EM_SETCHARFORMAT, &SCF_ALL, D@ChrFmt

    ; delete our new font.
    call 'gdi32.DeleteObject' ebx

EndP



     RTF_SETUP structure


[RTF_SETUP:
RTF_SETUP.FontColor: D$ (160 or (22 shl 8) or (24 shl 16)) <-----The font color
RTF_SETUP.ControlBackColor: D$ (224 or (221 shl 8) or (198 shl 16)) <----- The color of the background of the font
RTF_SETUP.nHeight: D$ 16 <--- This parameter and the others are exactly the same one as in CreateFont Api.
RTF_SETUP.nWidth: D$ 0
RTF_SETUP.nEscapement: D$ 0
RTF_SETUP.nOrientation: D$ 0
RTF_SETUP.fnWeight: D$ &FW_DONTCARE
RTF_SETUP.fdwItalic: D$ &FALSE
RTF_SETUP.fdwUnderline: D$ &FALSE
RTF_SETUP.fdwStrikeOut: D$ &FALSE
RTF_SETUP.fdwCharSet: D$ &DEFAULT_CHARSET
RTF_SETUP.fdwOutputPrecision: D$ &OUT_DEFAULT_PRECIS
RTF_SETUP.fdwClipPrecision: D$ &CLIP_DEFAULT_PRECIS
RTF_SETUP.fdwQuality: D$ &DEFAULT_QUALITY
RTF_SETUP.fdwPitchAndFamily: D$ &DEFAULT_PITCH
RTF_SETUP.lpszFace: D$ Sz_RTFFontName]

[Sz_RTFFontName: B$ "MS Sans Serif", 0]






Example of usage:


[RTF_SETUP:
RTF_SETUP.FontColor: D$ (160 or (22 shl 8) or (24 shl 16))
RTF_SETUP.ControlBackColor: D$ (224 or (221 shl 8) or (198 shl 16))
RTF_SETUP.nHeight: D$ 16
RTF_SETUP.nWidth: D$ 0
RTF_SETUP.nEscapement: D$ 0
RTF_SETUP.nOrientation: D$ 0
RTF_SETUP.fnWeight: D$ &FW_DONTCARE
RTF_SETUP.fdwItalic: D$ &FALSE
RTF_SETUP.fdwUnderline: D$ &FALSE
RTF_SETUP.fdwStrikeOut: D$ &FALSE
RTF_SETUP.fdwCharSet: D$ &DEFAULT_CHARSET
RTF_SETUP.fdwOutputPrecision: D$ &OUT_DEFAULT_PRECIS
RTF_SETUP.fdwClipPrecision: D$ &CLIP_DEFAULT_PRECIS
RTF_SETUP.fdwQuality: D$ &DEFAULT_QUALITY
RTF_SETUP.fdwPitchAndFamily: D$ &DEFAULT_PITCH
RTF_SETUP.lpszFace: D$ Sz_RTFFontName]

[Sz_RTFFontName: B$ "MS Sans Serif", 0]


                   call SetRTFFont D$hMyRTF, RTF_SETUP
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