使用PNG实现半透明的窗体(使用GDI+)
看来必须的初始化gdiplus。
unit CJ7Unit;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs;
type
TFormCJ7 = class(TForm)
procedure FormCreate(Sender: TObject);
procedure FormMouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
private
{ Private declarations }
public
{ Public declarations }
end;
var
FormCJ7: TFormCJ7;
implementation
{$R *.dfm}
uses ActiveX;
type
DebugEventLevel = (
DebugEventLevelFatal,
DebugEventLevelWarning
);
TDebugEventLevel = DebugEventLevel;
DebugEventProc = procedure(level: DebugEventLevel; message: PChar); stdcall;
GdiplusStartupInput = packed record
GdiplusVersion: Cardinal;
DebugEventCallback: DebugEventProc;
SuppressBackgroundThread: BOOL;
SuppressExternalCodecs: BOOL;
end;
TGdiplusStartupInput = GdiplusStartupInput;
PGdiplusStartupInput = ^TGdiplusStartupInput;
NotificationHookProc = function(out token: ULONG): Integer; stdcall;
NotificationUnhookProc = procedure(token: ULONG); stdcall;
GdiplusStartupOutput = packed record
NotificationHook : NotificationHookProc;
NotificationUnhook: NotificationUnhookProc;
end;
TGdiplusStartupOutput = GdiplusStartupOutput;
PGdiplusStartupOutput = ^TGdiplusStartupOutput;
function GdipCreateHBITMAPFromBitmap(bitmap: THandle; out hbmReturn: HBITMAP;
background: Longword): Integer; stdcall; external 'gdiplus.dll';
function GdipCreateBitmapFromFile(filename: PWChar; out bitmap: THandle): Integer;
stdcall; external 'gdiplus.dll';
function GdipCreateBitmapFromStreamICM(stream: ISTREAM;
out bitmap: THandle): Integer; stdcall; external 'gdiplus.dll';
function GdipDisposeImage(image: THandle): Integer; stdcall;
stdcall; external 'gdiplus.dll';
function GdiplusStartup(out token: ULONG; input: PGdiplusStartupInput;
output: PGdiplusStartupOutput): Integer; stdcall; external 'gdiplus.dll';
procedure GdiplusShutdown(token: ULONG); stdcall; external 'gdiplus.dll';
procedure TFormCJ7.FormCreate(Sender: TObject);
var
vGdip: THandle;
vBitmap: HBITMAP;
vOldBitmap: HBITMAP;
vPoint1, vPoint2: TPoint;
vSize: TSize;
vBlendFunction: TBlendFunction;
vDC: HDC;
vBitmapInfo: TBitmapInfoHeader;
vDIBSection: TDIBSection;
vBuffer: PChar;
vStream: IStream;
vGlobal: THandle;
begin
SetWindowLong(Handle, GWL_EXSTYLE,
GetWindowLong(Handle, GWL_EXSTYLE) or WS_EX_LAYERED);
///////Begin 从资源中载入
with TResourceStream.Create(HInstance, 'Png_Cj7', 'PNG') do try
vGlobal := GlobalAlloc(GHND, Size);
if vGlobal = 0 then Exit;
vBuffer := GlobalLock(vGlobal);
if not Assigned(vBuffer) then Exit;
try
Read(vBuffer^, Size);
finally
GlobalUnlock(vGdip);
end;
if CreateStreamOnHGlobal(vGlobal, False, vStream) <> S_OK then Exit;
if GdipCreateBitmapFromStreamICM(vStream, vGdip) <> S_OK then Exit;
GlobalFree(vGlobal);
finally
Free;
end;
///////End 从资源中载入
if GdipCreateHBITMAPFromBitmap(vGdip, vBitmap, 0) <> S_OK then Exit;
vBitmapInfo.biSize := SizeOf(vBitmapInfo);
GetObject(vBitmap, SizeOf(vDIBSection), @vDIBSection);
vPoint1 := Point(Left, Top);
vPoint2 := Point(0, 0);
vSize.cx := vDIBSection.dsBm.bmWidth;
vSize.cy := vDIBSection.dsBm.bmHeight;
vBlendFunction.BlendOp := AC_SRC_OVER;
vBlendFunction.BlendFlags := 0;
vBlendFunction.SourceConstantAlpha := $FF; // 透明度
vBlendFunction.AlphaFormat := AC_SRC_ALPHA; //同上
vDC := CreateCompatibleDC(Canvas.Handle);
vOldBitmap := SelectObject(vDC, vBitmap);
UpdateLayeredWindow(Handle, Canvas.Handle,
@vPoint1, @vSize, vDC, @vPoint2, 0, @vBlendFunction, ULW_ALPHA);
SelectObject(vDC, vOldBitmap);
DeleteDC(vDC);
DeleteObject(vBitmap);
GdipDisposeImage(vGdip);
end;
procedure TFormCJ7.FormMouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
ReleaseCapture;
Perform(WM_SYSCOMMAND, SC_MOVE or HTCLIENT, 0); // 拖动
end;
var
vStartupInput: TGDIPlusStartupInput;
vToken: ULONG;
initialization
vStartupInput.DebugEventCallback := nil;
vStartupInput.SuppressBackgroundThread := False;
vStartupInput.SuppressExternalCodecs := False;
vStartupInput.GdiplusVersion := 1;
GdiplusStartup(vToken, @vStartupInput, nil);
finalization
GdiplusShutdown(vToken);
end.
想了解gdi+的资料可以参考:
http://msdn2.microsoft.com/en-us/library/ms533798.aspx
http://blog.csdn.net/zswang/article/details/2119649
使用PNG实现半透明的窗体(使用GDI+)的更多相关文章
- GDI+用PNG图片做半透明异型窗口
http://hi.baidu.com/bluew/blog/item/2ecbe58bf93a937d9f2fb4de.html2007-08-09 00:52 我是用PNG图片Alpha透明的方式 ...
- 完美PNG半透明窗体解决方案
当年Vista系统刚出来的时候,最吸引人的莫过于半透明磨砂的窗体界面了,迷倒了多少人.这个界面技术随即引发了编程界的一阵骚动,很多人都在问:如何实现这一界面效果?当然,在Vista下倒是很简单,系统本 ...
- Windows 窗体的.Net 框架绘图技术
当编写一个典型的Windows 窗体程序时,窗体和控件的绘制.效果等操作是不需要特别加以考虑的.这是为什么呢?因为通过使用 .Net 框架,开发人员可以拖动一系列的控件到窗体上,并书写一些简单的与事件 ...
- 使用绘图API自定义组件
-----------------siwuxie095 工程名:CustomizeSwing 包名:com.siwuxie095.swi ...
- 为组件设定UI
-----------------siwuxie095 工程名:CustomizeSwing 包名:com.siwuxie095.swing 类 ...
- WPF绘制自定义窗口
原文:WPF绘制自定义窗口 WPF是制作界面的一大利器,下面就用WPF模拟一下360的软件管理界面,360软件管理界面如下: 界面不难,主要有如下几个要素: 窗体的圆角 自定义标题栏及按钮 自定义状态 ...
- 网易云信Duilib开发实践和Windows应用界面开发框架源码开源介绍
序言 Duilib介绍 Duilib是windows平台下的一款轻量级directUI开源库(遵循BSD协议),完全免费,可用于商业软件开发,只需在软件包里附上协议文件即可.Duilib可以简单方便地 ...
- gdi+ 高速绘制透明窗体
gdi+ 高速绘制透明窗体: 方法一: 1.用Iamge对象载入png资源, 2.调用drawimage函数讲图片绘制出了 3.UpdateLayeredWindow对窗体进行布局 方法二: 1.用B ...
- 用C++实现半透明按钮控件(PNG,GDI+)
使用MFC实现上面的按钮半透明效果能看到父窗口中的内容,上面是效果图(一个是带背景图片的.另一个是不带的). 控件继承自CWnd类(彩色的部分是窗口的背景图片.按钮是PNG图片,第二个图标是鼠 ...
随机推荐
- JS----checked----checked选中和未选中的获取
, allValue.length - 1); allValue = allValue.replace(/[ ]/g, ""); var checkedIds = allValue ...
- React为啥很多类里的标签上事件处理函数要用bind(this)
render() { return ( <div> <p onClick={this.clickHandler.bind(this)}>vz</p> </di ...
- 【45.61%】【codeforces 701D】As Fast As Possible
time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...
- 【u253】售货厅
Time Limit: 1 second Memory Limit: 128 MB [问题描述] 售票厅出售关于音乐会的票,取代原来的卖一张票的形式,而是一组座号连续的票.售票室已经收到很多预订.每个 ...
- .net 程序员 两年工作总结
2013 年7月毕业,算一算从开始在现任的公司实习到现在已经有小两年的时间了.公司的工作虽然不忙,但也一直没有时间思考一下. 现在决定辞职了,忽然一下轻松的让人想思考. 普通程序员.普通本科生.普通的 ...
- 图灵机(Turing Machine)
图灵机,又称图灵计算.图灵计算机,是由数学家阿兰·麦席森·图灵(1912-1954)提出的一种抽象计算模型,即将人们使用纸笔进行数学运算的过程进行抽象,由一个虚拟的机器替代人们进行数学运算. 所谓的图 ...
- GetEntryAssembly、GetExecutingAssembly和GetCallingAssembly的区别
GetEntryAssembly获取的是当前应用程序第一个启动的程序,一般就是xxx.exe文件. GetExecutingAssembly获取的是当前执行的方法所在的程序文件,可能是.exe,也可能 ...
- WPF 获取 ListView DataTemplate 中控件值
原文:WPF 获取 ListView DataTemplate 中控件值 版权声明:本文为博主原创文章,未经博主允许可以随意转载 https://blog.csdn.net/songqingwei19 ...
- 32位与64位、单精度(single-precision)与双精度(double-precision)
What's the difference between a single precision and double precision floating point operation? 0. 6 ...
- C# 有道API翻译 查询单词详细信息
原文:C# 有道API翻译 查询单词详细信息 有道云官方文档 有道云翻译API简介:http://ai.youdao.com/docs/doc-trans-api.s#p01 有道云C#Demo : ...