Solved

Bitmaps embedded in a TRichEdit control

Posted on 1998-09-02
4
418 Views
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.

Regards,
Erik
0
Comment
Question by:htw
  • 2
4 Comments
 
LVL 8

Accepted Solution

by:
ZifNab earned 100 total points
Comment Utility
htw,

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 :

TRichEditWithOle

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

---------------------------------------------------------

Regards,

Zif.
0
 
LVL 10

Expert Comment

by:viktornet
Comment Utility
Here is something you might want to try.....
---------------------
procedure TForm1.Button1Click(Sender: TObject);
var
  bmp : TBitmap;
  Can : TCanvas;
begin
  bmp := TBitmap.Create;
  Can := TCanvas.Create;
  try
    Bmp.LoadFromFile('E:\My Bmps\checked.bmp');
    Can.Handle := GetDC(RichEdit1.Handle);
    Can.Draw(100,100,bmp);
  finally
    Can.Free;
    bmp.Free;
  end;
end;
----------------
I hope it helps =)

Regards,
Viktor Ivanov
0
 

Author Comment

by:htw
Comment Utility
viktornet,

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.

0
 

Author Comment

by:htw
Comment Utility
ZifNab,

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!

Regards,
Erik
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
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…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

728 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now