使用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图片,第二个图标是鼠 ...
随机推荐
- C#编写TensorFlow人工智能应用
C#编写TensorFlow人工智能应用 TensorFlowSharp入门使用C#编写TensorFlow人工智能应用学习. TensorFlow简单介绍 TensorFlow 是谷歌的第二代机器学 ...
- 卷积神经网络(CNN)与特殊的卷积
各种卷积操作的可视化的显示形式:GitHub - vdumoulin/conv_arithmetic: A technical report on convolution arithmetic in ...
- 手机预览微信小程序
1. 获取微信小程序的 AppID 登录 https://mp.weixin.qq.com ,就可以在网站的“设置”-“开发者设置”中,查看到微信小程序的 AppID 了,注意不可直接使用服务号或订阅 ...
- 更改linux的最大文件描述符限制
To ensure good server performance, the total number of client connections, database files, and log f ...
- matlab 小波处理工具箱
1. wavedec:多尺度(multilevel)一维小波分解 [C,L] = wavedec(X,N,'wname') [C,L] = wavedec(X,N,Lo_D,Hi_D) 返回值 L(b ...
- docker入门3:基础操作(2)
-- 容器删除 docker rm CONTAIN_ID|CONTAIN_NAME -- 镜像删除 docker rmi IMAGE_ID|IMAGE_NAME -- 进入容器 docker exec ...
- PLC中ST语言的几种程序流程控制语句
ST语言是IEC61131-3中规定的5中标准语言之一,目前常用见品牌的PLC都支持这种语言(施耐德,AB可以直接选择创建该类型的程序段或者功能块,西门子的略微麻烦一点),ST语言的一个好处是移植性好 ...
- Codeforces 449 B. Jzzhu and Cities
堆优化dijkstra,假设哪条铁路能够被更新,就把相应铁路删除. B. Jzzhu and Cities time limit per test 2 seconds memory limit per ...
- Android 4.0开发之GridLayOut布局实践
在上一篇教程中http://blog.csdn.net/dawanganban/article/details/9952379,我们初步学习了解了GridLayout的布局基本知识,通过学习知道,Gr ...
- 详尽分析世纪之战:360VS腾讯是两个阶层的抗争
很不错的一篇文字 分析的也很透彻 [转自中国移动http://labs.chinamobile.com/] 来源:搜狐IT 作者:吃熊掌的鱼 2010-11-01 10:11:51 [ 13967阅 ...