WinAPI: SetLayeredWindowAttributes - 设置窗口的透明
生活随笔
收集整理的這篇文章主要介紹了
WinAPI: SetLayeredWindowAttributes - 设置窗口的透明
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
這是來賓 Dolby 在 http://www.cnblogs.com/del/archive/2008/03/08/1081295.html#1096814 詢問的問題.
//聲明: SetLayeredWindowAttributes(Hwnd: THandle; {窗口句柄}crKey: COLORREF; {透明色}bAlpha: Byte; {Alpha 值}dwFlags: DWORD {LWA_COLORKEY(=1)表示使用透明色; LWA_ALPHA(=2)表示使用 Alpha 值} ): Boolean; {是否成功設置}//舉例(控制外部程序的透明度, 用計算器舉了個例子): unit Unit1;interfaceusesWindows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,Dialogs, StdCtrls;typeTForm1 = class(TForm)Button1: TButton;Button2: TButton;procedure Button1Click(Sender: TObject);procedure Button2Click(Sender: TObject);end;varForm1: TForm1;implementation{$R *.dfm}{設定計算器的 Alpha 透明} procedure TForm1.Button1Click(Sender: TObject); varh: HWND;FormStyle: Integer; beginh := FindWindow('SciCalc', nil);FormStyle := GetWindowLong(h, GWL_EXSTYLE);SetWindowLong(h, GWL_EXSTYLE, FormStyle or WS_EX_LAYERED);SetLayeredWindowAttributes(h, 0, 128, LWA_ALPHA); end;{設定計算器中的白色透明} procedure TForm1.Button2Click(Sender: TObject); varh: HWND;FormStyle: Integer; beginh := FindWindow('SciCalc', nil);FormStyle := GetWindowLong(h, GWL_EXSTYLE);SetWindowLong(h, GWL_EXSTYLE, FormStyle or WS_EX_LAYERED);SetLayeredWindowAttributes(h, clWhite, 255, LWA_COLORKEY); end;end.
//聲明: SetLayeredWindowAttributes(Hwnd: THandle; {窗口句柄}crKey: COLORREF; {透明色}bAlpha: Byte; {Alpha 值}dwFlags: DWORD {LWA_COLORKEY(=1)表示使用透明色; LWA_ALPHA(=2)表示使用 Alpha 值} ): Boolean; {是否成功設置}//舉例(控制外部程序的透明度, 用計算器舉了個例子): unit Unit1;interfaceusesWindows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,Dialogs, StdCtrls;typeTForm1 = class(TForm)Button1: TButton;Button2: TButton;procedure Button1Click(Sender: TObject);procedure Button2Click(Sender: TObject);end;varForm1: TForm1;implementation{$R *.dfm}{設定計算器的 Alpha 透明} procedure TForm1.Button1Click(Sender: TObject); varh: HWND;FormStyle: Integer; beginh := FindWindow('SciCalc', nil);FormStyle := GetWindowLong(h, GWL_EXSTYLE);SetWindowLong(h, GWL_EXSTYLE, FormStyle or WS_EX_LAYERED);SetLayeredWindowAttributes(h, 0, 128, LWA_ALPHA); end;{設定計算器中的白色透明} procedure TForm1.Button2Click(Sender: TObject); varh: HWND;FormStyle: Integer; beginh := FindWindow('SciCalc', nil);FormStyle := GetWindowLong(h, GWL_EXSTYLE);SetWindowLong(h, GWL_EXSTYLE, FormStyle or WS_EX_LAYERED);SetLayeredWindowAttributes(h, clWhite, 255, LWA_COLORKEY); end;end.
轉載于:https://www.cnblogs.com/del/archive/2008/03/08/1096874.html
總結
以上是生活随笔為你收集整理的WinAPI: SetLayeredWindowAttributes - 设置窗口的透明的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 根本不存在 DIV + CSS 布局这回
- 下一篇: 有意思的批处理