终于找到了完美的透明窗口源代码,不过是c#的,有谁为大家造福,翻译成delphi!!(50分)

  • 主题发起人 wujingping
  • 开始时间
W

wujingping

Unregistered / Unconfirmed
GUEST, unregistred user!
终于找到了完美的透明窗口源代码,不过是c#的,有谁为大家造福,翻译成delphi!!<br>不过还是不支持98,调用了GDI+引擎,好像关键API是UpdateLayeredWindow。<br>本人不太懂C#,有哪位明白,不妨指教一下。<br><br>完整的zip 源文件在ftp://temp:temp@211.154.84.185/perpxalpha_sharp_src.zip<br>包含测试用的图片和成品exe文件。<br>源代码<br>//<br>// Copyright ?2002 Rui Godinho Lopes &lt;rui@ruilopes.com&gt;<br>// All rights reserved.<br>//<br>// This source file(s) may be redistributed unmodified by any means<br>// PROVIDING they are not sold for profit without the authors expressed<br>// written consent, and providing that this notice and the authors name<br>// and all copyright notices remain intact.<br>//<br>// Any use of the software in source or binary forms, with or without<br>// modification, must include, in the user documentation ("About" box and<br>// printed documentation) and internal comments to the code, notices to<br>// the end user as follows:<br>//<br>// "Portions Copyright ?2002 Rui Godinho Lopes"<br>//<br>// An email letting me know that you are using it would be nice as well.<br>// That's not much to ask considering the amount of work that went into<br>// this.<br>//<br>// THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, <br>// EXPRESS OR IMPLIED. USE IT AT YOUT OWN RISK. THE AUTHOR ACCEPTS NO<br>// LIABILITY FOR ANY DATA DAMAGE/LOSS THAT THIS PRODUCT MAY CAUSE.<br>//<br><br>using System;<br>using System.Drawing;<br>using System.Drawing.Imaging;<br>using System.Windows.Forms;<br>using System.Runtime.InteropServices;<br><br><br>// a static class to expose needed win32 gdi functions.<br>class Win32 {<br><br> public enum Bool {<br> False= 0,<br> True<br> };<br><br> [StructLayout(LayoutKind.Sequential)]<br> public struct Point {<br> public Int32 x;<br> public Int32 y;<br><br> public Point(Int32 x, Int32 y) { this.x= x; this.y= y; }<br> }<br><br> [StructLayout(LayoutKind.Sequential)]<br> public struct Size {<br> public Int32 cx;<br> public Int32 cy;<br><br> public Size(Int32 cx, Int32 cy) { this.cx= cx; this.cy= cy; }<br> }<br><br> [StructLayout(LayoutKind.Sequential, Pack=1)]<br> struct ARGB {<br> public byte Blue;<br> public byte Green;<br> public byte Red;<br> public byte Alpha;<br> }<br><br> [StructLayout(LayoutKind.Sequential, Pack=1)]<br> public struct BLENDFUNCTION {<br> public byte BlendOp;<br> public byte BlendFlags;<br> public byte SourceConstantAlpha;<br> public byte AlphaFormat;<br> }<br><br><br> public const Int32 ULW_COLORKEY = 0x00000001;<br> public const Int32 ULW_ALPHA &nbsp; &nbsp;= 0x00000002;<br> public const Int32 ULW_OPAQUE &nbsp; = 0x00000004;<br><br> public const byte AC_SRC_OVER &nbsp;= 0x00;<br> public const byte AC_SRC_ALPHA = 0x01;<br><br><br> [DllImport("user32.dll", ExactSpelling=true, SetLastError=true)]<br> public static extern Bool UpdateLayeredWindow(IntPtr hwnd, IntPtr hdcDst, ref Point pptDst, ref Size psize, IntPtr hdcSrc, ref Point pprSrc, Int32 crKey, ref BLENDFUNCTION pblend, Int32 dwFlags);<br><br> [DllImport("user32.dll", ExactSpelling=true, SetLastError=true)]<br> public static extern IntPtr GetDC(IntPtr hWnd);<br><br> [DllImport("user32.dll", ExactSpelling=true)]<br> public static extern int ReleaseDC(IntPtr hWnd, IntPtr hDC);<br><br> [DllImport("gdi32.dll", ExactSpelling=true, SetLastError=true)]<br> public static extern IntPtr CreateCompatibleDC(IntPtr hDC);<br><br> [DllImport("gdi32.dll", ExactSpelling=true, SetLastError=true)]<br> public static extern Bool DeleteDC(IntPtr hdc);<br><br> [DllImport("gdi32.dll", ExactSpelling=true)]<br> public static extern IntPtr SelectObject(IntPtr hDC, IntPtr hObject);<br><br> [DllImport("gdi32.dll", ExactSpelling=true, SetLastError=true)]<br> public static extern Bool DeleteObject(IntPtr hObject);<br>}<br><br><br>/// &lt;para&gt;PerPixel forms should derive from this base class&lt;/para&gt;<br>/// &lt;author&gt;&lt;name&gt;Rui Godinho Lopes&lt;/name&gt;&lt;email&gt;rui@ruilopes.com&lt;/email&gt;&lt;/author&gt;<br>class PerPixelAlphaForm : Form {<br><br> /// &lt;para&gt;Changes the current bitmap.&lt;/para&gt;<br> public void SetBitmap(Bitmap bitmap) {<br> SetBitmap(bitmap, 255);<br> }<br><br> /// &lt;para&gt;Changes the current bitmap with a custom opacity level. &nbsp;Here is where all happens!&lt;/para&gt;<br> public void SetBitmap(Bitmap bitmap, byte opacity) {<br> if (bitmap.PixelFormat != PixelFormat.Format32bppArgb)<br> throw new ApplicationException("The bitmap must be 32ppp with alpha-channel.");<br><br> // The ideia of this is very simple,<br> // 1. Create a compatible DC with screen;<br> // 2. Select the bitmap with 32bpp with alpha-channel in the compatible DC;<br> // 3. Call the UpdateLayeredWindow.<br><br> IntPtr screenDc = Win32.GetDC(IntPtr.Zero);<br> IntPtr memDc = Win32.CreateCompatibleDC(screenDc);<br> IntPtr hBitmap = IntPtr.Zero;<br> IntPtr oldBitmap = IntPtr.Zero;<br><br> try {<br> hBitmap = bitmap.GetHbitmap(Color.FromArgb(0)); &nbsp;// grab a GDI handle from this GDI+ bitmap<br> oldBitmap = Win32.SelectObject(memDc, hBitmap);<br><br> Win32.Size size = new Win32.Size(bitmap.Width, bitmap.Height);<br> Win32.Point pointSource = new Win32.Point(0, 0);<br> Win32.Point topPos = new Win32.Point(Left, Top);<br> Win32.BLENDFUNCTION blend = new Win32.BLENDFUNCTION();<br> blend.BlendOp &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; = Win32.AC_SRC_OVER;<br> blend.BlendFlags &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;= 0;<br> blend.SourceConstantAlpha = opacity;<br> blend.AlphaFormat &nbsp; &nbsp; &nbsp; &nbsp; = Win32.AC_SRC_ALPHA;<br><br> Win32.UpdateLayeredWindow(Handle, screenDc, ref topPos, ref size, memDc, ref pointSource, 0, ref blend, Win32.ULW_ALPHA);<br> }<br> finally {<br> Win32.ReleaseDC(IntPtr.Zero, screenDc);<br> if (hBitmap != IntPtr.Zero) {<br> Win32.SelectObject(memDc, oldBitmap);<br> //Windows.DeleteObject(hBitmap); // The documentation says that we have to use the Windows.DeleteObject... but since there is no such method I use the normal DeleteObject from Win32 GDI and it's working fine without any resource leak.<br> Win32.DeleteObject(hBitmap);<br> }<br> Win32.DeleteDC(memDc);<br> }<br> }<br><br> protected override CreateParams CreateParams {<br> get {<br> CreateParams cp = base.CreateParams;<br> cp.ExStyle |= 0x00080000; // This form has to have the WS_EX_LAYERED extended style<br> return cp;<br> }<br> }<br>}<br><br><br><br><br><br><br><br>/// &lt;para&gt;Our test form for this sample application. &nbsp;The bitmap will be displayed in this window.&lt;/para&gt;<br>class MyPerPixelAlphaForm : PerPixelAlphaForm {<br><br> public MyPerPixelAlphaForm() {<br> Text = "PerPixelAlpha Layered Form";<br> TopMost = true;<br> FormBorderStyle = FormBorderStyle.FixedDialog;<br> MinimizeBox = false;<br> MaximizeBox = false;<br> ControlBox = false;<br> }<br><br> // Let Windows drag this window for us<br> protected override void WndProc(ref Message m) {<br> if (m.Msg == 0x0084 /*WM_NCHITTEST*/) {<br> m.Result= (IntPtr)2; // HTCLIENT<br> return;<br> }<br> base.WndProc(ref m);<br> }<br>}<br><br><br><br>///&lt;para&gt;The "controller" dialog box.&lt;/para&gt;<br>class MyForm : Form {<br><br> public MyForm() {<br> Font= new Font("tahoma", 8);<br> Text= "perpixelalpha# - Sample application";<br> FormBorderStyle = FormBorderStyle.FixedDialog;<br> MinimizeBox = false;<br> MaximizeBox = false;<br> ClientSize = new Size(350, 160);<br> StartPosition = FormStartPosition.CenterScreen;<br><br> AllowDrop = true; // Because we want to be a drop target of windows explorer files.<br><br> InitializeComponent();<br> }<br><br> ///&lt;para&gt;Constructs and initializes all child controls of this dialog box.&lt;/para&gt;<br> private void InitializeComponent() {<br><br> // Label with to display current opacity level<br> Label Label1 = new Label();<br> Label1.AutoSize = true;<br> Label1.Location = new System.Drawing.Point(4, 8);<br> Label1.Text = "1. Drag&amp;&amp;Drop an image file from windows explorer into this window.";<br> Controls.Add(Label1);<br><br> Label Label2 = new Label();<br> Label2.AutoSize = true;<br> Label2.Location = new System.Drawing.Point(4, 38);<br> Label2.Text = "2. Play with the opacity level [0..255]:";<br> Controls.Add(Label2);<br><br> // Label with to display current opacity level<br> LabelValue = new Label();<br> LabelValue.AutoSize = true;<br> LabelValue.Location = new System.Drawing.Point(195, 38);<br> LabelValue.Text = "255";<br><br> Controls.Add(LabelValue);<br><br><br><br> // Trackbar to change opacity level<br> Track = new TrackBar();<br><br> Track.Location = new System.Drawing.Point(18, 58);<br> Track.Size = new System.Drawing.Size(310, 0);<br> Track.BeginInit();<br> Track.Maximum = 255;<br> Track.TickFrequency = 5;<br> Track.TickStyle = TickStyle.TopLeft;<br> Track.Value = 255;<br> Track.EndInit();<br><br> Track.ValueChanged += new EventHandler(Track_ValueChanged);<br><br> Controls.Add(Track);<br><br> <br> Label Label3 = new Label();<br> Label3.AutoSize = true;<br> Label3.Location = new System.Drawing.Point(4, 108);<br> Label3.Text = "3. Drag the layered window arround you desktop!";<br> Controls.Add(Label3);<br><br><br> // Label with two links to me! :)<br> LinkLabel Link = new LinkLabel();<br><br> Link.Location = new System.Drawing.Point(4, 140);<br> Link.Size = new System.Drawing.Size(250, 80);<br> Link.Text = "by Rui Lopes &lt;rui@ruilopes.com&gt;";<br> Link.Links.Add(3, 9, &nbsp;"http://www.ruilopes.com");<br> Link.Links.Add(14, 16, "mailto:rui@ruilopes.com");<br><br> Link.LinkClicked += new LinkLabelLinkClickedEventHandler(Link_LinkClicked);<br><br> Controls.Add(Link);<br><br><br> // TestForm will containt the per-pixel-alpha dib<br> TestForm = new MyPerPixelAlphaForm();<br> TestForm.Show();<br> }<br><br> ///&lt;para&gt;Frees our bitmap.&lt;/para&gt;<br> protected override void Dispose(bool disposing) {<br> try {<br> if (disposing &amp;&amp; bitmap != null) {<br> bitmap.Dispose();<br> bitmap = null;<br> }<br> } finally {<br> base.Dispose(disposing);<br> }<br> }<br><br> ///&lt;para&gt;Accepts only Drops of windows explorer files.&lt;/para&gt;<br> protected override void OnDragEnter(DragEventArgs e) {<br> if (e.Data.GetDataPresent(DataFormats.FileDrop))<br> e.Effect = DragDropEffects.Copy;<br> base.OnDragEnter(e);<br> }<br><br> ///&lt;para&gt;Just loads the dropped file from windows explorer.&lt;/para&gt;<br> protected override void OnDragDrop(DragEventArgs e) {<br> string[] files= e.Data.GetData(DataFormats.FileDrop) as string[];<br> if (files != null) {<br> if (files.Length == 1)<br> SetPerPixelBitmapFilename(files[0]);<br> else<br> MessageBox.Show(this, "Please, drop only one image file.", "Too many files dropped", MessageBoxButtons.OK, MessageBoxIcon.Stop);<br> }<br> base.OnDragDrop(e);<br> }<br><br> ///&lt;para&gt;Just load a image file and display it on our test form.&lt;/para&gt;<br> private void SetPerPixelBitmapFilename(string fileName) {<br> Bitmap newBitmap;<br><br> try {<br><br> newBitmap = Image.FromFile(fileName) as Bitmap;<br> TestForm.SetBitmap(newBitmap, (byte)Track.Value);<br><br> } catch (ApplicationException e) {<br> MessageBox.Show(this, e.Message, "Error with bitmap.", MessageBoxButtons.OK, MessageBoxIcon.Error);<br> return;<br> } catch (Exception e) {<br> MessageBox.Show(this, e.Message, "Could not open image file.", MessageBoxButtons.OK, MessageBoxIcon.Error);<br> return;<br> }<br><br> if (bitmap != null)<br> bitmap.Dispose();<br> bitmap = newBitmap;<br> }<br><br><br> ///&lt;para&gt;Change the opacity level of our test form.&lt;/para&gt;<br> private void Track_ValueChanged(object sender, EventArgs e) {<br> byte opacity = (byte)Track.Value;<br> LabelValue.Text = opacity.ToString();<br> LabelValue.Refresh(); // We need this because on slow computers (mine!) the windows takes some time to update our label.<br><br> if (bitmap != null)<br> TestForm.SetBitmap(bitmap, opacity); <br> }<br><br> ///&lt;para&gt;Start the computer browser in the specified uri.&lt;/para&gt;<br> private void Link_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e) {<br> e.Link.Visited = true;<br> using (System.Diagnostics.Process.Start(e.Link.LinkData.ToString())) {<br> }<br> }<br><br><br> // Our member varaibles:<br><br> private Label LabelValue; // label with current opacity level<br> private TrackBar Track; // trackbar to chabge opacity level<br> private MyPerPixelAlphaForm TestForm; // our test form<br> private Bitmap bitmap; // bitmap that is currently displaying on our test form<br>}<br><br><br><br>// Our Great Application!<br>class TheApp {<br> [STAThread]<br> public static void Main() {<br> Application.Run(new MyForm());<br> }<br>}
 
