?
Solved

Changing color of font automatically

Posted on 1997-07-20
1
Medium Priority
?
239 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
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
Course of the Month13 days, 17 hours left to enroll

801 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