BorlandTalk.com Forum Index BorlandTalk.com
Borland discussion newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

How can i display pictures/icons in TMemo
Goto page 1, 2  Next
 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> C++ Builder (VCL Components Development)
View previous topic :: View next topic  
Author Message
sphinxing
Guest





PostPosted: Fri Dec 12, 2003 2:59 am    Post subject: How can i display pictures/icons in TMemo Reply with quote



I want to write a custom component derived from TMemo or TEdit, that can
replace non-visual ANSI chars with small icons when I send those chars to
that component or load contents(e.g. file content) into it. My trouble is: I
have no idea how TMemo can treat icons as texts just like Richedit and how
caret can move through icons or select icons and even copy and paste them.

I have already readed TCustomRichedit source code in VCL, but I didn't find
how TCustomRichedit have capability of displaying graphics:( Code below
troubled me.

procedure TCustomRichEdit.CreateParams(var Params: TCreateParams);
const
RichEditModuleName = 'RICHED32.DLL';
HideScrollBars: array[Boolean] of DWORD = (ES_DISABLENOSCROLL, 0);
HideSelections: array[Boolean] of DWORD = (ES_NOHIDESEL, 0);
begin
if FRichEditModule = 0 then
begin
FRichEditModule := LoadLibrary(RichEditModuleName);
if FRichEditModule <= HINSTANCE_ERROR then FRichEditModule := 0;
end;
inherited CreateParams(Params);
CreateSubClass(Params, 'RICHEDIT');
..........

Can you help me?


Back to top
Remy Lebeau (TeamB)
Guest





PostPosted: Fri Dec 12, 2003 3:29 am    Post subject: Re: How can i display pictures/icons in TMemo Reply with quote



"sphinxing" <sphinxing (AT) 163 (DOT) com> wrote


Quote:
I have no idea how TMemo can treat icons as texts just like Richedit

It cannot. TMemo (and TEdit) have no support for images at all. Only
TRichEdit has that, so you will have to use that instead.

Quote:
I have already readed TCustomRichedit source code in VCL, but
I didn't find how TCustomRichedit have capability of displaying graphics

TCustomRichEdit (and thus TRichEdit) does not expose any native access for
displaying graphics. You will have to do it manually via the IRichEditOle
interface instead. Send the RichEdit window an EM_GETOLEINTERFACE message
to get the IRichEditOle interface, and then call its InsertObject() method
to insert a graphic.

However, just preparing for calling InsertObject() is not a trivial task,
you have to fill in a REOBJECT structure, which in turn requires you to
implement your own IOleObject and IDataObject interfaces, which themselves
are a bit complex to implement manually. Your best bet is to just go to
http://home.att.net/~robertdunn/Yacs.html and get Robert's TaeRichEdit
component and TIRichEditOle support class, they already do all of this work
for you.


Gambit



Back to top
sphinxing
Guest





PostPosted: Fri Dec 12, 2003 3:42 am    Post subject: Re: How can i display pictures/icons in TMemo Reply with quote



Thx at first.

I think what I need is so simple that I don't have to use Richedit or
others. And, I don't know whether I can draw icons myself, but I really want
do that myself. I just want to write my own component. Except Richedit or
others' component, Can you help me more?

I am always online within 6 hours. Waiting your answer.


Back to top
Rodolfo Frino
Guest





PostPosted: Fri Dec 12, 2003 4:56 am    Post subject: Re: How can i display pictures/icons in TMemo Reply with quote

I have an article on how o insert images along with static text in a
RichEdit
control
http://www.geocities.com/rodolfofrino/RichEditInsertImage.html

Rodolfo

"sphinxing" <sphinxing (AT) 163 (DOT) com> wrote

Quote:
Thx at first.

I think what I need is so simple that I don't have to use Richedit or
others. And, I don't know whether I can draw icons myself, but I really
want
do that myself. I just want to write my own component. Except Richedit or
others' component, Can you help me more?

I am always online within 6 hours. Waiting your answer.





Back to top
sphinxing
Guest





PostPosted: Fri Dec 12, 2003 5:41 am    Post subject: Re: How can i display pictures/icons in TMemo Reply with quote

Sad I can't access
http://www.geocities.com/rodolfofrino/RichEditInsertImage.html because page
not found.


"Rodolfo Frino" <MenInBlack (AT) nowhere (DOT) com> wrote

Quote:
I have an article on how o insert images along with static text in a
RichEdit
control
http://www.geocities.com/rodolfofrino/RichEditInsertImage.html

Rodolfo




Back to top
Rodolfo Frino
Guest





PostPosted: Fri Dec 12, 2003 6:42 am    Post subject: Re: How can i display pictures/icons in TMemo Reply with quote

I don't have problems accessing that page.

Rodolfo

"sphinxing" <sphinxing (AT) 163 (DOT) com> wrote

Quote:
Sad I can't access
http://www.geocities.com/rodolfofrino/RichEditInsertImage.html because
page
not found.


"Rodolfo Frino" <MenInBlack (AT) nowhere (DOT) com> wrote in message
news:3fd94a72 (AT) newsgroups (DOT) borland.com...
I have an article on how o insert images along with static text in a
RichEdit
control
http://www.geocities.com/rodolfofrino/RichEditInsertImage.html

Rodolfo






Back to top
Remy Lebeau (TeamB)
Guest





PostPosted: Fri Dec 12, 2003 6:45 am    Post subject: Re: How can i display pictures/icons in TMemo Reply with quote

"Rodolfo Frino" <MenInBlack (AT) nowhere (DOT) com> wrote

Quote:
I have an article on how o insert images along with static text in
a RichEdit control

Your solution is a hack at best. All it does it overlays a TImage on top of
the TRchEdit. You don't take scolling into account at all. You don't take
the user selecting the RichEdit content into account at all. You do not
take copy/paste into account at all. These are all things that sphinx
stated he needs (ok, not the scrolling part, but that is needed anyway). I
do not see how your solution can be applied to what he has described, not
even close.


Gambit



Back to top
Rodolfo Frino
Guest





PostPosted: Fri Dec 12, 2003 6:47 am    Post subject: Re: How can i display pictures/icons in TMemo Reply with quote

Here is the code

RichEditInsertImage.cpp

#include <vcl.h>
#pragma hdrstop

#include "RichEditInsertImage.h"

//--------------------------------------------------------------------------
-
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
TRichEdit* RichEdit1;
TImage* p;


__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
Color = (TColor)0x12dec;
Width = 800;
Height = 600;
Position = poScreenCenter;

//Create the TRichEdit Component
RichEdit1 = new TRichEdit(this);
RichEdit1->Parent = this;
RichEdit1->Top = 50;
RichEdit1->Left = 50;
RichEdit1->Width = 300;
RichEdit1->Height = 300;

//Create the TImage Component
p = new TImage( RichEdit1 );
p->Parent = RichEdit1;
p->Top = 100;
p->Left = 10;
p->Width = 30;
p->Height = 30;
p->Picture->LoadFromFile( String("C:\Dir1\Dir2\Image1.bmp") );
}
RichEditInsertImage.h

