Watch, Follow, &
Connect with Us

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


Welcome, Guest
Guest Settings
Help

Thread: RichEdit on canvas comctl32.lib



Permlink Replies: 6 - Last Post: Feb 4, 2018 11:10 PM Last Post By: Lex Dean
Lex Dean

Posts: 132
Registered: 3/26/07
RichEdit on canvas comctl32.lib
Click to report abuse...   Click to reply to this thread Reply
  Posted: Feb 1, 2018 7:59 PM
The comctl32.lib has been extended with statements below in Windows 7 and on
CHARFORMAT2 and WNDCLASSEX
https://msdn.microsoft.com/en-us/library/windows/desktop/bb787883(v=vs.85).aspx
https://msdn.microsoft.com/en-us/library/windows/desktop/ms633577(v=vs.85).aspx

I have some issues how to translate this info
WNDCLASSEX has
a) lpfnWndProc :WNDPROC This contains the HWND that we use to paint the canvas, can I get this info from a Delphi procedure TControl.CreateParams(var Params: TCreateParams); out of the Params
b) cbWndExtra: integer what size is DLGWINDOWEXTRA
c) lpszClassName: String or pointer or PChar, where Do I find this

CHARFORMAT2 there is a whole lot of values that are not given on the msn web site
CFM_ALL.................... best read from the page above Is these values available some were please.

Getting this to work with EM_SETCHARFORMAT will give me rich edit on a canvas hopefully
Peter Below

Posts: 1,227
Registered: 12/16/99
Re: RichEdit on canvas comctl32.lib
Click to report abuse...   Click to reply to this thread Reply
  Posted: Feb 1, 2018 11:19 PM   in response to: Lex Dean in response to: Lex Dean
Lex Dean wrote:

The comctl32.lib has been extended with statements below in Windows 7
and on CHARFORMAT2 and WNDCLASSEX
https://msdn.microsoft.com/en-us/library/windows/desktop/bb787883(v=vs.85).aspx
https://msdn.microsoft.com/en-us/library/windows/desktop/ms633577(v=vs.85).aspx

I have some issues how to translate this info
WNDCLASSEX has
a) lpfnWndProc :WNDPROC This contains the HWND that we use to paint
the canvas, can I get this info from a Delphi procedure
TControl.CreateParams(var Params: TCreateParams); out of the Params
b) cbWndExtra: integer what size is DLGWINDOWEXTRA c) lpszClassName:
String or pointer or PChar, where Do I find this

CHARFORMAT2 there is a whole lot of values that are not given on the
msn web site CFM_ALL.................... best read from the page
above Is these values available some were please.

Getting this to work with EM_SETCHARFORMAT will give me rich edit on
a canvas hopefully

I do not understand what you are after, sorry. To render a richedit's
content to a canvas you use the EM_FORMATRANGE message, nothing else.

I found this old example in my collection:

procedure TForm1.Button2Click(Sender: TObject);
Var
printarea: Trect;
x, y: Integer;
richedit_outputarea: TRect;
printresX, printresY: Integer;
fmtRange: TFormatRange;
Begin
Printer.beginDoc;
try
With Printer.Canvas Do Begin
printresX := GetDeviceCaps( handle, LOGPIXELSX );
printresY := GetDeviceCaps( handle, LOGPIXELSY );
Font.Name := 'Arial';
Font.Size := 14;
Font.Style := [fsBold];
printarea :=
Rect( printresX, // 1 inch left margin
printresY * 3 div 2, // 1.5 inch top margin
Printer.PageWidth - printresX, // 1 inch right margin
Printer.PageHeight - printresY * 3 div 2 // 1.5 inch
bottom margin
);
x := printarea.left;
y := printarea.top;
TextOut( x, y, 'A TRichEdit print example' );
y := y + TextHeight('Ag');
Moveto( x, y );
Pen.Width := printresY div 72; // 1 point
Pen.Style := psSolid;
Pen.Color := clBlack;
LineTo( printarea.Right, y );
Inc( y, printresY * 5 div 72 );

// Define a rectangle for the rich edit text. The height is set
to the
// maximum. But we need to convert from device units to twips,
// 1 twip = 1/1440 inch or 1/20 point.
richedit_outputarea :=
Rect( (printarea.left+2) * 1440 div printresX,
y * 1440 div printresY,
(printarea.right-4) * 1440 div printresX,
(printarea.bottom)* 1440 div printresY );

// Tell rich edit to format its text to the printer. First set
// up data record for message:
fmtRange.hDC := Handle; // printer handle
fmtRange.hdcTarget := Handle; // ditto
fmtRange.rc := richedit_outputarea;
fmtRange.rcPage :=
Rect( 0, 0,
Printer.PageWidth * 1440 div printresX,
Printer.PageHeight * 1440 div printresY );
fmtRange.chrg.cpMin := 0;
fmtRange.chrg.cpMax := richedit1.GetTextLen-1;

