Search code examples
delphiwinapidelphi-7

How to set the TRichedit default paragraph background color


I try to set the TRichEdit control default paragraph bg color with this code:

//******************************************************************************
class procedure TRichEditUtility.setBGColor( aRE_ : TTNTRichEdit; bgColor_ : cardinal; default_ : boolean = FALSE );
//******************************************************************************
var
  cf: TCharFormat2;
begin
  if ( aRE_ <> NIL ) then
  begin
    fillchar(cf, sizeof(cf), 0);
    cf.cbSize := sizeof( cf );
    cf.dwMask := CFM_BACKCOLOR;
    cf.crBackColor := bgColor_;
    if ( default_ ) then
      aRE_.Perform( EM_SETCHARFORMAT, SPF_SETDEFAULT, lparam(@cf) )
    else
      aRE_.Perform( EM_SETCHARFORMAT, SCF_SELECTION, lparam(@cf) );
  end else
    raise EInvalidInputParameter.create_string( 'TRichEditUtility', 'setBGColor', 'aRE_', CONST_chars_NIL );
end;

But the value of the SPF_SETDEFAULT constant is unknown!

Can somebody tell me its value? (Or the file name which define its value)


Solution

  • Here is how to resolve this issue, and any issue of this nature.

    • Perform a websearch for SPF_SETDEFAULT.
    • This takes you to the documentation for EM_SETCHARFORMAT.
    • That document lists Richedit.h as the required header.
    • Locate Richedit.h in your copy of the Windows SDK and search for SPF_SETDEFAULT.
    • That search yields this: #define SPF_SETDEFAULT 0x0004.
    • So in Delphi you define the constant like this: const SPF_SETDEFAULT = $0004.