Page 1 of 1

RichtText Class

Posted: Sun Feb 05, 2006 1:49 am
by reinaldocrespo
Hi.

I see the function RESetTextColor( ::hWnd, nRGB ) being used to color selected text. I also see :

RESetCharFormat( ::hWnd, ::oFont:cFaceName, ;
::oFont:nHeight * FNT_HEIGHT, nColor, ;
::oFont:nCharSet, ;
::oFont:nPitchFamily, ;
::oFont:nWeight, ;
::oFont:lItalic, ;
::oFont:lUnderline, ;
::oFont:lStrikeOut )

used to set font, size, color, etc... on selected text. They both work just fine to change foreground color of text.

However, I'd like to find a way to change the background color of selected text. Neither of these two seems to do it. Does any body know how can it be done?

thank you,


Reinaldo Crespo-Bazán.

Re: RichtText Class

Posted: Sun Feb 05, 2006 10:38 am
by Enrico Maria Giordano
Have a look at EM_SETCHARFORMAT message, SCF_SELECTION option and crBackColor field of CHARFORMAT2 structure (remember to set dwMask field to CFM_BACKCOLOR to activate crBackColor field).

EMG

Posted: Sun Feb 05, 2006 5:36 pm
by reinaldocrespo
Enrico;

Thank you for the tip.

I seldom make any contributions.

Below is what I wrote.

That's my 2 cents.

//----------------------------------------------------------------------------//

HB_FUNC( HIGHLIGHTSELECTION )
{
CHARFORMAT2 cfrm;

memset( ( char * ) &cfrm, 0, sizeof( cfrm ) );

cfrm.cbSize = sizeof( cfrm );
cfrm.dwMask = CFM_BACKCOLOR; //EMG tip. Without it won't work
cfrm.crBackColor = hb_parnl( 2 ); //color passed from xharb source

hb_retl( SendMessage( ( HWND ) hb_parnl( 1 ), EM_SETCHARFORMAT,
SCF_WORD | SCF_SELECTION, ( LPARAM ) &cfrm ) );
}

Here is how to call it from xharbour:

HighLightSelection( oRtf:hWnd, nClrBackGround )

Reinaldo.