procedure TfmMain.FormCreate(Sender: TObject); var AppPath:string; begin AppPath := ExtractFilePath(Application.ExeName); if FileExists(AppPath+'beauty.jpeg') and not FileExists(AppPath+'beauty.bmp')then ConvertJpgtoBmp(AppPath+'beauty.jpeg',AppPath+'beauty.bmp');if FileExists(AppPath+'beauty.bmp') then begin try imMain := TBitmap.Create; imMain.LoadFromFile(AppPath+'beauty.bmp'); Brush.Bitmap := imMain; except on EInvalidGraphic do imMain := nil; end; end;end;
I 服了 U ,BCB,这么绝的方法你也想得出来!!!
在MDI程序中,由于MDI的主窗口一般的功能是提供子窗口显示的位置和提供菜单、工具条、状态条等,而窗口的客户区则一般不会有其它的用途,如果在这里画上一些软件的标志、公司的标志或者其它的背景图案的话,不仅可以使MDI的主窗口更加充实、美观,而且还可以更加突出公司的形象和增加公司标志在客户心中的地位。 由于MDI主窗口的特性,使用普通OnPaint和使用TImage等方法都不会产生作用。下面将用编写一个简单的MDI程序来介绍如何实现。 第一步:打开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。 现在你可以编译运行这个程序,你会发现,Image元件并不会在Form上显示出来,但是整个Form的客户区域被Image中的图像所铺满。
1.在窗体中加入一个image,图片大小要适宜。unit RoundChildwin;interfaceuses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
ExtCtrls, jpeg, StdCtrls;
type
TRWinForm = class(TForm)
DrawImage: TImage;
procedure FormCreate(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure FormPaint(Sender: TObject);
protected
procedure PaintBackground ;
public
{ Public declarations }
end;var
RWinForm: TRWinForm;implementation{$R *.DFM}procedure TRWinForm.FormCreate(Sender: TObject);
var Rgn :HRGN ;
begin
Rgn :=CreateRoundRectRgn(0,0,Width,Height,5,5);
SetWindowRGN(handle,Rgn,true) ;
end;procedure TRWinForm.FormClose(Sender: TObject; var Action: TCloseAction);
begin
//Action:=CaFree;
end;procedure TRWinForm.PaintBackground;var X, Y : Integer;
IsClipRgnExists : Boolean;
PrevClipRgn, Rgn : HRGN;
ARect :TRect ;
begin
ARect :=ClientRect ;
{save rgn}
PrevClipRgn := CreateRectRgn(0, 0, 0, 0);
IsClipRgnExists := GetClipRgn(Canvas.Handle, PrevClipRgn) = 1;
Rgn := CreateRectRgnIndirect(ARect);
SelectClipRgn(Canvas.Handle, Rgn);
DeleteObject(Rgn);
X := ARect.Left;
while X < ARect.Right do begin
Y := ARect.Top;
while Y < ARect.Bottom do begin
Canvas.Draw(X, Y, DrawImage.Picture.Graphic );
inc(Y, DrawImage.Height);
end;
inc(X, DrawImage.Width);
end;
DrawEdge(Canvas.Handle, ARect, BDR_RAISEDINNER, BF_TOPLEFT);
DrawEdge(Canvas.Handle, ARect, BDR_RAISEDOUTER, BF_BOTTOMRIGHT);
{restore rgn}
if IsClipRgnExists then SelectClipRgn(Canvas.Handle, PrevClipRgn)
else SelectClipRgn(Canvas.Handle, 0);
DeleteObject(PrevClipRgn);
end;procedure TRWinForm.FormPaint(Sender: TObject);
begin
PaintBackground;
end;end.
laza(麻风瘦)的方法虽然复杂些,但是比较规矩,系统资源消耗的较少,只是只能做到“平铺”效果
具体还得看你自己的需求了!
Form1.Brush.Bitmap:=Image1.Picture.Bitmap;
Form1.Brush.Bitmap:=Image1.Picture.Bitmap;
放到 TForm1.OnCreate( )事件中;
{
Image1->Visible=false;
Brush->Bitmap=Image1->Picture->Bitmap;
}
注意:Image1中的小图片只能是.BMP, 如果是.jpg请用
ACDSEE之类的转换成.bmp
还是需要响应背景重画消息的
当然,如果要改变MDI窗体的背景,相对麻烦点,需要的话人民邮电出版的一本DELPHI技巧详解.
var AppPath:string;
begin
AppPath := ExtractFilePath(Application.ExeName);
if FileExists(AppPath+'beauty.jpeg') and not FileExists(AppPath+'beauty.bmp')then
ConvertJpgtoBmp(AppPath+'beauty.jpeg',AppPath+'beauty.bmp');if FileExists(AppPath+'beauty.bmp') then
begin
try
imMain := TBitmap.Create;
imMain.LoadFromFile(AppPath+'beauty.bmp');
Brush.Bitmap := imMain;
except
on EInvalidGraphic do
imMain := nil;
end;
end;end;
由于MDI主窗口的特性,使用普通OnPaint和使用TImage等方法都不会产生作用。下面将用编写一个简单的MDI程序来介绍如何实现。
第一步:打开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。
现在你可以编译运行这个程序,你会发现,Image元件并不会在Form上显示出来,但是整个Form的客户区域被Image中的图像所铺满。