这个控件就可以实现半透明的窗体<br><br>unit SGlass;<br>{*******************************************************<br>&nbsp;* &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;TStainedGlass version 14.06.99 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; *<br>&nbsp;* &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;written by Grigoriev Anton &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; *<br>&nbsp;* &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; *<br>&nbsp;*******************************************************}<br><br>&nbsp;interface<br><br>&nbsp; uses Windows,Messages,SysUtils,Classes,Graphics,Controls,Forms,Dialogs,Math;<br><br>&nbsp; &nbsp;type TTransparencyStyle=(tsConstant,tsHorGradient,tsVertGradient,tsCustom);<br>&nbsp; &nbsp; &nbsp; &nbsp; TBackgroundStyle=(bsSimple,bsMosaic,bsCentered,bsStretched,bsCustom);<br>&nbsp; &nbsp; &nbsp; &nbsp; TTransparency=0..100;<br><br>&nbsp; &nbsp; &nbsp; &nbsp; TGetTransparencyEvent=procedure(Sender:TObject;X,Y,Width,Height:Integer;var Transparency:TTransparency) of object;<br>&nbsp; &nbsp; &nbsp; &nbsp; TCreateBackgroundEvent=procedure(Sender:TObject;Back:TBitmap) of object;<br><br>&nbsp; &nbsp; &nbsp; &nbsp; TStainedGlass=class(TComponent)<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;private<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; FGlyph,ScrImage,Back:TBitmap;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; FTranspStyle:TTransparencyStyle;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; FBackStyle:TBackgroundStyle;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; OldWidth,OldHeight:Integer;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; FTransparency,FAltTransparency:TTransparency;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; FDrawOnDesigning:Boolean;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; OldWndProc:TFarProc;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; NewWndProc:pointer;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; NeedRefresh,Moving:Boolean;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; FDelayTime:Cardinal;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; FOnGetTransparency:TGetTransparencyEvent;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; FOnCreateBackground:TCreateBackgroundEvent;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; procedure HookOwner;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; procedure UnhookOwner;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; procedure SetAltTransparency(Value:TTransparency);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; procedure SetBackStyle(Value:TBackgroundStyle);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; procedure SetDrawOnDesigning(Value:Boolean);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; procedure SetGlyph(Value:TBitmap);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; procedure SetTransparency(Value:TTransparency);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; procedure SetTranspStyle(Value:TTransparencyStyle);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; function ConstantTransparency(X,Y,W,H:Integer):TTransparency;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; function HGTransparency(X,Y,W,H:Integer):TTransparency;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; function VGTransparency(X,Y,W,H:Integer):TTransparency;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; function CustomTransparency(X,Y,W,H:Integer):TTransparency;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; procedure GlyphChanged(Sender:TObject);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;protected<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; procedure CreateBack(W,H:Integer);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; procedure CallDefault(var Msg:TMessage);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; procedure HookWndProc(var Msg:TMessage);virtual;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;public<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; constructor Create(AOwner:TComponent);override;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; destructor Destroy;override;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; procedure Refresh;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;published<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; property AltTransparency:TTransparency read FAltTransparency write SetAltTransparency default 100;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; property BackStyle:TBackgroundStyle read FBackStyle write SetBackStyle default bsSimple;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; property DelayTime:Cardinal read FDelayTime write FDelayTime default 400;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; property DrawOnDesigning:Boolean read FDrawOnDesigning write SetDrawOnDesigning default False;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; property Glyph:TBitmap read FGlyph write SetGlyph;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; property Transparency:TTransparency read FTransparency write SetTransparency default 40;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; property TranspStyle:TTransparencyStyle read FTranspStyle write SetTranspStyle default tsConstant;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; property OnCreateBackground:TCreateBackgroundEvent read FOnCreateBackground write FOnCreateBackground default nil;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; property OnGetTransparency:TGetTransparencyEvent read FOnGetTransparency write FOnGetTransparency default nil;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; end;<br><br>&nbsp; &nbsp; procedure Register;<br><br>&nbsp;implementation<br><br>&nbsp; type TTransparencyFunc=function(X,Y,W,H:Integer):TTransparency of object;<br><br>&nbsp; &nbsp; &nbsp; &nbsp;PRGBArray=^TRGBArray;<br>&nbsp; &nbsp; &nbsp; &nbsp;TRGBArray=array[0..1000000] of TRGBTriple;<br><br>&nbsp; &nbsp;constructor TStainedGlass.Create;<br>&nbsp; &nbsp; var I:Integer;<br>&nbsp; &nbsp; &nbsp;begin<br>&nbsp; &nbsp; &nbsp; if not (AOwner is TForm) then<br>&nbsp; &nbsp; &nbsp; &nbsp;raise EInvalidCast.Create('TStainedGlass can be put on TForm or its destendant only');<br>&nbsp; &nbsp; &nbsp; with AOwner do<br>&nbsp; &nbsp; &nbsp; &nbsp;for I:=0 to ComponentCount-1 do<br>&nbsp; &nbsp; &nbsp; &nbsp; if (Components is TStainedGlass) and (Components&lt;&gt;Self) then<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;raise EComponentError.Create('Only one TStainedGlass component on a form is allowed');<br>&nbsp; &nbsp; &nbsp; inherited Create(AOwner);<br>&nbsp; &nbsp; &nbsp; FGlyph:=TBitmap.Create;<br>&nbsp; &nbsp; &nbsp; FGlyph.OnChange:=GlyphChanged;<br>&nbsp; &nbsp; &nbsp; ScrImage:=TBitmap.Create;<br>&nbsp; &nbsp; &nbsp; ScrImage.Width:=GetSystemMetrics(SM_CXScreen);<br>&nbsp; &nbsp; &nbsp; ScrImage.Height:=GetSystemMetrics(SM_CYScreen);<br>&nbsp; &nbsp; &nbsp; ScrImage.PixelFormat:=pf24Bit;<br>&nbsp; &nbsp; &nbsp; Back:=TBitmap.Create;<br>&nbsp; &nbsp; &nbsp; Back.PixelFormat:=pf24Bit;<br>&nbsp; &nbsp; &nbsp; OldWidth:=-1;<br>&nbsp; &nbsp; &nbsp; OldHeight:=-1;<br>&nbsp; &nbsp; &nbsp; NeedRefresh:=True;<br>&nbsp; &nbsp; &nbsp; FAltTransparency:=100;<br>&nbsp; &nbsp; &nbsp; FBackStyle:=bsSimple;<br>&nbsp; &nbsp; &nbsp; FTransparency:=40;<br>&nbsp; &nbsp; &nbsp; FTranspStyle:=tsConstant;<br>&nbsp; &nbsp; &nbsp; FDelayTime:=400;<br>&nbsp; &nbsp; &nbsp; Moving:=False;<br>&nbsp; &nbsp; &nbsp; FOnCreateBackground:=nil;<br>&nbsp; &nbsp; &nbsp; FOnGetTransparency:=nil;<br>&nbsp; &nbsp; &nbsp; HookOwner<br>&nbsp; &nbsp; &nbsp;end;<br><br>&nbsp; &nbsp;destructor TStainedGlass.Destroy;<br>&nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp;UnhookOwner;<br>&nbsp; &nbsp; &nbsp;ScrImage.Free;<br>&nbsp; &nbsp; &nbsp;FGlyph.Free;<br>&nbsp; &nbsp; &nbsp;Back.Free;<br>&nbsp; &nbsp; &nbsp;inherited Destroy<br>&nbsp; &nbsp; end;<br><br>&nbsp; &nbsp;procedure TStainedGlass.HookOwner;<br>&nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp;if not Assigned(Owner) then<br>&nbsp; &nbsp; &nbsp; Exit;<br>&nbsp; &nbsp; &nbsp;OldWndProc:=TFarProc(GetWindowLong(TForm(Owner).Handle,GWL_WndProc));<br>&nbsp; &nbsp; &nbsp;NewWndProc:=MakeObjectInstance(HookWndProc);<br>&nbsp; &nbsp; &nbsp;SetWindowLong(TForm(Owner).Handle,GWL_WndProc,LongInt(NewWndProc))<br>&nbsp; &nbsp; end;<br><br>&nbsp; &nbsp;procedure TStainedGlass.UnhookOwner;<br>&nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp;if Assigned(Owner) and Assigned(OldWndProc) then<br>&nbsp; &nbsp; &nbsp; SetWindowLong(TForm(Owner).Handle,GWL_WndProc,LongInt(OldWndProc));<br>&nbsp; &nbsp; &nbsp;if Assigned(NewWndProc) then<br>&nbsp; &nbsp; &nbsp; FreeObjectInstance(NewWndProc);<br>&nbsp; &nbsp; &nbsp;NewWndProc:=nil;<br>&nbsp; &nbsp; &nbsp;OldWndProc:=nil<br>&nbsp; &nbsp; end;<br><br>&nbsp; &nbsp;procedure TStainedGlass.CallDefault;<br>&nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp;Msg.Result:=CallWindowProc(OldWndProc,TForm(Owner).Handle,Msg.Msg,Msg.wParam,Msg.lParam)<br>&nbsp; &nbsp; end;<br><br>&nbsp; &nbsp;procedure TStainedGlass.HookWndProc;<br>&nbsp; &nbsp; var DC:HDC;<br>&nbsp; &nbsp; &nbsp; &nbsp; PS:TPaintStruct;<br>&nbsp; &nbsp; &nbsp; &nbsp; CW,CH,CX,CY:Integer;<br>&nbsp; &nbsp; &nbsp; &nbsp; SL,BL:pRGBArray;<br>&nbsp; &nbsp; &nbsp; &nbsp; X,Y,T:Integer;<br>&nbsp; &nbsp; &nbsp; &nbsp; TicksNow:Integer;<br>&nbsp; &nbsp; &nbsp; &nbsp; BM2:TBitmap;<br>&nbsp; &nbsp; &nbsp; &nbsp; TranspFunc:TTransparencyFunc;<br>&nbsp; &nbsp; &nbsp;begin<br>&nbsp; &nbsp; &nbsp; case Msg.Msg of<br>&nbsp; &nbsp; &nbsp; &nbsp;WM_Paint:if (csDesigning in ComponentState) and not FDrawOnDesigning then<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;CallDefault(Msg)<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; else<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;with Owner as TForm do<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if Msg.WParam&lt;&gt;0 then<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; raise EComponentError.Create('TStainedGlass: incompatibilities were detected. See ReadMe file');<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;CW:=ClientWidth;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;CH:=ClientHeight;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;CX:=ClientOrigin.X;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;CY:=ClientOrigin.Y;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if not Moving then<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;ShowWindow(Handle,SW_Hide);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;SetActiveWindow(0);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;TicksNow:=GetTickCount;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;repeat<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Application.ProcessMessages<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;until GetTickCount-TicksNow&gt;=DelayTime;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;DC:=GetDC(0);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;BitBlt(ScrImage.Canvas.Handle,0,0,ScrImage.Width,ScrImage.Height,DC,0,0,SrcCopy);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;ReleaseDC(0,DC)<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; end;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;BM2:=TBitmap.Create;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;BM2.Width:=CW+1;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;BM2.Height:=CH+1;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;BM2.PixelFormat:=pf24bit;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;BM2.Canvas.Draw(-CX,-CY,ScrImage);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if NeedRefresh or (CW&lt;&gt;OldWidth) or (CH&lt;&gt;OldHeight) then<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; CreateBack(CW,CH);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;case FTranspStyle of<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; tsConstant:TranspFunc:=ConstantTransparency;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; tsHorGradient:TranspFunc:=HGTransparency;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; tsVertGradient:TranspFunc:=VGTransparency;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; tsCustom:if Assigned(FOnGetTransparency) then<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; TranspFunc:=CustomTransparency<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;else<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; TranspFunc:=ConstantTransparency<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;end;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;for Y:=0 to CH do<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;SL:=BM2.ScanLine[Y];<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;BL:=Back.ScanLine[Y];<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;for X:=0 to CW do<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;T:=TranspFunc(X,Y,CW,CH);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;SL[X].rgbtRed:=(T*SL[X].rgbtRed+(100-T)*BL[X].rgbtRed) div 100;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;SL[X].rgbtGreen:=(T*SL[X].rgbtGreen+(100-T)*BL[X].rgbtGreen) div 100;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;SL[X].rgbtBlue:=(T*SL[X].rgbtBlue+(100-T)*BL[X].rgbtBlue) div 100<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; end<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; end;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;ShowWindow(Handle,SW_Show);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Msg.WParam:=BeginPaint(Handle,PS);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;BitBlt(Msg.WParam,0,0,BM2.Width,BM2.Height,BM2.Canvas.Handle,0,0,SrcCopy);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;BM2.Free;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;CallDefault(Msg);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;EndPaint(Handle,PS)<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; end;<br>&nbsp; &nbsp; &nbsp; &nbsp;WM_EraseBkgnd:if (csDesigning in ComponentState) and not FDrawOnDesigning then<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; CallDefault(Msg)<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;else<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Msg.Result:=1;<br>&nbsp; &nbsp; &nbsp; &nbsp;WM_WindowPosChanged:begin<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; CallDefault(Msg);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if not (csDesigning in ComponentState) or FDrawOnDesigning then<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;TForm(Owner).Invalidate<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;end;<br>&nbsp; &nbsp; &nbsp; &nbsp;WM_EnterSizeMove:begin<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Moving:=True;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;CallDefault(Msg)<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; end;<br>&nbsp; &nbsp; &nbsp; &nbsp;WM_ExitSizeMove:begin<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; CallDefault(Msg);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Moving:=False<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;end;<br>&nbsp; &nbsp; &nbsp; &nbsp;WM_DisplayChange:begin<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;CallDefault(Msg);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;ScrImage.Width:=Msg.LParamLo;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;ScrImage.Height:=Msg.LParamHi;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Refresh<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; end<br>&nbsp; &nbsp; &nbsp; else<br>&nbsp; &nbsp; &nbsp; &nbsp;CallDefault(Msg)<br>&nbsp; &nbsp; &nbsp; end<br>&nbsp; &nbsp; &nbsp;end;<br><br>&nbsp; &nbsp;procedure TStainedGlass.CreateBack;<br>&nbsp; &nbsp; var WX,W1,HX,H1,FY,FX:Integer;<br>&nbsp; &nbsp; &nbsp;begin<br>&nbsp; &nbsp; &nbsp; NeedRefresh:=False;<br>&nbsp; &nbsp; &nbsp; OldWidth:=W;<br>&nbsp; &nbsp; &nbsp; OldHeight:=H;<br>&nbsp; &nbsp; &nbsp; Back.Width:=W+1;<br>&nbsp; &nbsp; &nbsp; Back.Height:=H+1;<br>&nbsp; &nbsp; &nbsp; with Back.Canvas do<br>&nbsp; &nbsp; &nbsp; &nbsp;begin<br>&nbsp; &nbsp; &nbsp; &nbsp; Pen.Style:=psClear;<br>&nbsp; &nbsp; &nbsp; &nbsp; Brush.Style:=bsSolid;<br>&nbsp; &nbsp; &nbsp; &nbsp; Brush.Color:=TForm(Owner).Color;<br>&nbsp; &nbsp; &nbsp; &nbsp; Rectangle(0,0,W+1,H+1);<br>&nbsp; &nbsp; &nbsp; &nbsp; case FBackStyle of<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;bsMosaic:if not FGlyph.Empty then<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;begin<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; WX:=FGlyph.Width;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; HX:=FGlyph.Height;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; FY:=0;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; while FY&lt;H do<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;begin<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; H1:=MinIntValue([H-FY,HX]);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; FX:=0;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; while FX&lt;W do<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;begin<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; W1:=MinIntValue([W-FX,WX]);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Draw(FX,FY,FGlyph);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Inc(FX,W1)<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;end;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Inc(FY,H1)<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;end<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;end;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;bsCentered:if not FGlyph.Empty then<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Draw((W-FGlyph.Width) div 2,(H-FGlyph.Height) div 2,FGlyph);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;bsStretched:if not FGlyph.Empty then<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; StretchDraw(Rect(0,0,W,H),FGlyph);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;bsCustom:if Assigned(FOnCreateBackground) then<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;FOnCreateBackground(Self,Back)<br>&nbsp; &nbsp; &nbsp; &nbsp; end<br>&nbsp; &nbsp; &nbsp; &nbsp;end<br>&nbsp; &nbsp; &nbsp;end;<br><br>&nbsp; &nbsp;procedure TStainedGlass.Refresh;<br>&nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp;NeedRefresh:=True;<br>&nbsp; &nbsp; &nbsp;TForm(Owner).Invalidate<br>&nbsp; &nbsp; end;<br><br>&nbsp; &nbsp;procedure TStainedGlass.SetAltTransparency;<br>&nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp;if Value&lt;&gt;FAltTransparency then<br>&nbsp; &nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; &nbsp;FAltTransparency:=Value;<br>&nbsp; &nbsp; &nbsp; &nbsp;if FTranspStyle&lt;&gt;tsConstant then<br>&nbsp; &nbsp; &nbsp; &nbsp; TForm(Owner).Invalidate<br>&nbsp; &nbsp; &nbsp; end<br>&nbsp; &nbsp; end;<br><br>&nbsp; &nbsp;procedure TStainedGlass.SetBackStyle;<br>&nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp;if Value&lt;&gt;FBackStyle then<br>&nbsp; &nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; &nbsp;FBackStyle:=Value;<br>&nbsp; &nbsp; &nbsp; &nbsp;Refresh<br>&nbsp; &nbsp; &nbsp; end<br>&nbsp; &nbsp; end;<br><br>&nbsp; &nbsp;procedure TStainedGlass.SetDrawOnDesigning;<br>&nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp;FDrawOnDesigning:=Value;<br>&nbsp; &nbsp; &nbsp;if csDesigning in ComponentState then<br>&nbsp; &nbsp; &nbsp; TForm(Owner).Invalidate<br>&nbsp; &nbsp; end;<br><br>&nbsp; &nbsp;procedure TStainedGlass.SetGlyph;<br>&nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp;FGlyph.Assign(Value);<br>&nbsp; &nbsp; &nbsp;Refresh<br>&nbsp; &nbsp; end;<br><br>&nbsp; &nbsp;procedure TStainedGlass.SetTransparency;<br>&nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp;if Value&lt;&gt;FTransparency then<br>&nbsp; &nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; &nbsp;FTransparency:=Value;<br>&nbsp; &nbsp; &nbsp; &nbsp;TForm(Owner).Invalidate<br>&nbsp; &nbsp; &nbsp; end<br>&nbsp; &nbsp; end;<br><br>&nbsp; &nbsp;procedure TStainedGlass.SetTranspStyle;<br>&nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp;if Value&lt;&gt;FTranspStyle then<br>&nbsp; &nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; &nbsp;FTranspStyle:=Value;<br>&nbsp; &nbsp; &nbsp; &nbsp;TForm(Owner).Invalidate<br>&nbsp; &nbsp; &nbsp; end<br>&nbsp; &nbsp; end;<br><br>&nbsp; &nbsp;function TStainedGlass.ConstantTransparency;<br>&nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp;Result:=FTransparency<br>&nbsp; &nbsp; end;<br><br>&nbsp; &nbsp;function TStainedGlass.HGTransparency;<br>&nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp;Result:=Transparency+Round((AltTransparency-Transparency)/W*X)<br>&nbsp; &nbsp; end;<br><br>&nbsp; &nbsp;function TStainedGlass.VGTransparency;<br>&nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp;Result:=Transparency+Round((AltTransparency-Transparency)/H*Y)<br>&nbsp; &nbsp; end;<br><br>&nbsp; &nbsp;function TStainedGlass.CustomTransparency;<br>&nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp;FOnGetTransparency(Self,X,Y,W,H,Result)<br>&nbsp; &nbsp; end;<br><br>&nbsp; &nbsp;procedure TStainedGlass.GlyphChanged;<br>&nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp;TForm(Owner).Invalidate<br>&nbsp; &nbsp; end;<br><br>&nbsp; &nbsp;procedure Register;<br>&nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp;RegisterComponents('SGlass', [TStainedGlass])<br>&nbsp; &nbsp; end;<br><br>&nbsp;end.
 
