给你看看我以前写的一个FORM里的代码, 在WIN2K下有渐显的效果,在WIN9X下也不会出错:<br>type<br> TSetLayeredWindowAttributes = function(Handle: THandle; crey, bAlpha: Byte; dwFlags: Integer): LongInt; stdcall;<br><br> private<br> bTrans, FInterval: Byte;<br> FormClosing: Boolean;<br> LibHandle: THandle;<br> SetLayeredWindowAttributes: TSetLayeredWindowAttributes;<br><br>implementation<br><br>{$R *.DFM}<br>const<br> WS_EX_LAYERED = $80000;<br> LWA_ALPHA = $2;<br><br>procedure TForm1.TimerTimer(Sender: TObject);<br>begin<br> if CanTransparent then<br> begin<br> if FormClosing then<br> Dec(bTrans, FInterval)<br> else<br> Inc(bTrans, FInterval);<br> if @SetLayeredWindowAttributes <> nil then<br> SetLayeredWindowAttributes(Handle, 0, bTrans, LWA_ALPHA);<br> Timer.Enabled := (bTrans <= 255 - FInterval) and (bTrans >= FInterval);<br> if not Timer.Enabled and not FormClosing then<br> if @SetLayeredWindowAttributes <> nil then<br> SetLayeredWindowAttributes(Handle, 0, 255, LWA_ALPHA);<br> end;<br>end;<br><br>procedure TForm1.FormCreate(Sender: TObject);<br>begin<br> LibHandle := LoadLibrary(user32);<br> if LibHandle <> 0 then<br> begin<br> @SetLayeredWindowAttributes := GetProcAddress(LibHandle, 'SetLayeredWindowAttributes');<br> end;<br> FInterval := 8;<br> if CanTransparent then<br> begin<br> SetWindowLong(Handle, GWL_EXSTYLE, GetWindowLong(Handle, GWL_EXSTYLE) or WS_EX_LAYERED);<br> if @SetLayeredWindowAttributes <> nil then<br> SetLayeredWindowAttributes(Handle, 0, 0, LWA_ALPHA);<br> Timer.Enabled := True;<br> end;<br>end;<br><br>procedure TForm1.FormClose(Sender: TObject;<br> var Action: TCloseAction);<br>var<br> C: DWord;<br>begin<br> if CanTransparent then<br> begin<br> FormClosing := True;<br> FInterval := FInterval * 2;<br> Timer.Enabled := True;<br> C := GetTickCount;<br> while Timer.Enabled and ((GetTickCount - C) < 5000) do<br> Application.ProcessMessages;<br> end;<br> if LibHandle <> 0 then<br> FreeLibrary(LibHandle);<br>end;<br><br>function TForm1.CanTransparent: Boolean;<br>begin<br> Result := (LibHandle <> 0) and (@SetLayeredWindowAttributes <> nil);<br>end;<br>