|
메모의 배경에 이미지를 삽입하는 델파이 소스인데
변환 꼭 부탁드립니다.
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, ExtCtrls;
type
TForm1 = class(TForm)
Memo: TMemo;
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
private
MemoOrgWndProc: TWndMethod;
FBitmap: TBitmap;
Canvas: TCanvas;
procedure MemoNewWndProc(var Message: TMessage);
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
procedure TForm1.FormCreate(Sender: TObject);
begin
Canvas := TCanvas.Create;
FBitmap := TBitmap.Create;
FBitmap.LoadFromFile('a.bmp');
FBitmap.Dormant;
MemoOrgWndProc := Memo.WindowProc;
Memo.WindowProc := MemoNewWndProc;
end;
procedure TForm1.FormDestroy(Sender: TObject);
begin
Canvas.Free;
if FBitmap <> nil then
begin
FBitmap.Free;
FBitmap := nil;
end;
end;
procedure TForm1.MemoNewWndProc(var Message: TMessage);
var
PalFlag: Boolean;
OldPal: HPALETTE;
Col, Row, X, Y: Integer;
begin
case Message.Msg of
WM_ERASEBKGND : if FBitmap <> nil then
begin
PalFlag := ( GetDeviceCaps( Message.WParam,
BITSPIXEL ) <= 8 ) and ( FBitmap.Palette <> 0 );
Canvas.Lock;
try
Canvas.Handle := Message.WParam;
try
OldPal := 0;
if PalFlag then
begin
OldPal := SelectPalette( Canvas.Handle,
FBitmap.Palette,
False );
RealizePalette( Canvas.Handle );
end;
Col := Memo.ClientWidth div FBitmap.Width;
Row := Memo.ClientHeight div FBitmap.Height;
for Y := 0 to Row do
for X := 0 to Col do
Canvas.Draw( X * FBitmap.Width,
Y * FBitmap.Height, FBitmap );
if PalFlag then
SelectPalette( Canvas.Handle, OldPal, False );
finally
Canvas.Handle := 0;
end;
finally
Canvas.Unlock;
end;
Message.Result := 1;
end;
CN_CTLCOLOREDIT: begin
MemoOrgWndProc( Message );
SetBkMode( Message.WParam, TRANSPARENT );
end;
else MemoOrgWndProc( Message );
end;
end;
end.
|