MDI main form 인 TForm1의 WM_ERASEBKGND, WM_VSCROLL, WM_HSCROLL를 받아서 배경을
image로 그리는 예제 입니다.
type
TForm1 = class( TForm )
...
private
{ Private declarations }
public
{ Public declarations }
procedure ClientWndProc( var Message : TMessage );
procedure DrawImage;
protected
procedure CreateWnd; override;
end;
var
Form1 : TForm1;
NewClient,
OldClient : TFarProc;
MyDC : hDC;
implementation
uses
unit2;
{$R *.DFM}
procedure TForm1.CreateWnd;
begin
inherited CreateWnd;
// 메시지 처리를 위해 WndProc을 교체한다
NewClient := MakeObjectInstance( ClientWndProc );
OldClient := Pointer( GetWindowLong( ClientHandle, GWL_WNDPROC ) );
SetWindowLong( ClientHandle, GWL_WNDPROC, LongInt( NewClient ) );
end;
// MDI main form에 Image를 그려주는 함수
// - 이 함수에서 사용하는 Image1이 Form위에 올려져 있어야 한다
procedure TForm1.DrawImage;
var
i,
j : Integer;
Rows,
Cols : Integer;
WndRect,
ImageRect : TRect;
begin
GetWindowRect( ClientHandle, WndRect );
ImageRect := Image1.ClientRect;
Rows := WndRect.Bottom div ImageRect.Bottom;
Cols := WndRect.Right div ImageRect.Right;
with Image1 do
for i := 0 to Rows + 1 do
for j := 0 to Cols + 1 do
BitBlt( MyDC, j * Picture.Width,i * Picture.Height,Picture.Width,
Picture.Height,Picture.Bitmap.Canvas.Handle, 0, 0, SRCCOPY );
end;
procedure TForm1.ClientWndProc( var Message : TMessage );
begin
case Message.Msg of
WM_ERASEBKGND :
begin
CallWindowProc( OldClient, ClientHandle, Message.Msg, Message.wParam, Message.lParam );
MyDC := TWMEraseBkGnd( Message ).DC;
DrawImage;
Message.Result := 1;
end;
WM_VSCROLL,
WM_HSCROLL:
begin
Message.Result := CallWindowProc( OldClient, ClientHandle, Message.Msg, Message.wParam,
Message.lParam );
InvalidateRect( ClientHandle, nil, True );
end;
else
Message.Result := CallWindowProc( OldClient, ClientHandle, Message.Msg, Message.wParam,
Message.lParam );
end;
end;
|