[Webinar] Streamline your web hosting managementRegister Today

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 440
  • Last Modified:

Bitmaps embedded in a TRichEdit control

I'm looking for code snippets, examples, etc. how to implement bitmaps (standard BMP files, e.g. a company logo) in a TRichEdit. I know I'll probably need to use the IRichEditOle interface (it's OK if it's NT only, since that's the only platform this software will be running on). But I haven't the foggiest where to start...
As a quite experienced Pascal programmer but a relative newbie at the Windows API, I could use all help and hints you experts can provide me.

  • 2
1 Solution

This is what I normally would answer, ...

 I don't think it's possible to add any Object into a TRichedit. TRichEdit is limited!! Very Limited! It's descents from Windows Richedit control and doesn't has all the functions!

To try it for yourself, do the following:

1. Create a new document in Word.
2. Type in some text, format it the way you want.
3. Insert some picture.
4. Save the file as Rich Text Format (.RTF)
5. Open the previous RTF file from within your Delphi application, using MyRichEdit.Loadfromfile('xxxxxx.rtf').

Result :
The text will be displayed exactly how you formated it in Word, but the images won't. Thus we can conclude that images aren't supported by TRichEdit..


BUT : Last I read that it is possible with D3 and the richedit comming from IE4... here is the text :

Using Delphi 3 and the RichEdit control which comes with the IE 4 release, it appears that all you absolutely have to do to display graphics and other embedded or linked objects in a RichEdit control is implement one method of IRichEditOLECallback: specifically GetNewStorage. I've attached a TRichEdit descendent which does this (in the file OLERichEdit.pas) as well as a translation of the richole.h file (from BC5) which defines the RichEdit OLE interfaces.

The OLERichEdit file also includes one obvious enhancement to the default behavior. If you enable the VerbMenu define, then when you select a (linked or embedded) object and right click on it, the control will pop up a menu of available verbs for the object. The code used is essentially the same as that in the VCL's TOleContainer.

The implementation of the control included here allows you to edit objects by double clicking on them; it opens whatever application is registered to edit the object type (e.g., double click on a bitmap and Paint opens up).
The RichEdit control will also support in-place activation, provided you implement the right methods of IRichEditOleCallback (I did not try this in the unit included here). It appears to me that alot of the stuff in OLECTNRS.PAS could be used to enable this behavior.

Finally, a warning. This control has not been extensively tested by any means, and there may well be bugs or gotchas that I have not anticipated.
Use with caution. It is intended primarily as a starting point for people interested in extending TRichEdit.

followed by the code of richole... to big to paste it here

another (never tested this) component you can find :


find sources etc at his homepage http://wet.kiss.uni-lj.si/~k4fe0106/



Here is something you might want to try.....
procedure TForm1.Button1Click(Sender: TObject);
  bmp : TBitmap;
  Can : TCanvas;
  bmp := TBitmap.Create;
  Can := TCanvas.Create;
    Bmp.LoadFromFile('E:\My Bmps\checked.bmp');
    Can.Handle := GetDC(RichEdit1.Handle);
I hope it helps =)

Viktor Ivanov
htwAuthor Commented:

I too played with the idea to treat the RichEdit control as a canvas, and on screen this approach works OK, but it's a big hassle to print the "embedded" (or should I say overlayed, or is it underlayed? ;-)) graphics on paper.

htwAuthor Commented:

Thanks, on a first glance this looks like the component I need! Good readable source, looks like a decent piece of code, and even if it doesn't work (haven't tried it yet) it should be a great starting point for me to set my teeth in... ;-)

Maybe one caveat: in the past (when I just started with Delphi, coming from a Clipper background) I also tried to embed OLE objects using IRichEditOLECallback (in a _much_ less sophisticated way), and while this worked under Win95, it did absolutely nothing under NT 4.0 ws. If this still is the case it shouldn't be too difficult to alter the component so it uses IRichEditOLECallback under W95 and IRichEditOLE under NT...

Anyway, thanks for the URL. Apparently a lot of great Delphi programmers are living in the eastern part of Europe!


Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now