异形窗体的实现

一定有很多人看到过一些奇形怪状的窗体,例如一些屏幕精灵。其实实现起来非常容易,做到三点就好啦。下面我使用Delphi做了一个VCL控件(TBmpShape),你只需要指定一幅图片就可以将窗体变成你的图片的形状。

数据挖掘论坛

1。准备一幅位图图片,一定要BMP格式的

数据挖掘工具

2。将VCL控件放在你的窗体(FORM)上,注意不能是其他的容器,设置PICTURE属性,指定制作好的图片。 数据挖掘实验室

3。设置图片的背景颜色,必须是你的图片的背景颜色准确值 数据挖掘论坛

4。在本窗体的FormCreate事件中写一行代码

BmpShape1.Apply;

做到上面四点就可以了,编译运行你的窗体,是不是不一样啊。 数据挖掘交友

下面是具体的代码,不是太长吧。

unit BmpShape;
{
2002/08/22  by ultrared
根据BMP文件创建窗口
注意:
1. BMP文件最左上的一个点颜色作为背景色
2. BmpShape控件只能用在TForm容器上
3. BMP文件可以是256色或者24位色
4。大块背景色必须和背景色绝对相等才能获得正常效果
}
interface

数据挖掘研究院

uses
 Forms,Windows, Messages, SysUtils, Classes, Controls, ExtCtrls,Graphics;

数据挖掘研究院

type
 TBmpShape = class(TImage)
 private
  { Private declarations }
  BackColor:TColor;//背景颜色
  FColorDither:boolean;//是否允许背景颜色有一定的抖动
  function GetRegion:HRGN;//前景图片的区域
  procedure setColorDither(cd:Boolean);
 protected
  { Protected declarations }
 public
  { Public declarations }
  constructor Create(AOwner:TComponent);override;
  procedure Apply;//使用效果
 published
  { Published declarations }
  property Dither:Boolean read FColorDither write setColorDither;
 end; 数据挖掘交友

procedure Register;

数据挖掘交友

implementation

数据挖掘实验室

procedure Register;
begin
 RegisterComponents("Samples", [TBmpShape]);
end; 数据挖掘实验室

procedure TBmpShape.setColorDither(cd:Boolean);
begin
 if cd<>FColorDither then
  FColorDither:=cd;
end;

constructor TBmpShape.Create(AOwner:TComponent);
begin
 inherited Create(AOwner);
 BackColor:=RGB(0,0,0);
 FColorDither:=FALSE;
end;

//核心子程序,获得BMP图片的前景区域
function TBmpShape.GetRegion:HRGN;
var
 i,j:integer;
 rgn1,rgn2:HRGN;
 StartY:integer;
 r,g,b,r1,g1,b1:BYTE;
 cc:TColor;
begin
 if Picture.Bitmap<>nil then
 begin
  BackColor:=Picture.Bitmap.Canvas.Pixels[0,0];
  rgn1:=CreateRectRgn(0,0,0,0);
  for i:=0 to Picture.Bitmap.Width-1 do
  begin
   StartY:=-1;
   for j:=0 to Picture.Bitmap.Height-1 do
   begin
    cc:=Picture.Bitmap.Canvas.Pixels[i,j];
    if FColorDither then
    begin
     //允许和背景有一定的色差
     r:=(cc and $FF0000) shr 16;
     g:=(cc and $FF00) shr 8;
     b:=cc and $FF;
     r1:=(BackColor and $FF0000) shr 16;
     g1:=(BackColor and $FF00) shr 8; 数据挖掘工具
     b1:=BackColor and $FF;
     if (abs(r-r1)<10) and (abs(g-g1)<10) and (abs(b-b1)<10) then
     begin
      if (StartY>=0) and (j>=StartY) then
      begin
       rgn2:=CreateRectRgn(i,StartY,i+1,j);
       CombineRgn(rgn1,rgn1,rgn2,RGN_OR);
       StartY:=-1;
      end;
     end
     else
     begin
      if Starty<0 then
       StartY:=j
      else if j=(Picture.Bitmap.Height-1) then //最下面一个点
      begin
       rgn2:=CreateRectRgn(i,StartY,i+1,j); 数据挖掘研究院
       CombineRgn(rgn1,rgn1,rgn2,RGN_OR);
      end;
     end;
    end
    else //不允许色差
    begin
     if cc=BackColor then
     begin
      if (StartY>=0) and (j>=StartY) then
      begin
       rgn2:=CreateRectRgn(i,StartY,i+1,j);
       CombineRgn(rgn1,rgn1,rgn2,RGN_OR);
       StartY:=-1;
      end;
     end
     else
     begin
      if Starty<0 then
       StartY:=j
      else if j=(Picture.Bitmap.Height-1) then //最下面一个点


      begin
       rgn2:=CreateRectRgn(i,StartY,i+1,j);
       CombineRgn(rgn1,rgn1,rgn2,RGN_OR);
      end;
     end;
    end;
   end;
  end;
  result:=rgn1;
 end
 else
  result:=0;
