Solved

Changing color of font automatically

Posted on 1997-07-20
1
214 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
1 Comment
 
LVL 4

Accepted Solution

by:
erajoj earned 40 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 Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
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…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

760 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now