MDI主窗口加图片(strectch)

将Form1的FormStyle设置为fsMDIForm,设置成MDI的主窗口。
加入image1,并调入一幅图片

在Form1的Private中定义:
FClientInstance,FPrevClientProc : TFarProc;
PROCEDURE ClientWndProc(VAR Message: TMessage);

在Form1的创建事件中加入:
FClientInstance := MakeObjectInstance(ClientWndProc);
FPrevClientProc := Pointer(GetWindowLong(ClientHandle, GWL_WNDPROC));
SetWindowLong(ClientHandle, GWL_WNDPROC, LongInt(FClientInstance));


实现过程:
PROCEDURE TForm1.ClientWndProc(VAR Message: TMessage);
VAR
  CanvasClient:TCanvas;
begin
with Message do
case Msg of
WM_ERASEBKGND:
  begin
    CanvasClient:=Tcanvas.Create;
    CanvasClient.Handle:=GetDC(self.ClientHandle);
    CanvasClient.StretchDraw(rect(0,0,clientwidth,clientheight),image1.Picture.Bitmap);
    CanvasClient.Free;
  end;
else
  Result := CallWindowProc(FPrevClientProc, ClientHandle, Msg, wParam, lParam);
end;

end;