end;

数据挖掘工具

procedure TBmpShape.Apply;
begin
 if Parent is TForm then
 begin
  Left:=0;
  Top:=0;
  Width:=Picture.Bitmap.Width;
  Height:=Picture.Bitmap.Height;
  with (Parent as Tform) do
  begin
   BorderStyle:=bsNone;
   Width:=Self.Width;
   Height:=Self.Height;
  end;
  SetWindowRgn(Parent.Handle,GetRegion,FALSE);
 end;
end; 数据挖掘交友

end. 数据挖掘实验室

[数据挖掘专家] [数据挖掘研究院] [数据挖掘论坛] [数据挖掘实验室]
上一篇:检查特殊字符的简单VCL
下一篇:通过实例看VCL组件开发全过程(一)
最新评论共有 0 位网友发表了评论 , 查看所有评论
发表评论( 不能超过250字,需审核,请自觉遵守互联网相关政策法规。 )
匿名?
数据挖掘网站导航 数据挖掘论坛导航
  • 数据挖掘工具
  • 数据挖掘论坛
  • DataCruncher - Cognos
  • MineSet - MathSoft
  • Intelligent Miner - GainSmarts
  • Sqlserver - SAS - Clementine
  • CART - Weka - WizSoft
  • NeuroShell - ModelQuest
  • data mining tools - Darwin
  • 数据挖掘交友
  • 数据挖掘博客
  • 数据挖掘工具
  • 数据挖掘资源
  • 数据挖掘技术算法
  • 数据挖掘相关期刊、会议
  • 研究院联盟合作专区
  • 数据挖掘基础与相关技术
  • 数据挖掘厂商与就业
  • 数据挖掘研究者乐园
  • 知名厂商数据挖掘工具资料
  • 国内数据挖掘实验室
  • Foreign Data Mining Lab
  • 热点关注
  • GDI+简介
  • COM与DCOM的区别与联系
  • 使用Delphi解析XML 文档
  • 如何设置delphi/cbuilder/BDE/MSSQL
  • BORLAND在“迫害”程序员?
  • 将image的图片保存为JPG格式图片方法
  • InstallShieldExpressfordelphi制作安装程
  • Real Programmers Use Pascal
  • 关于在COM中使用可选参数的研究
  • TStrings的AddObject方法应用
  • 论坛最新话题
  • Foundations of Statistical Natural Langu
  • Game Theory meet Data Mining: A Recent P
  • System Building: How does it help or hin
  • 数据挖掘与Clementine培训
  • 新手报到
  • 求 SASEM 客户流失预测分析
  • 数据挖掘工程师/搜索研究院—北京——无线
  • 数据挖掘入门介绍(如何着手数据挖掘)
  • Information Overload Survey Results
  • The INEX 2005 Workshop on Element Retrie
  • 相关资讯
  • BORLAND在“迫害”程序员?
  • 李维:我的回忆和一些有趣的事(精彩绝伦)
  • 李维看.net和DELPHI6(含李维照片)
  • 《代码大全》电子版1.01发布了
  • Real Programmers Use Pascal
  • Kylix安装手记
  • Borland与Microsoft关于Delphi的对话
  • InstallShieldExpressfordelphi制作安装程
  • 关于在COM中使用可选参数的研究
  • msagent经典用法
  • 数据挖掘实验室资料
  • 数据挖掘博客地址
  • 数据挖掘实验室网站地址
  • Prepare for Medicare audits by using dat
  • 注册成为SAS用户与爱好者俱乐部会员
  • 水南梅
  • 明日烟
  • 新人报道
  • 下载
  • 厦门服务器托管,450元/月—0592-5177319 高
  • 买空间送域名--0592-5177319 高静