Watch, Follow, &
Connect with Us

For forums, blogs and more please visit our
Developer Tools Community.


Welcome, Guest
Guest Settings
Help

Thread: Rich edit to canvas


This question is answered. Helpful answers available: 1. Correct answers available: 1.


Permlink Replies: 4 - Last Post: Feb 17, 2018 2:30 PM Last Post By: Lex Dean Threads: [ Previous | Next ]
Lex Dean

Posts: 132
Registered: 3/26/07
Rich edit to canvas  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jan 20, 2018 12:34 PM
The code below works with a invisible rich edit
But it requires a timer of 1 mill second
I was wondering of a simple message to some object like the form could replace the timer so I keep the same thread going
can you suggest something please

procedure TForm2.FormCreate(Sender: TObject);

procedure DrawRTF(Bitmap: TBitmap; X1, Y1, X2, Y2: Integer);
const
BitmapPixelsPerInch = 96;
BitmapTwipsPerPixel = 1440 div BitmapPixelsPerInch;
var
Range: TFormatRange;
begin
with Range do
begin
hDC := Bitmap.Canvas.Handle; {DC handle}
hdcTarget := Bitmap.Canvas.Handle; {ditto}
rc := Rect(X1 * BitmapTwipsPerPixel, Y1 * BitmapTwipsPerPixel,
X2 * BitmapTwipsPerPixel, Y2 * BitmapTwipsPerPixel);
rcPage := rc;
chrg.cpMin := 0;
chrg.cpMax := 75;
RE.Perform(EM_FORMATRANGE, 0, 0);
RE.Perform(EM_FORMATRANGE, 0, DWord(@Range));
RE.Perform(EM_FORMATRANGE, 1, DWord(@Range)); {Now render the text}
RE.Perform(EM_FORMATRANGE, 0, 0);
end;
end;

begin
BM := TBitMap.Create;
BM.Width := 400;
BM.Height := 75;
BM.Mask(clwhite);
BM.TransparentMode := tmAuto;
RE.Lines.Clear;
RE.Font.Size := 48;
RE.Lines.BeginUpdate;
RE.Lines.Add('My Text');
RE.Lines.EndUpdate;
DrawRTF(BM, 0, 0, 600, 75);
Timer.Enabled := True;
end;

procedure TForm2.TimerTimer(Sender: TObject);
begin
Form2.Canvas.Draw(5, 5, BM);
BM.Free;
Timer.Enabled := False;
end;

Lex Dean

Posts: 132
Registered: 3/26/07
Re: Rich edit to canvas  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jan 20, 2018 2:56 PM   in response to: Lex Dean in response to: Lex Dean
below is the common remark but something else is not freed some how
Can I free it please

Remarks

This message is typically used with the EM_DISPLAYBAND message to format the content of rich edit control for an output device such as a printer.

It is very important to free cached information after the last time you use this message by specifying NULL in lParam. In addition, after using this message for one device, you must free cached information before using it again for a different device.

Remy Lebeau (Te...


Posts: 9,447
Registered: 12/23/01
Re: Rich edit to canvas
Helpful
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jan 22, 2018 10:11 AM   in response to: Lex Dean in response to: Lex Dean
Lex Dean wrote:

But it requires a timer of 1 mill second

To do what exactly? What are you trying to accomplish in the first
place?

I was wondering of a simple message to some object like the form
could replace the timer so I keep the same thread going can you
suggest something please

Just post your own custom message using PostMessage() to the Form's
HWND, and then do what you need in a handler for that message.

However, you are drawing the TBitmap directly onto the Form's Canvas
from outside of a paint cycle. As such, the drawing will be lost as
soon as the Form gets re-painted for any reason (and a visual window
gets painted frequently). If you need the image to be persistent, draw
it on the Form's Canvas from inside the Form's OnPaint event instead.

Or use a TImage component.

--
Remy Lebeau (TeamB)
Lex Dean

Posts: 132
Registered: 3/26/07
Re: Rich edit to canvas  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jan 25, 2018 9:49 PM   in response to: Remy Lebeau (Te... in response to: Remy Lebeau (Te...
Drawing on the form worked Bot its not were I'm hoping to put it
I will try in the form paint method but put it on the Bitmap

Thanks anyway.
Lex Dean

Posts: 132
Registered: 3/26/07
Re: Rich edit to canvas  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Feb 17, 2018 2:30 PM   in response to: Lex Dean in response to: Lex Dean
In the end I found text attributes in Rich edit and found them ore flexible than TFont
Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02