Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Bitmaps embedded in a TRichEdit control

Posted on 1998-09-02
4
Medium Priority
?
434 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 8

Accepted Solution

by:
ZifNab earned 300 total points
ID: 1338478
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
ID: 1338479
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
ID: 1338480
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
ID: 1338481
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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

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…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
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

722 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