解决方案 »
- 谁有好一点的注入dll到系统进程的代码?
- 请问在非阻塞状态下ServerSocket可同时连接多少个客户端
- 如何获得FTP服务器上目录下的所有文件名和子目录
- DBComboBox+Table+DataSource出错问题》?
- Report Machine控件的打印问题
- 我在scrollbox上动态添加了按钮和edit,如何用公式全部删除?
- 关于Ado的,在线等待
- 很急~~~~~~~~!!!请看看!!5~~~~~~~~~~
- 哪儿有关于图形处理的源码,如马赛克效果、加入文本等,请各位帮个忙!
- 请问在DBGrid中应用两个DBLookupComboBox时,总是出错怎么回事啊?
- 若子窗口没有关闭,关闭MDI主窗口时就会报错
- delphi 用TFileStreamdelphi操作文件,删除文件结尾处的空字符,要这么操作,本人新手
可以用Image,也可以在OnPaint事件中画上。
比说在相应的页有下面的控件,另外在这些 控件 里放了Image1,Image1放的是背景图片(已经切成小块了)进行这样设置,可是在运行时还是很闪,请教高手?多谢
DoubleBuffered:=True;
Notebook1.DoubleBuffered := True;
Panel.DoubleBuffered:=True;
Form.Canvas.StretchDraw
安装一下控件
unit uTiler;interfaceuses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs;type
TTileMode = (tmTile, tmStretch, tmCenter, // standard Window Wallpaper tilemodes (v1.0)
tmLeftVCenter, tmLeftVTop, tmLeftVBottom, // piccy on the left (v1.2)
tmRightVCenter, tmRightVTop, tmRightVBottom, // piccy on the right (v1.2)
tmCenterVTop, tmCenterVBottom); // piccy centered (v1.2) TTiler = class(TComponent)
private
FAutomaticAttach: Boolean;
FActive: Boolean;
FBitmap: TBitmap;
FTileMode: TTileMode; FHandle: HWND;
Form: TForm; VOffset: Integer;
HOffset: Integer; FClientInstance: TFarProc;
FDefClientProc: TFarProc; procedure SetActive(Value: Boolean);
procedure SetBitmap(Value: TBitmap);
procedure SetTileMode(Value: TTileMode); procedure ClientWndProc(var Message: TMessage);
procedure FillClientArea(DC: HDC); procedure Stretch(DC: HDC);
procedure Tile(DC: HDC);
procedure Center(DC: HDC);
procedure Spot(DC: HDC); { Private declarations }
protected
procedure Loaded; override;
{ Protected declarations }
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override; procedure Attach;
procedure Detach;
procedure Redraw;
{ Public declarations }
published
property AutomaticAttach: Boolean read FAutomaticAttach write FAutomaticAttach;
property Active: Boolean read FActive write SetActive;
property Bitmap: TBitmap read FBitmap write SetBitmap;
property TileMode: TTileMode read FTileMode write SetTileMode;
{ Published declarations }
end;procedure Register;implementationconstructor TTiler.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
FBitmap := TBitmap.Create;
FAutomaticAttach := True;
end;destructor TTiler.Destroy;
begin
Detach;
FBitmap.Free;
inherited Destroy;
end;procedure TTiler.Attach;
begin
if not (Owner is TForm)
then raise Exception.Create('Can''t attach TTiler component to something else than a TForm.');
if not Assigned(FClientInstance) // only attach once!
then begin
if (Owner as TForm).FormStyle = fsMDIForm
then FHandle := (Owner as TForm).ClientHandle
else FHandle := (Owner as TForm).Handle; FClientInstance := MakeObjectInstance(ClientWndProc);
FDefClientProc := Pointer(GetWindowLong(FHandle, GWL_WNDPROC));
SetWindowLong(FHandle, GWL_WNDPROC, LongInt(FClientInstance));
Form := Owner as TForm;
if Active
then begin
Active := False;
Active := True;
end;
end;
end;procedure TTiler.Detach;
begin
if Active and Assigned(FClientInstance)
then begin
Active := False; // clear client area
FActive := True; // put old value back for redrawing when attach again
end;
if Assigned(FClientInstance) // if attached
then begin
SetWindowLong(FHandle, GWL_WNDPROC, LongInt(FDefClientProc));
FreeObjectInstance(FClientInstance);
end;
FClientInstance := nil;
end;procedure TTiler.Redraw;
var b: Boolean;
begin
b := Active;
Active := False;
Active := b;
end;procedure TTiler.ClientWndProc(var Message: TMessage);
procedure Default;
begin
with Message
do Result := CallWindowProc(FDefClientProc, FHandle, Msg, wParam, lParam);
end;
begin
with Message
do begin
case Msg of
WM_NCHITTEST : begin
Default;
if FHandle = Form.ClientHandle
then if Result = HTCLIENT
then Result := HTTRANSPARENT;
end;
WM_ERASEBKGND : begin
if Assigned(FBitmap) and Active and (FHandle <> 0) and (FBitmap.Handle <> 0)
then FillClientArea(TWMEraseBkgnd(Message).DC)
else FillRect(TWMEraseBkgnd(Message).DC, (Owner as TForm).ClientRect, (Owner as TForm).Brush.Handle);
Result := 1;
end;
WM_VSCROLL,
WM_HSCROLL,
WM_SIZE : begin
Default;
InvalidateRect(FHandle, nil, True);
end;
else Default;
end;
end;
end;procedure TTiler.Loaded;
begin
inherited Loaded;
if AutomaticAttach
then Attach;
end;procedure TTiler.FillClientArea(DC: HDC);
begin
if FHandle <> 0
then case FTileMode of
tmTile : Tile(DC);
tmStretch : Stretch(DC);
tmCenter : Center(DC);
tmLeftVCenter,
tmLeftVTop,
tmLeftVBottom,
tmRightVCenter,
tmRightVTop,
tmRightVBottom,
tmCenterVTop,
tmCenterVBottom : Spot(DC);
end;
ReleaseDC(FHandle, DC);
end;procedure TTiler.Spot(DC: HDC);
var y, x: LongInt;
begin
x := 0;
y := 0; if TileMode in [tmRightVTop, tmRightVCenter, tmRightVBottom]
then x := Form.ClientWidth - FBitmap.Width - 1; if TileMode in [tmCenterVTop, tmCenterVBottom]
then x := (Form.ClientWidth div 2) - (FBitmap.Width div 2); case TileMode of
tmLeftVCenter,
tmRightVCenter : y := (Form.ClientHeight div 2) - (FBitmap.Height div 2);
tmLeftVTop,
tmRightVTop,
tmCenterVTop : y := 0;
tmLeftVBottom,
tmRightVBottom,
tmCenterVBottom : y := Form.ClientHeight - FBitmap.Height;
end;
FillRect(DC, (Owner as TForm).ClientRect, (Owner as TForm).Brush.Handle);
BitBlt(DC, x, y, FBitmap.Width, FBitmap.Height, FBitmap.Canvas.Handle, 0, 0, SRCCOPY);
end;procedure TTiler.Center(DC: HDC);
var R: TRect;
x, y: LongInt;
w, h: LongInt;
begin
R := Form.ClientRect;
x := (R.Right div 2) - (FBitmap.Width div 2);
y := (R.Bottom div 2) - (FBitmap.Height div 2);
w := x + FBitmap.Width;
h := y + FBitmap.Height;
FillRect(DC, R, Form.Brush.Handle);
BitBlt(DC, x, y, w, h, FBitmap.Canvas.Handle, 0, 0, SRCCOPY);
end;procedure TTiler.Stretch(DC: HDC);
var R: TRect;
begin
R := Form.ClientRect;
StretchBlt(DC, R.Left, R.Top, R.Right, R.Bottom, FBitmap.Canvas.Handle, 0, 0, FBitmap.Width, FBitmap.Height, SRCCOPY);
end;procedure TTiler.Tile(DC: HDC);
var x, y, bmWidth, bmHeight: Integer;
bmHandle: HBITMAP;
begin
bmWidth := FBitmap.Width;
bmHeight := FBitmap.Height;
bmHandle := FBitmap.Canvas.Handle; x := HOffset; while x < Form.Width
do begin
y := 0;
while y < Form.Height
do begin
BitBlt(DC, x, y, x + bmWidth, y + bmHeight,
bmHandle, 0, 0, SRCCOPY);
BitBlt(DC, x, y + bmHeight, x + bmWidth, y + bmHeight,
bmHandle, 0, 0, SRCCOPY);
BitBlt(DC, x + bmWidth, y, x + bmWidth, y + bmHeight,
bmHandle, 0, 0, SRCCOPY);
BitBlt(DC, x + bmWidth, y + bmHeight, x + bmWidth, y + bmHeight,
bmHandle, 0, 0, SRCCOPY);
y := y + bmHeight * 1;
end;
x := x + bmWidth * 1;
end;
end;
procedure TTiler.SetActive(Value: Boolean);
var msg: TMessage;
begin
if (Value <> FActive) and Assigned(Owner)
then begin
FActive := Value;
if not (csDesigning in ComponentState)
then begin
if FHandle <> 0 // draw, but only if there is a handle!!
then begin
msg.Msg := WM_ERASEBKGND;
TWMEraseBkgnd(msg).DC := GetDC(FHandle);
ClientWndProc(msg) // fire once!
end;
end
else {if FActive and not (csReading in ComponentState) and not (csLoading in ComponentState)
then ShowMessage('TTiler won''t show any drawing at designtime...')};
end;
end;procedure TTiler.SetBitmap(Value: TBitmap);
begin
FBitmap.Assign(Value);
end;procedure TTiler.SetTileMode(Value: TTileMode);
begin
if Value <> FTileMode
then begin
FTileMode := Value;
if (not (csDesigning in ComponentState)) and Active
then begin
Active := False; // clear all
Active := True; // start drawing again
end;
end;
end;
procedure Register;
begin
RegisterComponents('Upscene', [TTiler]);
end;end.
var
Bmp: TBitmap;procedure TForm1.FormCreate(Sender: TObject);
begin
Bmp := TBitmap.Create;
Bmp.LoadFromFile('D:\test.bmp');
Brush.Bitmap := Image1.Picture.Bitmap;
end;procedure TForm1.FormDestroy(Sender: TObject);
begin
Bmp.Free;
end;