给你贴个文章
应 该 响 应 WM_ERASEBKGND消 息 。
假 设 你 的 Form叫 MainForm, 其 中 有 一 个 Image1控 件 , 绘 制 的 背 景 图 片 包 括 在 这 个 控 件 中。 先 在 窗 体 定 义 中 加 入 如 下 变 量 :
FClientInstance : TFarProc;
FPrevClientProc : TFarProc;
procedure ClientWndProc(var Message: TMessage);
然 后 在 implementation部 分 加 上 :
procedure TMainForm.ClientWndProc(var Message: TMessage);
var Dc : hDC; Row : Integer; Col : Integer;
begin
with Message do
case Msg of
WM_ERASEBKGND:
begin
Dc := TWMEraseBkGnd(Message).Dc;
for Row := 0 to ClientHeight div Image1.Picture.Height do
for Col := 0 to ClientWidth div Image1.Picture.Width do
BitBlt(Dc
Col * Image1.Picture.Width
Row * Image1.Picture.Height
Image1.Picture.Width
Image1.Picture.Height
Image1.Picture.Bitmap.Canvas.Handle
0
0
SRCCOPY);
Result := 1;
end;
else
Result := CallWindowProc(FPrevClientProcClientHandleMsgwParamlParam);
end;
end;
在 OnCreate事 件 加 入 :
FClientInstance := MakeObjectInstance(ClientWndProc);
FPrevClientProc := Pointer(GetWindowLong(ClientHandle,GWL_WNDPROC));
SetWindowLong(ClientHandle,GWL_WNDPROC,LongInt(FClientInstance));
应 该 响 应 WM_ERASEBKGND消 息 。
假 设 你 的 Form叫 MainForm, 其 中 有 一 个 Image1控 件 , 绘 制 的 背 景 图 片 包 括 在 这 个 控 件 中。 先 在 窗 体 定 义 中 加 入 如 下 变 量 :
FClientInstance : TFarProc;
FPrevClientProc : TFarProc;
procedure ClientWndProc(var Message: TMessage);
然 后 在 implementation部 分 加 上 :
procedure TMainForm.ClientWndProc(var Message: TMessage);
var Dc : hDC; Row : Integer; Col : Integer;
begin
with Message do
case Msg of
WM_ERASEBKGND:
begin
Dc := TWMEraseBkGnd(Message).Dc;
for Row := 0 to ClientHeight div Image1.Picture.Height do
for Col := 0 to ClientWidth div Image1.Picture.Width do
BitBlt(Dc
Col * Image1.Picture.Width
Row * Image1.Picture.Height
Image1.Picture.Width
Image1.Picture.Height
Image1.Picture.Bitmap.Canvas.Handle
0
0
SRCCOPY);
Result := 1;
end;
else
Result := CallWindowProc(FPrevClientProcClientHandleMsgwParamlParam);
end;
end;
在 OnCreate事 件 加 入 :
FClientInstance := MakeObjectInstance(ClientWndProc);
FPrevClientProc := Pointer(GetWindowLong(ClientHandle,GWL_WNDPROC));
SetWindowLong(ClientHandle,GWL_WNDPROC,LongInt(FClientInstance));
墙纸构件,可将Form背景填充为指定图案,多种填充方式,使用简单。
2.如果是D5最简单的方法:在父窗体Form1中放入image1控件,设置好picture(必须是bmp),在Form1的OnCreate事件中加入:
Form1.Brush.Bitmap:=image1.Picture.Bitmap;
self.brush.bitmap := image1.picture.bitmap;