微信公众号 
图码生活

每天发布有五花八门的文章,各种有趣的知识等,期待您的订阅与参与
电脑报 1992-2001 十年文章全集
电脑报 1992-2001 十年文章全集
包含从 1992 年 - 2001 年间,两万余篇期刊文章,查询最少输入两个字符
随便看看
读取中
读取中
标题如何做一个软件的启动画面
栏目软件世界
作者朱大勇
发布2001年22期
  做一个软件的启动画面,关键是要将放在窗体上的位图部分显示出来,而将其它的部分隐藏,以此来达到具有自己特色的软件启动画面。下面我们以Delphi为例向大家介绍如何做一个软件的启动画面。
   1.程序中函数简介
  TBitmap.Mask(TransparentColor:TColor)
  Mask函数把位图转换成单色位图,用白色来替代指定的透明色(TransparentColor),其余颜色用黑色来替代。
  TBitmap.Scanline[Row:Integer]:Pointer
  通过Scanline[Row]属性可获得位图第Row行扫描线的指针。
  BeginPath(HDC hdc)、EndPath(HDC hdc)、CloseFigure(HDC hdc)
  BeginPath函数在指定的设备上下文(Device context)中打开路径,EndPath函数关闭该路径,CloseFigure函数通过把终点和起点连成直线来关闭路径。这三个函数中的hdc是指设备上下文句柄(Handle to device context),程序中调用的是TBitmap.Canvas.Handle。
  PathToRegion(HDC hdc)
  PathToRegion函数把路径转换成区域。
  CreateRegion(SourceBmp: TBitmap; MyTransparentColor:TColor):HRGN;
  CreateRegion函数把透明位图转换成区域,返回值为区域的句柄。其中SourceBmp为要转换的位图,MyTransparentColor为指定的透明色。
   2.程序清单
  unit bmptorgn
  {将程序定义为一个独立的单元(Unit),这样在需要调用CreateRegion函数单元的Uses语句中加上Bmptorgn即可。}
  interface
  uses
  Windows,Graphics;
  function CreateRegion(SourceBmp:TBitmap;MyTransparentColor:TColor):HRGN;
  implementation
  function CreateRegion(SourceBmp:TBitmap;MyTransparentColor:TColor):HRGN;
  var
  offbyte,lineaddress,x,y:integer;
  isline:boolean;{画线标志,"true"表示开始画线,"false"表示终止画线}
  bmp:tbitmap;{程序中使用的单色位图}
  Cx,Cy:integer;{线的起点}
  bitcolor:byte;{点(x,y)处的颜色}
  begin
  bmp:=Tbitmap.create;
  bmp.assign:sourcebmp;
  with bmp;bmp.canvas do begin
  mask(MyTransparentColor);
  Monochrome:=true;设置为单色位图}
  pixelformat:=pf1bit;
  BeginPath(handle);
  for y:=0 to Height-1 do begin
  lineaddress:=longint(scanline[y]);
  isline:= false;
  for x:=0 to Width-1 do begin;
  offbyte:=(x shr 3);点(x,y)处的颜色值在第y行扫描线中的偏移字节数}
  bitcolor:=((Pbyte(lineaddress+offbyte)^shl(x-(offbyte shl 3)))and $80);{将点(x.y)处的颜色值移到最高位,然后和$80进行与计算,结果为0时是黑色,128则为白色。bitcolor的值也可采用canvas.pixel(x,y),但运行速度比采用Scanline方法的慢}
  if bitcolor=0 then begin
  if not isline then begin
  isline:= true;
  Cx:= x;
  Cy:= y;
  end;
  if x=Width-1 then begin
  MoveTo(Cx,Cy);
  LineTo(Width,cy);
  LineTo(Width,Cy+1);
  LineTo(Cx,Cy+1);
  CloseFigure(handle);
  end;
  end else if isline then begin
  isline:= false;
  MoveTo(Cx,Cy);
  LineTo(Width,cy);
  LineTo(Width,Cy+1);
  LineTo(Cx,Cy+1);
  CloseFigure(handle);
  end;
  end;
  end;
  EndPath(handle);
  result:= PathToRegion(handle);  
  end;
  bmp.free;
  end;
  end.
   3.例程
  该程序的主窗口包括一个Timage控件,Form1、Image1的Autosize属性均为“True”。Image1所包含位图的背景颜色为$40ffff。
  程序清单如下:
  unit main;
  interface
  uses
  Windows,Messages,SysUtils,Classes,Graphics,Controls,Forms,ExtCtrls,bmptorgn;
  type
  TForm1 = class(TForm)
  Image1:TImage;
  procedure FormCreate(Sender:TObject);
  procedure FormCreate(Sender:TObject);
  private
   {Private declarations} 
  public
  {Private declarations}
  end;
  var
  Form1:TForm1;
  implementation
  {$R*.DFM}
  procedure TForm1.FormCreate(Sender:TOb-ject);
  var myrgn:HRGN;
  begin
  myrgn:=CreateRegion(image1.picture.bitmap,$40ffff);
  offsetrgn(myrgn,clientorigin.x-left,clientorigin.y-top);{将区域移到窗口的客户区(Client area)}
  setwindowrgn(handle,myrgn,true);{设置窗口区域}
  end;
  procedure TForm1.Image1Click(Sender:TOb-ject);
  begin
  close;{由于没有标题栏,所以采用该方法退出程序}
  end;
  end.
  注:程序在Windows98 Delphi5下运行通过。