Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Changing color of font automatically

Posted on 1997-07-20
1
Medium Priority
?
241 Views
Last Modified: 2013-12-03
Is it possible when loading a *.rtf document in richedit, which contains any black font to automatically convert to white font at loading.
0
Comment
Question by:hellfire052497
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 4

Accepted Solution

by:
erajoj earned 160 total points
ID: 1339317
This works but it isn't the most beautiful piece of code
I have come up with. It is not very fast but it does the job.
This is quite a complicated problem and it's really worth
more than 40pts, but this solution is ;^):

procedure TfrmMain.LoadRTFBlackToWhite(FileName: string);
const
  BlackAttr = $80000008; // don't ask me why, ought to be $0
var
  Index1, Index2 : Integer;
  First, Last    : Cardinal;
begin
  RichEdit1.Hide;
  RichEdit1.Lines.LoadFromFile(FileName);
  SendMessage(RichEdit1.Handle, EM_SETSEL, 0, -1); // Set cursor at last position
  SendMessage(RichEdit1.Handle, EM_GETSEL, Integer(@First), Integer(@Last)); // Get gursor position
  Index1  := 0; // First char
  repeat  // Yes it's true, scan through every char. Might be slow on large files!
    SendMessage(RichEdit1.Handle, EM_SETSEL, Index1, Index1+1); // Select char
    with RichEdit1.SelAttributes do
    if (Color=BlackAttr) or (Color=clBlack) then begin
      Index2 := Index1;
      repeat // Find end of color paragraph
        SendMessage(RichEdit1.Handle, EM_SETSEL, Index2, Index2+1);
        Inc(Index2);
      until ((Color<>BlackAttr) and (Color<>clBlack)) or (Index2>=Last);
      SendMessage(RichEdit1.Handle, EM_SETSEL, Index1, Index2-1);
      RichEdit1.SelAttributes.Color := clWhite; // replacement
      Index1 := Index2-1;
    end;
    Inc(Index1);
  until (Index1>=Last);
  SendMessage(RichEdit1.Handle, EM_SETSEL, -1, 0); // Select nothing and put cursor last
  RichEdit1.Show;
end;

/// John
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
Suggested Courses

609 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question