Bagaimanakah cara memberikan background image pada form MDI di Delphi, seperti pada gambar?
unit UMain;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, jpeg;
type
TFrmMDI = class(TForm)
Image1: TImage;
private
{ Private declarations }
FDrawDC: HDC;
FOldClientProc, FNewClientProc: TFarProc;
procedure DrawStretched;
procedure DrawCentered;
procedure DrawTiled;
procedure CreateWnd; override;
procedure ClientWndProc(var Mesg: TMessage);
public
{ Public declarations }
end;
var
FrmMDI: TFrmMDI;
implementation
{$R *.dfm}
procedure TFrmMDI.ClientWndProc(var Mesg: TMessage);
begin
with Mesg do
case Msg of
WM_ERASEBKGND:
begin
CallWindowProc(FOldClientProc, ClientHandle, Msg, wParam, lParam);
FDrawDC := TWMEraseBkgnd(Mesg).DC;
// anda dapat memilih DrawCentered, DrawTiled, DrawStretched
// DrawCentered;
DrawTiled;
// DrawStretched;
Result := 1;
end;
WM_VSCROLL, WM_HSCROLL:
begin
Result := CallWindowProc(FOldClientProc, ClientHandle, Msg, wParam,
lParam);
InvalidateRect(ClientHandle, nil, True);
end;
else
Result := CallWindowProc(FOldClientProc, ClientHandle, Msg, wParam,
lParam);
end;
end;
procedure TFrmMDI.CreateWnd;
begin
inherited CreateWnd;
FNewClientProc:= MakeObjectInstance(ClientWndProc);
FOldClientProc:= Pointer(GetWindowLong(ClientHandle, GWL_WNDPROC));
SetWindowLong(ClientHandle, GWL_WNDPROC, LongInt(FNewClientProc));
end;
procedure TFrmMDI.DrawCentered;
var
CR: TRect;
begin
GetWindowRect(ClientHandle, CR);
with Image1 do
BitBlt(FDrawDC, 50, 50, Picture.Graphic.Width, Picture.Graphic.Height,
Picture.Bitmap.Canvas.Handle, 0, 0, SRCCOPY);
end;
procedure TFrmMDI.DrawStretched;
var
CR: TRect;
begin
GetWindowRect(ClientHandle, CR);
StretchBlt(FDrawDC, 0, 0, CR.Right, CR.Bottom, Image1.Picture.Bitmap.Canvas.Handle, 0, 0,
Image1.Picture.Width, Image1.Picture.Height, SRCCOPY);
end;
procedure TFrmMDI.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 NumRows + 1 do
for Col:= 0 to NumCols + 1 do
BitBlt(FDrawDC, Col * Picture.Width, Row * Picture.Height,
Picture.Width, Picture.Height, Picture.Bitmap.Canvas.Handle,
0, 0, SRCCOPY);
end;
end.

Comments
Post a Comment