代码不错呀!
 
拖动窗口后显示得时候有点慢
 
好长呀,我记得一本书是有做透明窗口的,&lt;Delphi程序设计&gt;清华大学出版社,蒋方帅:编著<br>是黑是面的,书的内容一般,你的要求里面好象有.<br>
 
不用这么复杂去翻译吧。网上多得看不过来。
 
将 Form 的 Alphablend 属性设为 true。然后调整 AlphablendValue 的值,即可<br>调整窗体的透明度。
 
UpdateLayeredWindow 和SetLayeredWindowAttributes是win32标准函数.<br>delphi可直接调用
 
能支持98才是真的牛<br><br>我记得在一个比赛看见用汇编实现的<br><br>牛啊
 
还要这么复杂啊?Delphi的TForm有属性设置的,不用写代码,看来大家都觉得从汇编写一个操作系统然后写一个Delphi最好了
 
这个透明窗口的含义不是简单的重复D6-D7已经有的功能,而是将一张带透明通道的PNG图片直接平滑的显示在桌面上。大家不是经常讨论不规则窗口吗?可是那样窗口是有锯齿的,也不可能显示漂亮的发光啦阴影啦之类的。如果要渐变透明怎么办?用图片来控制透明度是真正解决问题的方法。其实这一段C#程序有用的部分并不多,因为有大量代码是在描述软件界面,作者想一个文件搞定一切,所以才这样,我在google上搜了很久才找到一篇是我想要的东西,好多人对这个东西并没有看清楚,其实要让一个窗口半透明只要用到SetLayeredWindowAttributes 这个API,不需要用UpdateLayeredWindow,如果要做图片控制透明/半透明则一定要用UpdateLayeredWindow,我在google上搜索了好多有关代码,在大富翁上也找了不少,很多人在前面都把UpdateLayeredWindow声明好了,程序里面却根本没有用到过,不知是否仔细思考过,还是人云亦云的"COPY"了过来呢?<br>有多少人真的下载了我的DEMO文件运行了呢?
 
