正确代码:
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;
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;
private
MDIDefProc:pointer;
MDIInstance:TFarProc;
procedure MDIWndProc(var prmMsg:TMessage);
protected
procedure CreateWnd; override;
public
end;procedure Tfrm_Main.CreateWnd;
begin
inherited CreateWnd;
MDIInstance:=MakeObjectInstance(MDIWndProc); { create wrapper }
MDIDefProc:=pointer(SetWindowLong(ClientHandle,GWL_WNDPROC,
longint(MDIInstance)) );
end;procedure Tfrm_Main.MDIWndProc(var prmMsg: TMessage);
begin
with prmMsg do
if Msg = WM_ERASEBKGND then
// Snakeguo(楠) 的代码
else
Result:=CallWindowProc(MDIDefProc,ClientHandle,Msg,wParam,lParam);
end;
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
OutlookBtn, ToolWin, ComCtrls, ExtCtrls, Db, ADODB;type
Tfrmmain = class(TForm);
Image1: TImage;
private
FClientInstance,FPrevClientProc : TFarProc;
procedure ClientWndProc(VAR Message: TMessage);
{ Private declarations }
public
{ Public declarations }
end;var
frmmain: Tfrmmain;
implementation
{$R *.DFM}
procedure Tfrmmain.ClientWndProc(VAR Message: TMessage);
var mydc:hdc;
row,col:integer;
begin
with message do
case msg of WM_ERASEBKGND:
begin
MyDC := TWMEraseBkGnd(Message).DC;
FOR Row := 0 TO ClientHeight DIV Image1.Picture.Height DO
FOR Col := 0 TO ClientWIDTH DIV Image1.Picture.Width DO
BitBlt(MyDC,
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(FPrevClientProc,ClientHandle,Msg,wParam,lParam);
end;
end;procedure Tfrmmain.FormCreate(Sender: TObject);
begin
FClientInstance := MakeObjectInstance(ClientWndProc);
FPrevClientProc := Pointer(GetWindowLong(ClientHandle,GWL_WNDPROC));
SetWindowLong(ClientHandle,GWL_WNDPROC,LongInt(FClientInstance));
frmmain.WindowState:=wsmaximized;
end;