Page 1 of 1

Support for RichEdit 4.1 - source code

Posted: Tue Jul 24, 2007 7:46 am
by tomisoft
Hi,

I've needed to add support for new RichEdit 4.1 component introduced in Windows XP SP 2, so I made some improvements in frxRichEdit.pas unit. I'll be happy if Sergey wants to add it to standard package.
Here it goes (changes are bold):

unit frxRichEdit;

{$I frx.inc}

interface

uses
Windows, ActiveX, ComObj, CommCtrl, Messages, SysUtils, Classes, Controls,
Forms, Graphics, StdCtrls, Dialogs, RichEdit, Menus, ComCtrls;

interface

type
TRichEditVersion = 1..{3}4;

implementation

const
RichEdit41ModuleName = 'MSFTEDIT.DLL';

procedure TRxCustomRichEdit.CreateParams(var Params: TCreateParams);
const
HideScrollBars: array[Boolean] of DWORD = (ES_DISABLENOSCROLL, 0);
HideSelections: array[Boolean] of DWORD = (ES_NOHIDESEL, 0);
WordWraps: array[Boolean] of DWORD = (0, ES_AUTOHSCROLL);
SelectionBars: array[Boolean] of DWORD = (0, ES_SELECTIONBAR);

MSFTEDIT_CLASS = 'RichEdit50W';

begin
inherited CreateParams(Params);
case RichEditVersion of
1: CreateSubClass(Params, RICHEDIT_CLASS10A);
4: CreateSubClass(Params, MSFTEDIT_CLASS);
else CreateSubClass(Params, RICHEDIT_CLASS);
end;
with Params do begin
Style := (Style and not (WS_HSCROLL or WS_VSCROLL)) or ES_SAVESEL or
(WS_CLIPSIBLINGS or WS_CLIPCHILDREN);
{ NOTE: WS_CLIPCHILDREN and WS_CLIPSIBLINGS are essential otherwise }
{ once the object is inserted you see some painting problems. }
Style := Style and not (WS_HSCROLL or WS_VSCROLL);
if ScrollBars in [ssVertical, ssBoth] then
Style := Style or WS_VSCROLL;
if (ScrollBars in [ssHorizontal, ssBoth]) and not WordWrap then
Style := Style or WS_HSCROLL;
Style := Style or HideScrollBars[FHideScrollBars] or
SelectionBars[FSelectionBar] or HideSelections[FHideSelection] and
not WordWraps[WordWrap];
WindowClass.style := WindowClass.style and not (CS_HREDRAW or CS_VREDRAW);
end;
end;

initialization
RichEditVersion := 1;
OldError := SetErrorMode(SEM_NOOPENFILEERRORBOX);
try
FLibHandle := LoadLibrary(RichEdit41ModuleName);
if (FLibHandle > 0) and (FLibHandle < HINSTANCE_ERROR) then
FLibHandle := 0;
if FLibHandle = 0 then
begin

FLibHandle := LoadLibrary(RichEdit20ModuleName);
if (FLibHandle > 0) and (FLibHandle < HINSTANCE_ERROR) then
FLibHandle := 0;
if FLibHandle = 0 then begin
FLibHandle := LoadLibrary(RichEdit10ModuleName);
if (FLibHandle > 0) and (FLibHandle < HINSTANCE_ERROR) then
FLibHandle := 0;
end
else
begin
RichEditVersion := 2;
Ver.dwOSVersionInfoSize := SizeOf(Ver);
GetVersionEx(Ver);
with Ver do
begin
if (dwPlatformId = VER_PLATFORM_WIN32_NT) and (dwMajorVersion >= 5) then
RichEditVersion := 3;
end;
end;
end
else
RichEditVersion := 4;

finally
SetErrorMode(OldError);
end;
CFEmbeddedObject := RegisterClipboardFormat(CF_EMBEDDEDOBJECT);
CFLinkSource := RegisterClipboardFormat(CF_LINKSOURCE);
CFRtf := RegisterClipboardFormat(CF_RTF);
CFRtfNoObjs := RegisterClipboardFormat(CF_RTFNOOBJS);
finalization
if FLibHandle <> 0 then FreeLibrary(FLibHandle);
end.

Best regards

Milan

P.S.: If anybody wants whole unit source feel free to pm me

Posted: Tue Jul 24, 2007 2:20 pm
by Sergey Tkachenko
Err... sorry, what is frxRichEdit.pas?

Posted: Wed Jul 25, 2007 6:16 am
by hruslan2000
Maybe it for FastReport?
Seems like this...