下面的方法绝对行,你参巧下<1>在窗体上添加一个Image,加入要显示的图片. <2>在private中加入 FClientInstance, FPrevClientProc : TFarProc; procedure ClientWndProc(var Message: TMessage); <3>加入以下过程 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; <4>在FormCreate中加入以下代码 FClientInstance := MakeObjectInstance(ClientWndProc); FPrevClientProc := Pointer(GetWindowLong(ClientHandle, GWL_WNDPROC)); SetWindowLong(ClientHandle, GWL_WNDPROC, LongInt(FClientInstance));
to lfpsoft(聪聪) : 你的方法只能实现图片平铺的效果,我是想让整个图片充满窗体。 我修改以上函数后已经实现procedure TfrmMain.DrawStretched; { This procedure stretches the image on the form's client area } var CR: TRect; begin GetWindowRect(ClientHandle, CR); SetStretchBltMode(FDrawDC, WHITEONBLACK) ; StretchBlt(FDrawDC, 0, 0, CR.Right - CR.Left , CR.Bottom - CR.Top, imgMain.Picture.Bitmap.Canvas.Handle, 0, 0, imgMain.Picture.Width, imgMain.Picture.Height, SRCCOPY) ; end; 现在还有一个问题是,在切换左边列表时,图片会有点闪烁,不知该怎么解决才好? 另,已经将FrmMain.DoubleBuffered := true ; 但是好象效果不是很好,请问还有什么别的方法?谢谢!
autosize := true ;还是不行。
autosize := true ;
loadfromfile()
<2>在private中加入
FClientInstance,
FPrevClientProc : TFarProc;
procedure ClientWndProc(var Message: TMessage);
<3>加入以下过程
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;
<4>在FormCreate中加入以下代码
FClientInstance := MakeObjectInstance(ClientWndProc);
FPrevClientProc := Pointer(GetWindowLong(ClientHandle, GWL_WNDPROC));
SetWindowLong(ClientHandle, GWL_WNDPROC, LongInt(FClientInstance));
你的方法只能实现图片平铺的效果,我是想让整个图片充满窗体。
我修改以上函数后已经实现procedure TfrmMain.DrawStretched;
{ This procedure stretches the image on the form's client area }
var
CR: TRect;
begin
GetWindowRect(ClientHandle, CR);
SetStretchBltMode(FDrawDC, WHITEONBLACK) ;
StretchBlt(FDrawDC, 0, 0, CR.Right - CR.Left , CR.Bottom - CR.Top,
imgMain.Picture.Bitmap.Canvas.Handle, 0, 0,
imgMain.Picture.Width, imgMain.Picture.Height, SRCCOPY) ;
end;
现在还有一个问题是,在切换左边列表时,图片会有点闪烁,不知该怎么解决才好?
另,已经将FrmMain.DoubleBuffered := true ; 但是好象效果不是很好,请问还有什么别的方法?谢谢!
但现在无法给你。需要重载窗口函数,然后在自己的窗口程序中画图。
fDrawDC;hDC;
procedure ClientWndProc(var message:TMessage);
procedure Draw_Stretch;
procedure CreateWnd;override;...... ......procedure TFormMdi.CreateWnd;
begin
inherited CreateWnd;
fNewProc:=MakeObjectInstance(ClientWndProc);
fOldProc:=Pointer(GetWindowLong(ClientHandle,GWL_WNDPROC));
SetWindowLong(ClientHandle,GWL_WNDPROC,Integer(fNewProc));
end;procedure TFormMdi.ClientWndProc(var message:TMessage); //自定义窗口处理程序
begin
case Message.Msg of
WM_ERASEBKGND:
begin
CallWindowProc(fOldProc, ClientHandle, Message.Msg, Message.wParam,Message.lParam);
fDrawDC := TWMEraseBkGnd(Message).DC;
Draw_Stretch; //拉伸画背景图
Message.Result := 1;
end;
WM_SIZE:
begin
Message.Result := CallWindowProc(fOldProc, ClientHandle, Message.Msg,Message.wParam, Message.lParam);
InvalidateRect(ClientHandle, nil, True);//刷新整个客户窗口
end;
else
Message.Result := CallWindowProc(fOldtProc, ClientHandle, Message.Msg,Message.wParam, Message.lParam);
end;
end;procedure TFormMdi.Draw_Stretch;
var
Rc:TRect;
begin
GetWindowRect(ClientHandle,Rc);
StretchBlt(fDrawDC, 0, 0, Rc.Right, Rc.Bottom,
imgMdi.Picture.Bitmap.Canvas.Handle, 0, 0,
imgMdi.Picture.Width, imgMdi.Picture.Height, SRCCOPY);
end;
加双缓冲是设置图片控件的容器的DoubleBuffered属性?
可是这样做了好象也没什么效果