GDI+用PNG图片做半透明异型窗口
- {*******************************************************}
- { }
- { GDI+用PNG图片做半透明异型窗口 }
- { }
- { 版权所有 (C) 2008 QQ:3150379 }
- { }
- {*******************************************************}
- unit Unit1;
- interface
- uses
- Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
- Dialogs,
- GDIPAPI, GDIPOBJ, Menus, StdCtrls;
- type
- TForm1 = class(TForm)
- PopupMenu1: TPopupMenu;
- mniClose: TMenuItem;
- mniChangeSkin: TMenuItem;
- About1: TMenuItem;
- Stayontop1: TMenuItem;
- procedure FormCreate(Sender: TObject);
- procedure FormMouseDown(Sender: TObject; Button: TMouseButton;
- Shift: TShiftState; X, Y: Integer);
- procedure About1Click(Sender: TObject);
- procedure Stayontop1Click(Sender: TObject);
- procedure mniChangeSkinClick(Sender: TObject);
- procedure mniCloseClick(Sender: TObject);
- private
- m_Blend: BLENDFUNCTION;
- procedure SetTransparent(lpSkinFile: WideString; nTran: integer);
- { Private declarations }
- public
- { Public declarations }
- end;
- var
- Form1: TForm1;
- implementation
- {$R *.dfm}
- procedure TForm1.FormCreate(Sender: TObject);
- begin
- BorderStyle := bsNone;
- m_Blend.BlendOp := AC_SRC_OVER; // the only BlendOp defined in Windows 2000
- m_Blend.BlendFlags := 0; // Must be zero
- m_Blend.AlphaFormat := AC_SRC_ALPHA; //This flag is set when the bitmap has an Alpha channel
- m_Blend.SourceConstantAlpha := 255;
- if (FileExists(ExtractFilePath(ParamStr(0)) + 'Security - Alert.png')) then
- SetTransparent(WideString(ExtractFilePath(ParamStr(0)) + 'Security - Alert.png'), 100);
- // Stay on top
- SetWindowPos(Handle, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE or SWP_NOSIZE);
- end;
- procedure TForm1.SetTransparent(lpSkinFile: WideString; nTran: integer);
- var
- GPImage: TGPImage;
- GPGraph: TGPGraphics;
- m_Image: TGPImage;
- m_hdcMemory: HDC;
- hdcScreen: HDC;
- hBMP: HBITMAP;
- sizeWindow: SIZE;
- rct: TRECT;
- ptSrc: TPOINT;
- begin
- // Use GDI+ load image
- GPImage := TGPImage.Create();
- m_Image := GPImage.FromFile(lpSkinFile);
- // Create Compatible Bitmap
- hdcScreen := GetDC(0);
- m_hdcMemory := CreateCompatibleDC(hdcScreen);
- hBMP := CreateCompatibleBitmap(hdcScreen, m_Image.GetWidth(), m_Image.GetHeight());
- SelectObject(m_hdcMemory, hBMP);
- // Alpha Value
- if (nTran < 0) or (nTran > 100) then
- nTran := 100;
- m_Blend.SourceConstantAlpha := round(nTran * 2.55); // 1~255
- GetWindowRect(Handle, rct);
- GPGraph := TGPGraphics.Create(m_hdcMemory);
- GPGraph.DrawImage(m_Image, 0, 0, m_Image.GetWidth(), m_Image.GetHeight());
- sizeWindow.cx := m_Image.GetWidth();
- sizeWindow.cy := m_Image.GetHeight();
- ptSrc.x := 0;
- ptSrc.y := 0;
- // Set Window style
- SetWindowLong(Handle, GWL_EXSTYLE, GetWindowLong(Handle, GWL_EXSTYLE) or WS_EX_LAYERED);
- // perform the alpha blend
- UpdateLayeredWindow(Handle, hdcScreen, nil,@sizeWindow, m_hdcMemory, @ptSrc, 0, @m_Blend, ULW_ALPHA);
- //Release resources
- GPGraph.ReleaseHDC(m_hdcMemory);
- ReleaseDC(0, hdcScreen);
- hdcScreen := 0;
- DeleteObject(hBMP);
- DeleteDC(m_hdcMemory);
- m_hdcMemory := 0;
- m_Image.Free;
- GPGraph.Free;
- end;
- procedure TForm1.FormMouseDown(Sender: TObject; Button: TMouseButton;
- Shift: TShiftState; X, Y: Integer);
- begin
- if (Button = mbLeft) then
- begin
- ReleaseCapture();
- Perform(WM_SYSCOMMAND, SC_MOVE or HTCAPTION, 0);
- end;
- end;
- procedure TForm1.About1Click(Sender: TObject);
- begin
- MessageDlg('效果还不行吧!'#13+'QQ:3150379', mtInformation, [mbOK], 0);
- end;
- procedure TForm1.Stayontop1Click(Sender: TObject);
- var
- mi: TMenuItem;
- WindowPos: HWND;
- begin
- mi := Sender as TMenuItem;
- mi.Checked := not mi.Checked;
- if mi.Checked then
- WindowPos := HWND_TOPMOST
- else
- WindowPos := HWND_NOTOPMOST;
- SetWindowPos(Handle, WindowPos,0, 0, 0, 0, SWP_NOMOVE or SWP_NOSIZE);
- end;
- procedure TForm1.mniChangeSkinClick(Sender: TObject);
- var
- dlgOpen: TOpenDialog;
- begin
- dlgOpen := TOpenDialog.Create(Self);
- dlgOpen.Filter := 'PNG file(*.png)|*.png';
- if (dlgOpen.Execute()) then
- begin
- SetTransparent(WideString(dlgOpen.FileName), 100);
- Invalidate();
- end;
- dlgOpen.Free;
- end;
- procedure TForm1.mniCloseClick(Sender: TObject);
- begin
- Close;
- end;
- end.
GDI+用PNG图片做半透明异型窗口的更多相关文章
- GDI+用PNG图片做半透明异型窗口
http://hi.baidu.com/bluew/blog/item/2ecbe58bf93a937d9f2fb4de.html2007-08-09 00:52 我是用PNG图片Alpha透明的方式 ...
- 【C++自绘控件】如何用GDI+来显示图片
在我们制作一个应用软件的时候往往需要在窗口或控件中添加背景图.而图片不仅有BMP格式的,还有JPEG.PNG.TIFF.GIF等其它的格式.那么如何用jpg格式的图片来当背景呢? 这里用到了GDI+, ...
- background-clip 背景图片做适当的裁剪
background-clip 用来将背景图片做适当的裁剪以适应实际需要. 语法: background-clip : border-box | padding-box | content-box | ...
- 机器学习进阶-图像金字塔与轮廓检测-图像金字塔-(**高斯金字塔) 1.cv2.pyrDown(对图片做向下采样) 2.cv2.pyrUp(对图片做向上采样)
1.cv2.pyrDown(src) 对图片做向下采样操作,通常也可以做模糊化处理 参数说明:src表示输入的图片 2.cv2.pyrUp(src) 对图片做向上采样操作 参数说明:src表示输入的 ...
- [翻译] MCProgressView 使用自定义图片做进度显示
MCProgressView 使用自定义图片做进度显示 https://github.com/Baglan/MCProgressView Progress bar view with custom i ...
- python 对图片做垂直投影
Python 对图片做垂直投影 本文利用opencv对图片进行垂直投影,做出垂直投影图,大体思路:打开图片,灰度化,二值化,按列进行统计,新建一个大小和原图一样的图片,按列进行填充: cv2.cv.G ...
- GDI+中GIF图片的显示
某位网友曾经问过我GDI+中Gif图像显示的问题,一直没时间给你写,在此致歉.我把这篇文章送给他. 一.GIF格式介绍 1.概述 GIF(Graphics Interchange Format,图形交 ...
- IE6 png图片实现半透明的方法
IE6中支持PNG半透明图片完美解决方法-divcss5亲測 从IE7及IE7以上版本号都支持PNG半透明格式图片,而只有IE6不支持png格式透明图片,而GIF半透明效果不及png半透明格式图片,由 ...
- GDI+ 支持的图片文件格式
您可以使用许多标准格式将位图储存在磁盘文件中.GDI+ 支持以下各种图片文件格式. o 位图 (BMP) 位图是 Windows 用来储存设备无关和与应用程序无关的图片的标准格式.文件头决定了指定的位 ...
随机推荐
- [cookie篇]cookie-parser之parser.js
cookie-parser的作用,官方的说法是:Parse Cookie header and populate req.cookies with an object keyed by the coo ...
- async异步注解和aspect切面注解等注解的原理
在我们使用spring框架的过程中,在很多时候我们会使用@async注解来异步执行某一些方法,提高系统的执行效率.今天我们来探讨下spring是如何完成这个功能的. 1.spring 在扫描bean的 ...
- centos6.5环境DNS-本地DNS主从服务器bind的搭建
centos6.5环境DNS-本地DNS主从服务器bind的搭建 在上一篇博客中我已经搭建好了一个本地DNS服务器,能够实现正向反向解析,那么我们只需要加入一台从DNS服务器即可完成,我们来开始配置主 ...
- (转载)mysql:设置mysql的远程访问
1.登陆Mysqlmysql -u root -p2.允许任何IP访问,其中密码为admingrant all privileges on *.* to root@"%" iden ...
- 不将EF连接字符串写在配置文件的方法
edmx的构造函数: public DecorationMSEntities() : base(myConfig.DataBaseConnectionString, "DecorationM ...
- 解决spring boot JavaMailSender部分收件人错误导致发送失败的问题
使用spring boot通常使用spring-boot-starter-mail进行邮件的发送.当进行邮件群发的话,如果一个收件人的地址错误,会导致所有邮件都发送失败.因此我们需要在邮件发送失败的时 ...
- Restful对于URL的简化
REST是英文representational state transfer(表象性状态转变)或者表述性状态转移,它是web服务的一种架构风格.使用HTTP,URI,XML,JSON,HTML等广泛流 ...
- python2.x下pip install mysql-python报错解决办法
在https://www.lfd.uci.edu/~gohlke/pythonlibs/#mysql-python 下载该驱动网盘链接:https://pan.baidu.com/s/1r0fNYnU ...
- 记录一起k8s的service服务名解析灵异事件
故障现象: 基于alpine 3.7的镜像,构建的spring boot服务及eureka服务器. 在使用deployment和service文件部署到k8s集群之后, 在不同的pod内部,访问ser ...
- CSS------ul与div如何排成一行
如图: 代码:(需要给div的float属性设置为left) <div style="margin-top:10px"> <div style="flo ...