// first measure the text, to find out how high the format
rectangle
// will be. The call sets fmtrange.rc.bottom to the actual height
// required, if all characters in the selected range will fit into
// a smaller rectangle,
richedit1.Perform( EM_FORMATRANGE, 0, Longint(@fmtRange));

// Draw a rectangle around the format rectangle
Pen.Width := printresY div 144; // 0.5 points
Brush.Style := bsClear;
Rectangle( printarea.Left, y - 2, printarea.right,
fmtrange.rc.bottom * printresY div 1440 + 2 );

// Now render the text
richedit1.Perform( EM_FORMATRANGE, 1, Longint(@fmtRange));
y := fmtrange.rc.bottom * printresY div 1440 + printresY * 5 div
72;

// Free cached information
richedit1.Perform( EM_FORMATRANGE, 0, 0);
TextOut( x, y, 'End of example.' );
End;
finally
Printer.EndDoc;
end;
end;

--
Peter Below
TeamB
Lex Dean

Posts: 132
Registered: 3/26/07
Re: RichEdit on canvas comctl32.lib
Click to report abuse...   Click to reply to this thread Reply
  Posted: Feb 2, 2018 1:22 AM   in response to: Peter Below in response to: Peter Below
Peter
I just what rich edit on a form canvas
Not printer canvas,
I have no code support for these statements
Peter Below

Posts: 1,227
Registered: 12/16/99
Re: RichEdit on canvas comctl32.lib
Click to report abuse...   Click to reply to this thread Reply
  Posted: Feb 3, 2018 12:40 AM   in response to: Lex Dean in response to: Lex Dean
Lex Dean wrote:

Peter
I just what rich edit on a form canvas
Not printer canvas,

Does not matter, em_formatrange works for any type of canvas.


--
Peter Below
TeamB

Remy Lebeau (Te...


Posts: 9,447
Registered: 12/23/01
Re: RichEdit on canvas comctl32.lib
Click to report abuse...   Click to reply to this thread Reply
  Posted: Feb 2, 2018 10:04 AM   in response to: Lex Dean in response to: Lex Dean
Lex Dean wrote:

The comctl32.lib has been extended with statements below in Windows 7
and on CHARFORMAT2 and WNDCLASSEX

CHARFORMAT2 was introduced in Windows 98/NT4.

WNDCLASSEX was introduced in Windows 2000.

WNDCLASSEX has
a) lpfnWndProc :WNDPROC This contains the HWND that we use to paint
the canvas, can I get this info from a Delphi procedure
TControl.CreateParams(var Params: TCreateParams); out of the Params
b) cbWndExtra: integer what size is DLGWINDOWEXTRA c) lpszClassName:
String or pointer or PChar, where Do I find this

You don't need to deal with WNDCLASSEX at all. TWinControl already
deals with WNDCLASS for you, and the only thing WMDCLASSEX adds over
WNDCLASS is the ability to register a small icon with a window class,
which is not necessary for child controls.

CHARFORMAT2 there is a whole lot of values that are not given on the
msn web site CFM_ALL.................... best read from the page above
Is these values available some were please.

The numeric values are not documented on MSDN, because the Win32 API is
designed and documented with C/C++ compilers in mind, and the Win32 API
header files for C/C++ define the actual numbers. But, the numbers are
easy to find with a simple web search, if you don't have the Win32 SDK
installed (such as in C++Builder).

Getting this to work with EM_SETCHARFORMAT will give me rich edit on
a canvas hopefully

No, it won't. EM_SETCHARFORMAT has nothing to do with canvases at
all. Like Peter said, you need to use EM_FORMATRANGE instead.

--
Remy Lebeau (TeamB)
Lex Dean

Posts: 132
Registered: 3/26/07
Re: RichEdit on canvas comctl32.lib
Click to report abuse...   Click to reply to this thread Reply
  Posted: Feb 3, 2018 10:07 PM   in response to: Remy Lebeau (Te... in response to: Remy Lebeau (Te...
A lot of experience and info tips Remy Lebeau
Format range is useful but not to change font style

thanks for advice I see if I can pull this off.

Edited by: Lex Dean on Feb 4, 2018 12:47 AM
Lex Dean

Posts: 132
Registered: 3/26/07
Re: RichEdit on canvas comctl32.lib
Click to report abuse...   Click to reply to this thread Reply
  Posted: Feb 4, 2018 11:10 PM   in response to: Lex Dean in response to: Lex Dean
With a little searching on the internet
And looking how Delphi uses TCHARFORMAT
It did not take me long to find TRichEdit and FSelAttributes := TTextAttributes.Create(Self, atSelected);
If I take TTextAttributes rewrite it with my own parent (with its own canvas) I should have a major step to write RichEdit on my own canvas
everything is their as I see to do this.
I see this as more RAD and getting the Job Done.
Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02