.NET 本来窗体就有这个属性设置,还用得着写代码?
 
那么长,狂晕呀。。。
 
高手如云!
 
终于搞定,ftp://temp:temp@211.154.84.185/ddd.rar ,大约1.6M,exe和dll解压到同一文件夹下,“./images/” 里面有15张PNG图片,运行一下,很好看的,我用三维做的。<br>技术上的问题基本解决,CPU占用也不多。<br>
 
你们研究过delphi的 源代码吗<br>在forms.pas中,有关于AlphaBlend的部分<br>我把他们摘出来,让大家看一看<br>TCustomForm = class(TScrollingWinControl)<br>private<br>&nbsp; ... ...<br>&nbsp; FAlphaBlend: Boolean;<br>&nbsp; FAlphaBlendValue: Byte;<br>&nbsp; ... ...<br>&nbsp; procedure SetAlphaBlend(const Value: Boolean);<br>&nbsp; procedure SetAlphaBlendValue(const Value: Byte);<br>&nbsp; ... ...<br>&nbsp; procedure SetLayeredAttribs;<br>&nbsp; ... ...<br>protected<br>&nbsp; ... ...<br>&nbsp; property AlphaBlend: Boolean read FAlphaBlend write SetAlphaBlend;<br>&nbsp; property AlphaBlendValue: Byte read FAlphaBlendValue write SetAlphaBlendValue;<br>&nbsp; ... ...<br>&nbsp; ... ...<br>end;<br><br>procedure TCustomForm.SetAlphaBlend(const Value: Boolean);<br>begin<br>&nbsp; if FAlphaBlend &lt;&gt; Value then<br>&nbsp; begin<br>&nbsp; &nbsp; FAlphaBlend := Value;<br>&nbsp; &nbsp; SetLayeredAttribs;<br>&nbsp; end;<br>end;<br><br>procedure TCustomForm.SetAlphaBlendValue(const Value: Byte);<br>begin<br>&nbsp; if FAlphaBlendValue &lt;&gt; Value then<br>&nbsp; begin<br>&nbsp; &nbsp; FAlphaBlendValue := Value;<br>&nbsp; &nbsp; SetLayeredAttribs;<br>&nbsp; end;<br>end;<br><br>procedure TCustomForm.SetLayeredAttribs;<br>const<br>&nbsp; cUseAlpha: array [Boolean] of Integer = (0, LWA_ALPHA);<br>&nbsp; cUseColorKey: array [Boolean] of Integer = (0, LWA_COLORKEY);<br>var<br>&nbsp; AStyle: Integer;<br>begin<br>&nbsp; if not (csDesigning in ComponentState) and<br>&nbsp; &nbsp; (Assigned(SetLayeredWindowAttributes)) and HandleAllocated then<br>&nbsp; begin<br>&nbsp; &nbsp; AStyle := GetWindowLong(Handle, GWL_EXSTYLE);<br>&nbsp; &nbsp; if FAlphaBlend or FTransparentColor then<br>&nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; if (AStyle and WS_EX_LAYERED) = 0 then<br>&nbsp; &nbsp; &nbsp; &nbsp; SetWindowLong(Handle, GWL_EXSTYLE, AStyle or WS_EX_LAYERED);<br>&nbsp; &nbsp; &nbsp; SetLayeredWindowAttributes(Handle, FTransparentColorValue, FAlphaBlendValue,<br>&nbsp; &nbsp; &nbsp; &nbsp; cUseAlpha[FAlphaBlend] or cUseColorKey[FTransparentColor]);<br>&nbsp; &nbsp; end<br>&nbsp; &nbsp; else<br>&nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; SetWindowLong(Handle, GWL_EXSTYLE, AStyle and not WS_EX_LAYERED);<br>&nbsp; &nbsp; &nbsp; RedrawWindow(Handle, nil, 0, RDW_ERASE or RDW_INVALIDATE or RDW_FRAME or RDW_ALLCHILDREN);<br>&nbsp; &nbsp; end;<br>&nbsp; end;<br>end;<br><br>&nbsp; ... &nbsp;...<br>procedure InitProcs;<br>const<br>&nbsp; sUser32 = 'User32.dll';<br>var<br>&nbsp; ModH: HMODULE;<br>begin<br>&nbsp; ModH := GetModuleHandle(sUser32);<br>&nbsp; if ModH &lt;&gt; 0 then<br>&nbsp; &nbsp; &nbsp;@SetLayeredWindowAttributes := GetProcAddress(ModH, 'SetLayeredWindowAttributes');<br>end;<br>&nbsp;... ...<br>&nbsp;... ...<br>initialization<br>&nbsp; InitProcs;<br><br>这是真对于窗体的,其他的控件,也是这个样子的<br>知道了吗
 
