procedure TMainForm.CreateWnd;
begin
inherited CreateWnd;
// Turn the ClientWndProc method into a valid window procedure
FNewClientProc := MakeObjectInstance(ClientWndProc);
// Get a pointer to the original window procedure
FOldClientProc := Pointer(GetWindowLong(ClientHandle, GWL_WNDPROC));
// Set ClientWndProc as the new window procedure
SetWindowLong(ClientHandle, GWL_WNDPROC, LongInt(FNewClientProc));
end;procedure TMainForm.DrawCentered;
{ This procedure centers the image on the form's client area }
var
CR: TRect;
begin
GetWindowRect(ClientHandle, CR);
with imgMain do
BitBlt(FDrawDC, ((CR.Right - CR.Left) - Picture.Width) div 2,
((CR.Bottom - CR.Top) - Picture.Height) div 2,
Picture.Graphic.Width, Picture.Graphic.Height,
Picture.Bitmap.Canvas.Handle, 0, 0, SRCCOPY);
end;
begin
inherited CreateWnd;
// Turn the ClientWndProc method into a valid window procedure
FNewClientProc := MakeObjectInstance(ClientWndProc);
// Get a pointer to the original window procedure
FOldClientProc := Pointer(GetWindowLong(ClientHandle, GWL_WNDPROC));
// Set ClientWndProc as the new window procedure
SetWindowLong(ClientHandle, GWL_WNDPROC, LongInt(FNewClientProc));
end;procedure TMainForm.DrawCentered;
{ This procedure centers the image on the form's client area }
var
CR: TRect;
begin
GetWindowRect(ClientHandle, CR);
with imgMain do
BitBlt(FDrawDC, ((CR.Right - CR.Left) - Picture.Width) div 2,
((CR.Bottom - CR.Top) - Picture.Height) div 2,
Picture.Graphic.Width, Picture.Graphic.Height,
Picture.Bitmap.Canvas.Handle, 0, 0, SRCCOPY);
end;
private
foldclientproc,fnewclientproc:tfarproc;
fdrawdc:hdc;
procedure drawtiled;
procedure clientwndproc(var message:tmessage);
procedure createwnd;override;
{ Private declarations }
public
...
procedure tmain.createwnd;
begin
inherited createwnd;
fnewclientproc:=makeobjectinstance(clientwndproc);
foldclientproc:=pointer(getwindowlong(clienthandle,gwl_wndproc));
setwindowlong(clienthandle,gwl_wndproc,longint(fnewclientproc));
end;procedure tmain.clientwndproc(var message:tmessage);
begin
case message.Msg of
wm_erasebkgnd:
begin
callwindowproc(foldclientproc,clienthandle,message.msg,message.wparam,message.lparam);
fdrawdc:=twmerasebkgnd(message).dc;
drawtiled;
message.Result:=1;
end;
wm_vscroll,wm_hscroll:
begin
message.Result:=callwindowproc(foldclientproc,clienthandle,message.msg,message.wparam,message.lparam);
invalidaterect(clienthandle,nil,true);
end;
else
message.Result:=callwindowproc(foldclientproc,clienthandle,message.msg,message.wparam,message.lparam);
end;
end;procedure tmain.drawtiled;
var
row,col:integer;
cr,ir:trect;
numrows,numcols:integer;
begin
getwindowrect(clienthandle,cr);
ir:=image1.clientrect;
numrows:=cr.bottom div ir.bottom;
numcols:=cr.right div ir.right;
with image1 do
for row:=0 to 4 do
for col:=0 to 7 do
bitblt(fdrawdc,col*picture.width,row*picture.height,picture.width,picture.height,picture.bitmap.canvas.handle,0,0,srccopy);
end;