#ifndef RichEditInsertImageH
#define RichEditInsertImageH
//--------------------------------------------------------------------------
-
#include <Classes.hpp>
#include <Controls.hpp>
#include <StdCtrls.hpp>
#include <Forms.hpp>
#include <ComCtrls.hpp>
#include <ImgList.hpp>
#include <ExtCtrls.hpp>
#include <sGraphics.hpp>
//--------------------------------------------------------------------------
-
class TForm1 : public TForm
{
__published: // IDE-managed Components
void __fastcall RichEdit1Enter(TObject *Sender);
private: // User declarations
public: // User declarations
__fastcall TForm1(TComponent* Owner);
};
//--------------------------------------------------------------------------
-
extern PACKAGE TForm1 *Form1;
//--------------------------------------------------------------------------
-
#endif


Rodolfo


Back to top
Remy Lebeau (TeamB)
Guest





PostPosted: Fri Dec 12, 2003 6:48 am    Post subject: Re: How can i display pictures/icons in TMemo Reply with quote

"sphinxing" <sphinxing (AT) 163 (DOT) com> wrote


Quote:
I think what I need is so simple that I don't have to use Richedit
or others.

What you are asking for is *not* as simple as you think. If you want the
images to truely be part of the RichEdit content, then using a RichEdit with
the IRichEditOle interface is the best way to go, since RichEdit's already
have native support for embedded images, the VCL simply doesn't expose
access to it by default. Otherwise, you'll just have to write your own edit
component *from scratch*, derived, from either TCustomControl or
TGraphicControl, handling all of the drawing, scrolling, copy/pasting, etc.
manually.


