給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;