一定有很多人看到过一些奇形怪状的窗体,例如一些屏幕精灵。其实实现起来非常容易,做到三点就好啦。下面我使用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', );
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.

DELPHI 异形窗体的更多相关文章

  1. delphi 异形窗体可半透明

    unit xDrawForm; interface uses Windows, Messages, SysUtils, Classes, Controls, Forms, Menus, Graphic ...

  2. Qt绘制异形窗体

    异形窗体即不规则窗体,一般采用png图片,一般绘制异形窗体分两步: 1.设置遮罩区 2.绘制图片   使用png图片的透明部分作为遮罩区,然后绘制图片,这样我们就看到一个只绘制了非透明部分的图形,废话 ...

  3. FireMonkey下的异形窗体拖动(句柄转换)

    DelphiXE2 Firemoney FMX 的窗体不只是为windows的, 所以很多功能都没有了. 最常见的就是拖拽了 先看 VCL时代 一个经典拖动代码 ReleaseCapture(); S ...

  4. DSAPI显示PNG异形窗体

    使用DSAPI实现PNG异形窗体,注意,该窗体为层样式窗体,以PNG或32位带透明通道的图像合成到屏幕,此方法不会触发窗体的重绘,故原窗体(包括其子控件)均不会显示,如果需要更新画面,需要重新用代码等 ...

  5. FireMonkey下的异形窗体拖动(需要使用FmxHandleToHwnd函数转化一下句柄)

    DelphiXE2 Firemoney FMX 的窗体不只是为windows的, 所以很多功能都没有了. 最常见的就是拖拽了 先看 VCL时代 一个经典拖动代码 ReleaseCapture(); S ...

  6. delphi实现窗体闪烁功能

    delphi实现窗体闪烁功能 以前做窗口闪动时都没有考虑到让任务栏上的按钮闪动的问题, 现在一个客户需要任务栏按钮闪动,发现以前使用的flashwindow不能达到要求了, 查找了一下,找到flash ...

  7. Delphi中窗体的事件

    Delphi中窗体的事件 Form窗体可以响应各种各样的时间,在Object Inspector的Events页面中罗列了一大堆,如下图: 下面将要列出一些常用的事件. 1.OnActivate 当窗 ...

  8. Qt 实现 异形 窗体&按钮

    //关键部分代码如下//设置异形窗体 //setWindowOpacity(0.5);//设置窗体透明度 0完全透明,1完全不透明 this->setWindowFlag(Qt::Framele ...

  9. Delphi下创建异形窗体

    procedure TForm1.FormCreate(Sender: TObject);var  pt: array [0 .. 4] of TPoint;  m_rgn: HRGN;begin   ...

随机推荐

  1. 洛谷P1935 [国家集训队]圈地计划

    题目大意: 有个\(n*m\)的网格图 每个点可以选择\(A\),获得\(A[i][j]\)或选\(B\)获得\(B[i][j]\)的收益 相邻点有\(k\)个不同可以获得\(C[i][j]\)的收益 ...

  2. HttpClient异常处理手册

    HttpClient异常处理手册 开源中国 发表于 2014-08-26 19:44:06 异常处理 HttpClient的使用者在执行HTPP方法(GET,PUT,DELETE等),可能遇到会两种主 ...

  3. python自动化测试-使用第三方python库技术实现

    转载自https://www.cnblogs.com/beer/p/5418471.html

  4. php-验证码类-PDO类-缩略图类

    Verify.class.php 验证码类 <?php class Verify{ const VERIFY_TYPE_NUM=1; const VERIFY_TYPE_EN=2; const ...

  5. 「NOI2018」屠龙勇士 解题报告

    「NOI2018」屠龙勇士 首先对于每个龙用哪个剑砍,我们可以用set随便模拟一下得到. 然后求出拿这个剑砍这条龙的答案 \[ atk_ix-p_iy=a_i \] 其中\(atk_i\)是砍第\(i ...

  6. 预处理+状态压缩+剪枝——codefoece 1209E

    那一步剪枝实在是没想到 #include<bits/stdc++.h> using namespace std; #define N 2005 struct Col{ ],Max[< ...

  7. php linux下安装xml扩展

    1.进入PHP安装源码包,找到ext下的ftp,进入 cd /home/local/php-5.6.25/ext/xml 2./usr/local/php/bin/phpize 3../configu ...

  8. 剑指offer——数组中出现次数超过一半的数字(c++)

    题目描述数组中有一个数字出现的次数超过数组长度的一半,请找出这个数字.例如输入一个长度为9的数组{1,2,3,2,2,2,5,4,2}.由于数字2在数组中出现了5次,超过数组长度的一半,因此输出2.如 ...

  9. 批处理禁止指定的IE的加载项

    步骤: 1.查找插件对应的 CLSID 获取 HKCU\Software\Microsoft\Windows\CurrentVersion\Ext\Stats 下的 CLSID, 然后在 HKCR\C ...

  10. JEECG树(TreeGrid)字段的扩展

    转载:https://blog.csdn.net/huangzirong822/article/details/38400817 之前使用jeecg集成框架做过一个项目 这里说说框架中树(tree)字 ...