Gambit



Back to top
sphinxing
Guest





PostPosted: Fri Dec 12, 2003 6:58 am    Post subject: Re: How can i display pictures/icons in TMemo Reply with quote

God:-( It seems that I must use Richedit. But I really have no idea about
OLE, interfaces etc. I'm just a beginner:-(
After all, thank kindly Remy.
Another question: if I'll learn about IRichEditOle interface, what knowledge
I need? COM?? Does it spend my long time?
And... what's Gambit Smile Nickname?


"Remy Lebeau (TeamB)" <gambit47.no.spam (AT) no (DOT) spam.yahoo.com> wrote

Quote:

"sphinxing" <sphinxing (AT) 163 (DOT) com> wrote in message
news:3fd93940$1 (AT) newsgroups (DOT) borland.com...

I think what I need is so simple that I don't have to use Richedit
or others.

What you are asking for is *not* as simple as you think. If you want the
images to truely be part of the RichEdit content, then using a RichEdit
with
the IRichEditOle interface is the best way to go, since RichEdit's already
have native support for embedded images, the VCL simply doesn't expose
access to it by default. Otherwise, you'll just have to write your own
edit
component *from scratch*, derived, from either TCustomControl or
TGraphicControl, handling all of the drawing, scrolling, copy/pasting,
etc.
manually.


Gambit





Back to top
sphinxing
Guest





PostPosted: Fri Dec 12, 2003 7:04 am    Post subject: Re: How can i display pictures/icons in TMemo Reply with quote

Sorry, I think Remy is right, that code can't help me.


Quote:
Your solution is a hack at best. All it does it overlays a TImage on top
of
the TRchEdit. You don't take scolling into account at all. You don't
take
the user selecting the RichEdit content into account at all. You do not
take copy/paste into account at all. These are all things that sphinx
stated he needs (ok, not the scrolling part, but that is needed anyway).
I
do not see how your solution can be applied to what he has described, not
even close.


Gambit



Back to top
Rodolfo Frino
Guest





PostPosted: Fri Dec 12, 2003 7:25 am    Post subject: Re: How can i display pictures/icons in TMemo Reply with quote

Use this one then

#include <vcl.h>
#include <vector>
#include <algorithm>
#pragma hdrstop

#include "RichEditInsertImagesAndText.h"

//--------------------------------------------------------------------------
-
#pragma package(smart_init)
#pragma resource "*.dfm"

using namespace std;

TForm1 *Form1;
TRichEdit* RichEdit1;
TButton* Button1;
TButton* Button2;
TButton* Button3;

const int NUMBER_IMAGES = 20;
TImage* p[NUMBER_IMAGES];

vector<AnsiString> Vector;

// We assume that all images are square
// (IMAGE_SIZE * IMAGE_SIZE pixels)
const int IMAGE_SIZE = 40;


//Compare function S1 Greater Than S2
bool Compare_GreaterThan(const AnsiString& S1, const AnsiString& S2)
{
return S1 > S2;
}

//Compare function S1 Less Than S2
bool Compare_LessThan(const AnsiString& S1, const AnsiString& S2)
{
return S1 < S2;
}

void SortVector(vector bool (pfun)(const AnsiString& S1, const AnsiString& S2))
{
sort(V.begin(), V.end(), pfun);
}

void Write( TRichEdit* p, String text, TColor color )
{
p->SelStart = p->GetTextLen();
p->SelAttributes->Color = color;
p->SelText = text;
}

__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
Color = (TColor)clSilver;
Width = 600;
Height = 500;
Position = poScreenCenter;

RichEdit1 = new TRichEdit(this);
RichEdit1->Parent = this;
RichEdit1->Top = 50;
RichEdit1->Width = 400;
RichEdit1->Left = Width/2 - RichEdit1->Width/2;
RichEdit1->Height = 280;
//------------------------
RichEdit1->Lines->Clear();
RichEdit1->Font->Size = 20;
Write(RichEdit1, "nnn", clBlack);
Write(RichEdit1, "Electronic Signn", clRed);
Write(RichEdit1, "This text is green", clGreen);
Write(RichEdit1, "This text is blue", clBlue);
Write(RichEdit1, "This text is blue", clSilver);
Write(RichEdit1, "This text is blue", clBlack);

Button1 = new TButton(this);
Button1->Parent = this;
Button1->Top = RichEdit1->Top + RichEdit1->Height + 20;
Button1->Width = 150;
Button1->Left = RichEdit1->Left;
Button1->Height = 50;
Button1->Caption = "Draw on RichEdit";
Button1->OnClick = Button1Click;

// Sort Button 2
Button2 = new TButton(this);
Button2->Parent = this;
Button2->Top = RichEdit1->Top + RichEdit1->Height + 20;
Button2->Width = 150;
Button2->Left = Button1->Left + Button1->Width;
Button2->Height = 50;
Button2->Caption = "Sort Ascending";
Button2->OnClick = Button2Click;

// Sort Button 2
Button3 = new TButton(this);
Button3->Parent = this;
Button3->Top = RichEdit1->Top + RichEdit1->Height + 20;
Button3->Width = 150;
Button3->Left = Button2->Left + Button2->Width;
Button3->Height = 50;
Button3->Caption = "Sort Descending";
Button3->OnClick = Button3Click;


Vector.push_back("g0.bmp");
Vector.push_back("g1.bmp");
Vector.push_back("g2.bmp");
Vector.push_back("g3.bmp");
Vector.push_back("g4.bmp");
Vector.push_back("g5.bmp");
Vector.push_back("g6.bmp");
Vector.push_back("g7.bmp");
Vector.push_back("g8.bmp");
Vector.push_back("g9.bmp");

Vector.push_back("g10.bmp");
Vector.push_back("g11.bmp");
Vector.push_back("g12.bmp");
Vector.push_back("g13.bmp");
Vector.push_back("g14.bmp");
Vector.push_back("g15.bmp");
Vector.push_back("g16.bmp");
Vector.push_back("g17.bmp");
Vector.push_back("g18.bmp");
Vector.push_back("g19.bmp");
/*
Vector.push_back("g20.bmp");
Vector.push_back("g21.bmp");
Vector.push_back("g22.bmp");
Vector.push_back("g23.bmp");
Vector.push_back("g24.bmp");
Vector.push_back("g25.bmp");
Vector.push_back("g26.bmp");
Vector.push_back("g27.bmp");
Vector.push_back("g28.bmp");
Vector.push_back("g29.bmp");

Vector.push_back("g30.bmp");
Vector.push_back("g31.bmp");
Vector.push_back("g32.bmp");
Vector.push_back("g33.bmp");
Vector.push_back("g34.bmp");
Vector.push_back("g35.bmp");
Vector.push_back("g36.bmp");
Vector.push_back("g37.bmp");
Vector.push_back("g38.bmp");
Vector.push_back("g39.bmp");

Vector.push_back("g40.bmp");
Vector.push_back("g41.bmp");
Vector.push_back("g42.bmp");
Vector.push_back("g43.bmp");
Vector.push_back("g44.bmp");
Vector.push_back("g45.bmp");
Vector.push_back("g46.bmp");
Vector.push_back("g47.bmp");
Vector.push_back("g48.bmp");
Vector.push_back("g49.bmp");

Vector.push_back("g50.bmp");
Vector.push_back("g51.bmp");
Vector.push_back("g52.bmp");
Vector.push_back("g53.bmp");
Vector.push_back("g54.bmp");
Vector.push_back("g55.bmp");
Vector.push_back("g56.bmp");
Vector.push_back("g57.bmp");
Vector.push_back("g58.bmp");
Vector.push_back("g59.bmp");

Vector.push_back("g60.bmp");
Vector.push_back("g61.bmp");
Vector.push_back("g62.bmp");
Vector.push_back("g63.bmp");
Vector.push_back("g64.bmp");
Vector.push_back("g65.bmp");
Vector.push_back("g66.bmp");
Vector.push_back("g67.bmp");
Vector.push_back("g68.bmp");
Vector.push_back("g69.bmp");
*/
}