wujingping &nbsp;你好,你的那个例子是用DELPHI做的吗?如果是DELPHI做的,能不能<br>把源码给我发一个,学习研究。谢谢!<br>lovezuere@sina.com
 
我用了gdi+引擎,程序还在修改,先贴出一部分关键的吧。<br>找个gdi+引擎先看看,不然其他部分也不明白。<br><br>Function UpdateLayeredWindow(hWnd : HWND;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; hdcDst : HDC; pptDst : PPoint; psize : PSize;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; hdcSrc : HDC; pptSrc : PPoint;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; crKey &nbsp;: COLORREF;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; pblend : PBlendFunction;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; dwFlags : DWORD): BOOL; stdcall;<br>//--------------------------------------------------------<br>const<br>&nbsp; WS_EX_LAYERED = $80000;<br>&nbsp; LWA_COLORKEY &nbsp;= 1;<br>&nbsp; LWA_ALPHA &nbsp; &nbsp; = 2;<br>&nbsp; ULW_COLORKEY &nbsp;= 1;<br>&nbsp; ULW_ALPHA &nbsp; &nbsp; = 2;<br>&nbsp; ULW_OPAQUE &nbsp; &nbsp;= 4;<br>//--------------------------------------------------------<br><br>var<br>&nbsp; Form1: TForm1;<br>&nbsp; bmp, old_bmp : HBITMAP;<br>&nbsp; DC : HDC;<br>&nbsp; bitmap:array[1..15] of tgpbitmap;<br>&nbsp; j:integer;<br>//---------------------------------------------------------<br>Function UpdateLayeredWindow; external 'user32.dll';<br><br>//--------------------------------------------------------<br>procedure TForm1.Timer1Timer(Sender: TObject);<br>var<br>&nbsp; pt1, pt2 : TPoint;<br>&nbsp; sz : TSize;<br>&nbsp; bf : TBlendFunction;<br>begin<br>&nbsp; if j&gt;15 then j:=1;<br>&nbsp; pt1 := Point(left, top);<br>&nbsp; pt2 := Point(0, 0);<br>&nbsp; sz.cx := bitmap[1].GetWidth;<br>&nbsp; sz.cy := bitmap[1].GetHeight;<br>&nbsp; bf.BlendOp := AC_SRC_OVER;<br>&nbsp; bf.BlendFlags := 0;<br>&nbsp; bf.SourceConstantAlpha := $ff;<br>&nbsp; bf.AlphaFormat := AC_SRC_ALPHA;<br>&nbsp; //-----------------------------------<br>&nbsp; DeleteObject(bmp);<br>&nbsp; [red]bitmap[j].GetHBITMAP(0,bmp);[/red]<br>&nbsp; DeleteDC(DC);<br>&nbsp; [red]DC := CreateCompatibleDC(Canvas.Handle);[/red]<br>&nbsp; old_bmp := SelectObject(DC, bmp);<br>&nbsp; [red]UpdateLayeredWindow(Handle, Canvas.Handle, @pt1, @sz, DC, @pt2,0, @bf,ULW_ALPHA);[/red]<br>&nbsp; j:=j+1;<br>end;
 
wujingping的代码不知道在98下能不能运行,<br>不过SetLayeredWindowAttributes和Delphi的Alphablend、AlphablendValue在98下绝对不行<br>因为那函数只有在2K以上才可以的,可是我贴的那控件就可以在98下运行,虽然拖动后太恶心了点[:D]
 
顶部