Go Premium for a chance to win a PS4. Enter to Win


Bitmaps embedded in a TRichEdit control

Posted on 1998-09-02
Medium Priority
Last Modified: 2013-12-03
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.

Question by:htw
  • 2

Accepted Solution

ZifNab earned 300 total points
ID: 1338478

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/



LVL 10

Expert Comment

ID: 1338479
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

Author Comment

ID: 1338480

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.


Author Comment

ID: 1338481

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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
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…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
Suggested Courses

927 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