void __fastcall TForm1::Button1Click(TObject *Sender)
{
static bool firstTime = true;
int itemCount = 0;
int rowCount = 0;
int colCount = 0;



for(vector<AnsiString>::size_type i = 0 ; i != Vector.size(); i++)
{
if (((itemCount+1)*IMAGE_SIZE) > RichEdit1->Width)
{
rowCount = rowCount + IMAGE_SIZE;

if (rowCount + IMAGE_SIZE > RichEdit1->Height )
{
// Rich Edit is not tall enough
// cannot fit the images in RichEdit
break;
}

colCount = 0;
itemCount = 0;
}
if (firstTime)
{
p[i] = new TImage(RichEdit1);
p[i]->Width = 0;
p[i]->Height = 0;
p[i]->Parent = RichEdit1;
p[i]->Visible = false;
}
p[i]->Top = rowCount;
p[i]->Left = colCount * IMAGE_SIZE;
p[i]->Height = IMAGE_SIZE;
p[i]->Width = IMAGE_SIZE;
p[i]->Picture->LoadFromFile( "C:\Graphics\" + Vector[i] );
p[i]->Visible = true;

itemCount++;
colCount++;
}

firstTime = false;

}
//--------------------------------------------------------------------------
-
void __fastcall TForm1::Button2Click(TObject *Sender)
{
// Ascending Order
SortVector(Vector, Compare_GreaterThan);
Button1Click(Sender);
}

void __fastcall TForm1::Button3Click(TObject *Sender)
{
//Descending Order
SortVector(Vector, Compare_LessThan);
Button1Click(Sender);
}

Rodolfo
"sphinxing" <sphinxing (AT) 163 (DOT) com> wrote

Quote:
Sorry, I think Remy is right, that code can't help me.


Your solution is a hack at best. All it does it overlays a TImage on
top
of
the TRchEdit. You don't take scolling into account at all. You don't
take
the user selecting the RichEdit content into account at all. You do not
take copy/paste into account at all. These are all things that sphinx
stated he needs (ok, not the scrolling part, but that is needed anyway).
I
do not see how your solution can be applied to what he has described,
not
even close.


Gambit





Back to top
Remy Lebeau (TeamB)
Guest





PostPosted: Fri Dec 12, 2003 6:44 pm    Post subject: Re: How can i display pictures/icons in TMemo Reply with quote


"Rodolfo Frino" <MenInBlack (AT) nowhere (DOT) com> wrote

Quote:
Use this one then

I think you are completely missing the point here. Your solution to use
TImage *will not solve the situation* that has been described. In fact,
your code now doesn't even *address* the original problem at all!


Gambit



Back to top
Remy Lebeau (TeamB)
Guest





PostPosted: Fri Dec 12, 2003 6:45 pm    Post subject: Re: How can i display pictures/icons in TMemo Reply with quote


"sphinxing" <sphinxing (AT) 163 (DOT) com> wrote

Quote:
It seems that I must use Richedit. But I really have no idea
about OLE, interfaces etc. I'm just a beginner:-(

Please go to the site I directed you to earlier, it has all of that
information available, and already has pre-written code to handle placing
images in RichEdit for you.


Gambit



Back to top
sphinxing
Guest





PostPosted: Sat Dec 13, 2003 11:13 am    Post subject: Re: How can i display pictures/icons in TMemo Reply with quote

OK, thank you. I'll try to study those codes myself.


Back to top
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> C++ Builder (VCL Components Development) All times are GMT
Goto page 1, 2  Next
Page 1 of 2

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.