SetLayeredWindowAttributes函数的使用.
2008-04-14 15:38
417 查看
SetLayeredWindowAttributes函数:
hwnd是透明窗体的句柄,
crKey为颜色值,
bAlpha是透明度,取值范围是[0,255],
dwFlags是透明方式,可以取两个值: 当取值为LWA_ALPHA时,crKey参数无效,bAlpha参数有效; 当取值为LWA_COLORKEY时,bAlpha参数有效而窗体中的所有颜色为crKey的地方将变为透明。 LWA_ALPHA = 0x2 LWA_COLORKEY=0x1 要使使窗体拥有透明效果,首先要有WS_EX_LAYERED扩展属性 (旧的sdk没有定义这个属性,所以可以直接指定为0x80000). WS_EX_LAYERED = 0x80000
hwnd是透明窗体的句柄,
crKey为颜色值,
bAlpha是透明度,取值范围是[0,255],
dwFlags是透明方式,可以取两个值: 当取值为LWA_ALPHA时,crKey参数无效,bAlpha参数有效; 当取值为LWA_COLORKEY时,bAlpha参数有效而窗体中的所有颜色为crKey的地方将变为透明。 LWA_ALPHA = 0x2 LWA_COLORKEY=0x1 要使使窗体拥有透明效果,首先要有WS_EX_LAYERED扩展属性 (旧的sdk没有定义这个属性,所以可以直接指定为0x80000). WS_EX_LAYERED = 0x80000
//声明: SetLayeredWindowAttributes( Hwnd: THandle; {窗口句柄} crKey: COLORREF; {透明色} bAlpha: Byte; {Alpha 值} dwFlags: DWORD {LWA_COLORKEY(=1)表示使用透明色; LWA_ALPHA(=2)表示使用 Alpha 值} ): Boolean; {是否成功设置} //举例(控制外部程序的透明度, 用计算器举了个例子): unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls; type TForm1 = class(TForm) Button1: TButton; Button2: TButton; procedure Button1Click(Sender: TObject); procedure Button2Click(Sender: TObject); end; var Form1: TForm1; implementation {$R *.dfm} {设定计算器的 Alpha 透明} procedure TForm1.Button1Click(Sender: TObject); var h: HWND; FormStyle: Integer; begin h := FindWindow('SciCalc', nil); FormStyle := GetWindowLong(Handle, GWL_EXSTYLE); SetWindowLong(h, GWL_EXSTYLE, FormStyle or WS_EX_LAYERED); SetLayeredWindowAttributes(h, 0, 128, LWA_ALPHA); end; {设定计算器中的白色透明} procedure TForm1.Button2Click(Sender: TObject); var h: HWND; FormStyle: Integer; begin h := FindWindow('SciCalc', nil); FormStyle := GetWindowLong(Handle, GWL_EXSTYLE); SetWindowLong(h, GWL_EXSTYLE, FormStyle or WS_EX_LAYERED); SetLayeredWindowAttributes(h, clWhite, 255, LWA_COLORKEY); end; end.
相关文章推荐
- 使用SetLayeredWindowAttributes函数设置窗口透明色与透明度
- SetLayeredWindowAttributes 函数的使用方法,对话框透明的方法
- 设置windows窗口半透明(使用SetLayeredWindowAttributes API函数)
- mfc的窗口透明度调整(SetLayeredWindowAttributes函数)
- SetLayeredWindowAttributes函数:
- UpdateLayeredWindow与SetLayeredWindowAttributes的使用
- (转)xp下实现窗体透明特效/异形窗口SetLayeredWindowAttributes函数
- VC6.0使用SetLayeredWindowAttributes实现透明效果
- 使用SetLayeredWindowAttributes API 实现透明窗口
- 异性窗口 (解决SetLayeredWindowAttributes函数未定义的问题)
- 透明窗口(窗口上面文字图片等内容不透明)的实现(使用SetLayeredWindowAttributes API函数)
- SetLayeredWindowAttributes函数
- 透明化窗口SetLayeredWindowAttributes
- SetLayeredWindowAttributes 创建不规则窗口(此处为椭圆)
- UpdateLayeredWindow和SetLayeredWindowAttributes
- SetLayeredWindowAttributes参数错误
- LoadImage LoadBitmap 调用不同 SetLayeredWindowAttributes 失效
- SetLayeredWindowAttributes未定义的解决方案
- UpdateLayeredWindow和SetLayeredWindowAttributes
- VC++ 实现整个对话框透明的效果SetLayeredWindowAttributes