...
{ Private declarations }
bmW, bmH : Integer;
FClientInstance,
FPrevClientProc : TFarProc;
PROCEDURE ClientWndProc(VAR Message: TMessage);
public
PROCEDURE PaintUnderIcon(F: TForm; D: hDC);
...
PROCEDURE TForm1.PaintUnderIcon(F: TForm; D: hDC);
VAR
DestR, WndR : TRect;
Ro, Co,
xOfs, yOfs,
xNum, yNum : Integer;
BEGIN
{вычисляем необходимое число изображений для заливки D}
GetClipBox(D, DestR);
WITH DestR DO
BEGIN
xNum := Succ((Right-Left) DIV bmW);
yNum := Succ((Bottom-Top) DIV bmW);
END;
{вычисление смещения изображения в D}
GetWindowRect(F.Handle, WndR);
WITH ScreenToClient(WndR.TopLeft) DO
BEGIN
xOfs := X MOD bmW;
yOfs := Y MOD bmH;
END;
FOR Ro := 0 TO xNum DO
FOR Co := 0 TO yNum DO
BitBlt(D, Co*bmW-xOfs, Ro*bmH-Yofs, bmW, bmH,
Image1.Picture.Bitmap.Canvas.Handle,
0, 0, SRCCOPY);
END;
PROCEDURE TForm1.ClientWndProc(VAR Message: TMessage);
VAR Ro, Co : Word;
begin
with Message do
case Msg of
WM_ERASEBKGND:
begin
FOR Ro := 0 TO ClientHeight DIV bmH DO
FOR Co := 0 TO ClientWIDTH DIV bmW DO
BitBlt(TWMEraseBkGnd(Message).DC,
Co*bmW, Ro*bmH, bmW, bmH,
Image1.Picture.Bitmap.Canvas.Handle,
0, 0, SRCCOPY);
Result := 1;
end;
WM_VSCROLL,
WM_HSCROLL :
begin
Result := CallWindowProc(FPrevClientProc,
ClientHandle, Msg, wParam, lParam);
InvalidateRect(ClientHandle, NIL, True);
end;
else
Result := CallWindowProc(FPrevClientProc,
ClientHandle, Msg, wParam, lParam);
end;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
bmW := Image1.Picture.Width;
bmH := Image1.Picture.Height;
FClientInstance := MakeObjectInstance(ClientWndProc);
FPrevClientProc := Pointer(
GetWindowLong(ClientHandle, GWL_WNDPROC));
SetWindowLong(ClientHandle, GWL_WNDPROC,
LongInt(FClientInstance));
end;