希望对你有帮助PROCEDURE TFrmMain.ClientWndProc(VAR AMessage: TMessage); VAR MyDC : hDC; Ro, Co : Word; begin case AMessage.Msg of WM_ERASEBKGND: begin MyDC := TWMEraseBkGnd(AMessage).DC; { if (Screen.Width = 800) and(Screen.Height = 600) then begin FOR Ro := 0 TO ClientHeight DIV Image1.Picture.Height DO FOR Co := 0 TO ClientWIDTH DIV Image1.Picture.Width DO BitBlt(MyDC, Co*Image1.Picture.Width, Ro*Image1.Picture.Height, Image1.Picture.Width, Image1.Picture.Height, Image1.Picture.Bitmap.Canvas.Handle, 0, 0, SRCCOPY); end else begin //1024 * 768 or other } with Image1.Picture.Bitmap do StretchBlt(MyDC, 0,0,Self.ClientWidth, Self.ClientHeight-panel2.Height, Canvas.Handle, 0, 0, Width, Height, SRCCOPY); // end; AMessage.Result := 1; end else AMessage.Result := CallWindowProc(FPrevClientProc, ClientHandle, AMessage.Msg, AMessage.wParam, AMessage.lParam); end; end;
第一步:打开Delphi(Delphi 1,2,3都可以),创建一个新的工程。 第二步:将Form1的FormStyle设置为fsMDIForm,设置成MDI的主窗口。 第三步:在Form1上增加一个Image元件,并选择要设置的背景到Image的Picture中。 第四步:在Form1的Private中定义: FClientInstance, FPrevClientProc : TFarProc; PROCEDURE ClientWndProc(VAR Message: TMessage); 第五步:在实现(implementation)中加入上述过程的具体内容: PROCEDURE TForm1.ClientWndProc(VAR Message: TMessage); VAR MyDC : hDC; Ro, Co : Word; begin with Message do case Msg of WM_ERASEBKGND: begin MyDC := TWMEraseBkGnd(Message).DC; FOR Ro := 0 TO ClientHeight DIV Image1.Picture.Height DO FOR Co := 0 TO ClientWIDTH DIV Image1.Picture.Width DO BitBlt(MyDC, Co*Image1.Picture.Width, Ro*Image1.Picture.Height, Image1.Picture.Width, Image1.Picture.Height, Image1.Picture.Bitmap.Canvas.Handle, 0, 0, SRCCOPY); Result := 1; end; else Result := CallWindowProc(FPrevClientProc, ClientHandle, Msg, wParam, lParam); end; end; 第六步:在Form1的创建事件中加入: FClientInstance := MakeObjectInstance(ClientWndProc); FPrevClientProc := Pointer(GetWindowLong(ClientHandle, GWL_WNDPROC)); SetWindowLong(ClientHandle, GWL_WNDPROC, LongInt(FClientInstance)); 上面的步骤已经完成了MDI主窗口背景图案的设置,下面可以增加一个MDIChild窗口,实现MDI程序。 第七步:新增加一个Form,并将FormStyle设置为fsMDIChild。
很你的问题有点相关,使用的是重画的方法。
VAR
MyDC : hDC;
Ro, Co : Word;
begin
case AMessage.Msg of
WM_ERASEBKGND:
begin
MyDC := TWMEraseBkGnd(AMessage).DC;
{ if (Screen.Width = 800)
and(Screen.Height = 600) then
begin
FOR Ro := 0 TO ClientHeight DIV Image1.Picture.Height DO
FOR Co := 0 TO ClientWIDTH DIV Image1.Picture.Width DO
BitBlt(MyDC, Co*Image1.Picture.Width, Ro*Image1.Picture.Height,
Image1.Picture.Width, Image1.Picture.Height,
Image1.Picture.Bitmap.Canvas.Handle, 0, 0, SRCCOPY);
end
else begin //1024 * 768 or other }
with Image1.Picture.Bitmap do
StretchBlt(MyDC, 0,0,Self.ClientWidth,
Self.ClientHeight-panel2.Height,
Canvas.Handle, 0, 0, Width, Height, SRCCOPY);
// end;
AMessage.Result := 1;
end
else
AMessage.Result := CallWindowProc(FPrevClientProc, ClientHandle,
AMessage.Msg, AMessage.wParam, AMessage.lParam);
end;
end;
第三步:在Form1上增加一个Image元件,并选择要设置的背景到Image的Picture中。
第四步:在Form1的Private中定义:
FClientInstance,
FPrevClientProc : TFarProc;
PROCEDURE ClientWndProc(VAR Message: TMessage);
第五步:在实现(implementation)中加入上述过程的具体内容:
PROCEDURE TForm1.ClientWndProc(VAR Message: TMessage);
VAR
MyDC : hDC;
Ro, Co : Word;
begin with Message do
case Msg of
WM_ERASEBKGND:
begin
MyDC := TWMEraseBkGnd(Message).DC;
FOR Ro := 0 TO ClientHeight DIV Image1.Picture.Height DO
FOR Co := 0 TO ClientWIDTH DIV Image1.Picture.Width DO
BitBlt(MyDC, Co*Image1.Picture.Width, Ro*Image1.Picture.Height,
Image1.Picture.Width, Image1.Picture.Height,
Image1.Picture.Bitmap.Canvas.Handle, 0, 0, SRCCOPY);
Result := 1;
end;
else Result := CallWindowProc(FPrevClientProc, ClientHandle, Msg, wParam, lParam);
end;
end; 第六步:在Form1的创建事件中加入:
FClientInstance := MakeObjectInstance(ClientWndProc);
FPrevClientProc := Pointer(GetWindowLong(ClientHandle, GWL_WNDPROC));
SetWindowLong(ClientHandle, GWL_WNDPROC, LongInt(FClientInstance)); 上面的步骤已经完成了MDI主窗口背景图案的设置,下面可以增加一个MDIChild窗口,实现MDI程序。 第七步:新增加一个Form,并将FormStyle设置为fsMDIChild。