http://www.swissdelphicenter.ch/torry/showcode.php?id=1147 에 보시면 데모 다운로드 가능합니다.
단 RxRichEdit 를 설치해야 합니다.
-_- 시간이 없어서 변환은 못했습니다만 충분히 가능할 듯 하군요 ^^...
즐빌하세요.
...insert a Smiley image into a TRxRichEdit?
Author: Thomas Stutz
1 Comment to this tip [Write new comment]
[ Print tip ]
Tip Rating (20):
var
frmMain: TfrmMain;
implementation
{$R *.DFM}
{$R Smiley.res}
uses
RichEdit;
type
TEditStreamCallBack = function(dwCookie: Longint; pbBuff: PByte;
cb: Longint; var pcb: Longint): DWORD;
stdcall;
TEditStream = record
dwCookie: Longint;
dwError: Longint;
pfnCallback: TEditStreamCallBack;
end;
type
TMyRichEdit = TRxRichEdit;
// EditStreamInCallback callback function
function EditStreamInCallback(dwCookie: Longint; pbBuff: PByte;
cb: Longint; var pcb: Longint): DWORD; stdcall;
var
theStream: TStream;
dataAvail: LongInt;
begin
theStream := TStream(dwCookie);
with theStream do
begin
dataAvail := Size - Position;
Result := 0;
if dataAvail <= cb then
begin
pcb := read(pbBuff^, dataAvail);
if pcb <> dataAvail then
Result := UINT(E_FAIL);
end
else
begin
pcb := read(pbBuff^, cb);
if pcb <> cb then
Result := UINT(E_FAIL);
end;
end;
end;
// Insert Stream into RichEdit
procedure PutRTFSelection(RichEdit: TMyRichEdit; SourceStream: TStream);
var
EditStream: TEditStream;
begin
with EditStream do
begin
dwCookie := Longint(SourceStream);
dwError := 0;
pfnCallback := EditStreamInCallBack;
end;
RichEdit.Perform(EM_STREAMIN, SF_RTF or SFF_SELECTION, Longint(@EditStream));
end;
// Load a smiley image from resource
function GetSmileyCode(ASimily: string): string;
var
dHandle: THandle;
pData, pTemp: PChar;
Size: Longint;
begin
pData := nil;
dHandle := FindResource(hInstance, PChar(ASimily), RT_RCDATA);
if dHandle <> 0 then
begin
Size := SizeofResource(hInstance, dHandle);
dhandle := LoadResource(hInstance, dHandle);
if dHandle <> 0 then
try
pData := LockResource(dHandle);
if pData <> nil then
try
if pData[Size - 1] = #0 then
begin
Result := StrPas(pTemp);
end
else
begin
pTemp := StrAlloc(Size + 1);
try
StrMove(pTemp, pData, Size);
pTemp[Size] := #0;
Result := StrPas(pTemp);
finally
StrDispose(pTemp);
end;
end;
finally
UnlockResource(dHandle);
end;
finally
FreeResource(dHandle);
end;
end;
end;
procedure InsertSmiley(ASmiley: string);
var
ms: TMemoryStream;
s: string;
begin
ms := TMemoryStream.Create;
try
s := GetSmileyCode(ASmiley);
if s <> '' then
begin
ms.Seek(0, soFromEnd);
ms.Write(PChar(s)^, Length(s));
ms.Position := 0;
PutRTFSelection(frmMain.RXRichedit1, ms);
end;
finally
ms.Free;
end;
end;
procedure TfrmMain.SpeedButton1Click(Sender: TObject);
begin
InsertSmiley('Smiley1');
end;
procedure TfrmMain.SpeedButton2Click(Sender: TObject);
begin
InsertSmiley('Smiley2');
end;
// Replace a :-) or :-( with a corresponding smiley
procedure TfrmMain.RxRichEdit1KeyPress(Sender: TObject; var Key: Char);
var
sCode, SmileyName: string;
procedure RemoveText(RichEdit: TMyRichEdit);
begin
with RichEdit do
begin
SelStart := SelStart - 2;
SelLength := 2;
SelText := '';
end;
end;
begin
If (Key = ')') or (Key = '(') then
begin
sCode := Copy(RxRichEdit1.Text, RxRichEdit1.SelStart-1, 2) + Key;
SmileyName := '';
if sCode = ':-)' then SmileyName := 'Smiley1';
if sCode = ':-(' then SmileyName := 'Smiley2';
if SmileyName <> '' then
begin
Key := #0;
RemoveText(RxRichEdit1);
InsertSmiley('Smiley1');
end;
end;
end;
utime.김성하 님이 쓰신 글 :
: 안녕하세요 utime.김성하 입니다.
: 네이트온이나 Msn 메신저의 에디터 기능을 구현하려 합니다.
:
: 지난번 이 관련되어 질문을 드렸는데 어느 분께서 TWebBrowser Compnent를 이용해서 html로 처리하는게 편하다고 하시더군요
:
: 그런데 살펴 보니 TWebBrowser 는 M$ IE를 이용해서 그냥 뷰어 정도 가능한 것 같은데 TWebBrowser에서 메신져 처럼 에디팅이 가능 한가요?
:
: 참고로 네이트 온은 SoftWeb_Control이란 클래스를, Msn은 RichEdit20W 라는 클래스를 쓰던데 이 클래스에 관련된 참고할 만한 자료가 있는지요...
:
: 답변 부탁 드립니다~ ^^;