... private FClientInstance : TFarProc; FPrevClientProc : TFarProc; procedure ClientWndProc(var message:TMessage); ... procedure TMForm.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 ImgMain.Picture.Height do for Col := 0 to ClientWidth div ImgMain.Picture.Width do BitBlt(Dc, Col * ImgMain.Picture.Width, Row * ImgMain.Picture.Height, ImgMain.Picture.Width, ImgMain.Picture.Height, ImgMain.Picture.Bitmap.Canvas.Handle, 0, 0, SRCCOPY); Result := 1; end; else Result := CallWindowProc(FPrevClientProc, ClientHandle, Msg, wParam, lParam); end; end; procedure TMForm.FormCreate(Sender: TObject); begin FClientInstance := MakeObjectInstance(ClientWndProc); FPrevClientProc := Pointer(GetWindowLong(ClientHandle,GWL_WNDPROC)); SetWindowLong(ClientHandle,GWL_WNDPROC, LongInt(FClientInstance)); end;
//NewWinProc :=MakeObjectInstance(NewWinProcedure); //OldWinProc :=Pointer (SetWindowLong (ClientHandle,gwl_WndProc,Cardinal (NewWinProc))); //Canvas :=TCanvas.Create; {procedure TMainForm.NewWinProcedure(var Msg: TMessage); var BmpWidth,BmpHeight: Integer; I,J: Integer; begin //TODO -o: 在Client窗体上接受消息画图片 Msg.Result :=CallWindowProc(OldWinProc,ClientHandle, Msg.Msg,Msg.WParam,Msg.LParam); if Msg.Msg = wm_EraseBkgnd then begin BmpWidth :=MainForm.ImgClient.Width; BmpHeight :=MainForm.ImgClient.Height; if (BmpWidth <> 0) and (BmpHeight <> 0)then Canvas.Handle :=Msg.WParam; for I := 0 to MainForm.ClientWidth div BmpWidth do for J := 0 to MainForm.ClientHeight div BmpHeight do Canvas.Draw(I * BmpWidth,J* BmpHeight,MainForm.ImgClient.Picture.Graphic); end; end; }
FPrevClientProc : TFarProc;
procedure ClientWndProc(var message:TMessage);
...
procedure TMForm.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 ImgMain.Picture.Height do
for Col := 0 to ClientWidth div ImgMain.Picture.Width do
BitBlt(Dc,
Col * ImgMain.Picture.Width,
Row * ImgMain.Picture.Height,
ImgMain.Picture.Width,
ImgMain.Picture.Height,
ImgMain.Picture.Bitmap.Canvas.Handle,
0,
0,
SRCCOPY);
Result := 1;
end;
else
Result := CallWindowProc(FPrevClientProc,
ClientHandle,
Msg,
wParam,
lParam);
end;
end;
procedure TMForm.FormCreate(Sender: TObject);
begin
FClientInstance := MakeObjectInstance(ClientWndProc);
FPrevClientProc := Pointer(GetWindowLong(ClientHandle,GWL_WNDPROC));
SetWindowLong(ClientHandle,GWL_WNDPROC, LongInt(FClientInstance));
end;
//OldWinProc :=Pointer (SetWindowLong (ClientHandle,gwl_WndProc,Cardinal (NewWinProc)));
//Canvas :=TCanvas.Create;
{procedure TMainForm.NewWinProcedure(var Msg: TMessage);
var
BmpWidth,BmpHeight: Integer;
I,J: Integer;
begin
//TODO -o: 在Client窗体上接受消息画图片
Msg.Result :=CallWindowProc(OldWinProc,ClientHandle,
Msg.Msg,Msg.WParam,Msg.LParam);
if Msg.Msg = wm_EraseBkgnd then
begin
BmpWidth :=MainForm.ImgClient.Width;
BmpHeight :=MainForm.ImgClient.Height;
if (BmpWidth <> 0) and (BmpHeight <> 0)then
Canvas.Handle :=Msg.WParam;
for I := 0 to MainForm.ClientWidth div BmpWidth do
for J := 0 to MainForm.ClientHeight div BmpHeight do
Canvas.Draw(I * BmpWidth,J* BmpHeight,MainForm.ImgClient.Picture.Graphic);
end;
end; }
procedure aaa(var message:TMessage); message WM_ERASEBKGND;然后在此过程里显示图片, 这样好像只是在FORM上闪了一下.我是菜鸟, 哪位能帮我解释一下我的这种方式跟z_hongbao说的重写窗体函数方式有什么不同?
TfrmMain.FormCreate(Sender: TObject);
begin
Self.Brush.Bitmap := Image1.Picture.Bitmap;
end;
在FORM上放一个IMAGE(将VISIBLE设为FALSE),并加载一幅图
(必须是BMP),在ONSHOW中添加代码:
procedure TForm1.FormShow(Sender: TObject);
begin
Brush.Bitmap := Image1.Picture.Bitmap;
end;
不就可以了吗,费那个尽干什么