delphi 异形窗体可半透明
unit xDrawForm; interface
uses Windows, Messages, SysUtils, Classes, Controls, Forms, Menus,
Graphics,GDIPOBJ,GDIPAPI,GDIPUTIL; type TwwGDIImage = class
public
n_Pos_X : Integer;
n_Pos_Y : Integer;
n_Width : Integer;
n_Height : Integer;
GPImageNormal : TGPImage; procedure CreateImageNormal(wsFileName: WideString;nPosX,nPosY,nW,nH:Integer);
end; TwwGDIButton = class(TwwGDIImage)
public
GPImageHot : TGPImage;
GPImageDown : TGPImage;
end; TwwCanvas = class(TObject)
private
m_hdcMemory: HDC;
hdcScreen: HDC;
hBMP: HBITMAP;
m_Blend: BLENDFUNCTION;
// 事件
FGPGraph: TGPGraphics;
FOnDrawImage: TNotifyEvent; procedure BeginDraw(); // 绘图前置工作
procedure EndDraw(Handle:THandle); // 绘图收尾工作
public
sizeWindow: SIZE;
ptSrc: TPOINT;
n_Handle : THandle;
procedure RePaint(h:THandle);
procedure InitCanvas(nx,ny:Integer);
procedure wwDrawImage(wwGDIImage :TwwGDIImage);
property GPGraph: TGPGraphics read FGPGraph write FGPGraph;
property OnDrawImage: TNotifyEvent read FOnDrawImage write FOnDrawImage;
end; implementation { TwwCanvas } procedure TwwCanvas.BeginDraw;
begin
// 获取桌面屏幕设备
hdcScreen := GetDC();
// 创建一个与指定设备兼容的内存设备上下文环境(DC)
m_hdcMemory := CreateCompatibleDC(hdcScreen);
// 创建与指定的设备环境相关的设备兼容的位图
hBMP := CreateCompatibleBitmap(hdcScreen, sizeWindow.cx, sizeWindow.cy );
// 选择一对象到指定的设备上下文环境中,该新对象替换先前的相同类型的对象
SelectObject(m_hdcMemory, hBMP);
// 创建画布
GPGraph := TGPGraphics.Create(m_hdcMemory);
end; procedure TwwCanvas.wwDrawImage(wwGDIImage: TwwGDIImage);
begin
GPGraph.DrawImage(
wwGDIImage.GPImageNormal,
wwGDIImage.n_Pos_X,
wwGDIImage.n_Pos_Y,
wwGDIImage.n_Width,
wwGDIImage.n_Height)
end; procedure TwwCanvas.EndDraw(Handle:THandle);
begin
// 设置窗体风格
SetWindowLong(Handle, GWL_EXSTYLE, GetWindowLong(Handle, GWL_EXSTYLE) or WS_EX_LAYERED);
// 执行透明混合
UpdateLayeredWindow(Handle, hdcScreen, nil,@sizeWindow, m_hdcMemory, @ptSrc, , @m_Blend, ULW_ALPHA);
// 设置窗体位置
SetWindowPos(Handle, HWND_TOPMOST, , , , , SWP_NOMOVE or SWP_NOSIZE); // 各种释放就对了.. 不然画起来会糊
GPGraph.ReleaseHDC(m_hdcMemory);
ReleaseDC(, hdcScreen);
hdcScreen := ;
DeleteObject(hBMP);
DeleteDC(m_hdcMemory);
m_hdcMemory := ;
GPGraph.Free;
end; procedure TwwCanvas.RePaint(h:THandle);
begin
if Assigned(FOnDrawImage) then
begin
BeginDraw();
FOnDrawImage(Self);
EndDraw(h);
end;
end; procedure TwwCanvas.InitCanvas(nx, ny: Integer);
begin
m_Blend.BlendOp := AC_SRC_OVER; // the only BlendOp defined in Windows 2000
m_Blend.BlendFlags := ; // Must be zero
m_Blend.AlphaFormat := AC_SRC_ALPHA; //This flag is set when the bitmap has an Alpha channel
m_Blend.SourceConstantAlpha := ; sizeWindow.cx := nx;
sizeWindow.cy := ny;
ptSrc := Point(,);
end; { TwwGDIImage } procedure TwwGDIImage.CreateImageNormal(wsFileName: WideString;nPosX,nPosY,nW,nH:Integer);
begin
Self.GPImageNormal := TGPImage.Create(wsFileName);
Self.n_Pos_X := nPosX;
Self.n_Pos_Y := nPosY;
Self.n_Width := nW;
Self.n_Height:= nH;
end; end. unit uMainForm; interface uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, GDIPOBJ,GDIPAPI,GDIPUTIL; type
TForm1 = class(TForm)
procedure FormCreate(Sender: TObject);
procedure FormShow(Sender: TObject); private
{ Private declarations }
public
procedure DrawImage(Sender: TObject);
{ Public declarations }
end; var
Form1: TForm1; implementation
uses xDrawForm;
var
wwCanvas : TwwCanvas = nil;
img_BackGround: TwwGDIImage= nil; // 背景图
// img_ProgressBar1: TwwGDIImage= nil; // 上滚动条
// img_ProgressBar2: TwwGDIImage= nil; // 下滚动条
// img_Lighting: TwwGDIImage= nil; // 闪光点 {$R *.dfm} procedure TForm1.DrawImage(Sender: TObject);
begin
TwwCanvas(Sender).wwDrawImage(img_BackGround);
end; procedure TForm1.FormCreate(Sender: TObject);
begin
DoubleBuffered := True;
BorderStyle := bsNone;
wwCanvas := TwwCanvas.Create();
wwCanvas.InitCanvas(,);
wwCanvas.OnDrawImage := Self.DrawImage; img_BackGround := TwwGDIImage.Create();
img_BackGround.CreateImageNormal('BackGround.png',,,,); end; procedure TForm1.FormShow(Sender: TObject);
begin
wwCanvas.RePaint(Self.Handle);
end; end.
delphi 异形窗体可半透明的更多相关文章
- DELPHI 异形窗体
一定有很多人看到过一些奇形怪状的窗体,例如一些屏幕精灵.其实实现起来非常容易,做到三点就好啦.下面我使用Delphi做了一个VCL控件(TBmpShape),你只需要指定一幅图片就可以将窗体变成你的图 ...
- Qt绘制异形窗体
异形窗体即不规则窗体,一般采用png图片,一般绘制异形窗体分两步: 1.设置遮罩区 2.绘制图片 使用png图片的透明部分作为遮罩区,然后绘制图片,这样我们就看到一个只绘制了非透明部分的图形,废话 ...
- FireMonkey下的异形窗体拖动(句柄转换)
DelphiXE2 Firemoney FMX 的窗体不只是为windows的, 所以很多功能都没有了. 最常见的就是拖拽了 先看 VCL时代 一个经典拖动代码 ReleaseCapture(); S ...
- DSAPI显示PNG异形窗体
使用DSAPI实现PNG异形窗体,注意,该窗体为层样式窗体,以PNG或32位带透明通道的图像合成到屏幕,此方法不会触发窗体的重绘,故原窗体(包括其子控件)均不会显示,如果需要更新画面,需要重新用代码等 ...
- FireMonkey下的异形窗体拖动(需要使用FmxHandleToHwnd函数转化一下句柄)
DelphiXE2 Firemoney FMX 的窗体不只是为windows的, 所以很多功能都没有了. 最常见的就是拖拽了 先看 VCL时代 一个经典拖动代码 ReleaseCapture(); S ...
- delphi实现窗体闪烁功能
delphi实现窗体闪烁功能 以前做窗口闪动时都没有考虑到让任务栏上的按钮闪动的问题, 现在一个客户需要任务栏按钮闪动,发现以前使用的flashwindow不能达到要求了, 查找了一下,找到flash ...
- Delphi中窗体的事件
Delphi中窗体的事件 Form窗体可以响应各种各样的时间,在Object Inspector的Events页面中罗列了一大堆,如下图: 下面将要列出一些常用的事件. 1.OnActivate 当窗 ...
- Qt 实现 异形 窗体&按钮
//关键部分代码如下//设置异形窗体 //setWindowOpacity(0.5);//设置窗体透明度 0完全透明,1完全不透明 this->setWindowFlag(Qt::Framele ...
- Delphi下创建异形窗体
procedure TForm1.FormCreate(Sender: TObject);var pt: array [0 .. 4] of TPoint; m_rgn: HRGN;begin ...
随机推荐
- linux暴露端口可以被外部访问
linux暴露端口可以被外部访问,把端口号换成要暴露的端口:/sbin/iptables -I INPUT -p tcp --dport 3306 -j ACCEPT Centos 7 开启端口Cen ...
- Vue自定义事件:触发自定义事件
一 项目结构 二 子组件(Mongo.vue) <template> <button @click="eat">按钮</button> < ...
- MySQL- 查询总结
查询总结 语法: select 查询字段 from 表 别名 连接类型inner|left|right join on 连接条件 where 筛选 group by 分组列表 having 筛选(二次 ...
- Recurrent Neural Network(1):Architecture
Recurrent Neural Network是在单个神经元上,除了输入与输出外,添加了一条Recurrent回路.也就是说,节点当前的状态将会影响其未来的状态.下式可以表征此关系: st= f(s ...
- 10: Django + Uwsgi + Nginx 的生产环境部署
1.1 一些重要概念 1.Web协议介绍 Web协议出现顺序: CGI -> FCGI -> WSGI -> uwsgi 1. CGI: 最早的协议 2. FCGI: 比CGI快 ...
- 获取Linux内核未导出符号的几种方式
从Linux内核的2.6某个版本开始,内核引入了导出符号的机制.只有在内核中使用EXPORT_SYMBOL或EXPORT_SYMBOL_GPL导出的符号才能在内核模块中直接使用.然而,内核并没有导出所 ...
- 使用EntityFramework调用存储过程并获取存储过程返回的结果集
[实习]刚入职,公司要求完成两个任务,任务要求使用存储过程和事务,其中一个问题要获取存储过程的查询结果集.经过多方查找和自己的实践,终于找到了方法.这里记录一下. 看到的这篇文章中给出的例子是查询单个 ...
- win10开机出现两个系统
1.cmd(Ctrl+R) 2.输入msconfig 3.选引导 4.删除多余的系统(切记不能删错)
- Linux就该这么学08学习笔记
参考链接:https://www.linuxprobe.com/chapter-08.html 防火墙管理工具 众所周知,相较于企业内网,外部的公网环境更加恶劣,罪恶丛生.在公网与企业内网之间充当保护 ...
- 字符串函数-unquote()函数
字符串函数顾名思意是用来处理字符串的函数.Sass 的字符串函数主要包括两个函数: unquote($string):删除字符串中的引号: quote($string):给字符串添加引号. 1.unq ...