Foros Club Delphi

Foros Club Delphi (https://www.clubdelphi.com/foros/index.php)
-   Trucos (https://www.clubdelphi.com/foros/forumdisplay.php?f=52)
-   -   Semitransparencia sin alphablend (https://www.clubdelphi.com/foros/showthread.php?t=80870)

coso 15-06-2008 13:02:21

Semitransparencia sin alphablend
 
Semitransparencia sin usar la propiedad alphablend (Windows 2000 y mas)

Código Delphi [-]
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs;

type
  TForm1 = class(TForm)
  procedure SetTransparentForm(AHandle : THandle; AValue : byte = 0);
    procedure FormCreate(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;
const
  WS_EX_LAYERED = $80000;
  LWA_COLORKEY = 1;
  LWA_ALPHA    = 2;

type
  TSetLayeredWindowAttributes = function (
      hwnd : HWND;         // handle to the layered window
      crKey : TColor;      // specifies the color key
      bAlpha : byte;       // value for the blend function
      dwFlags : DWORD      // action
      ): BOOL; stdcall;

var


  Form1: TForm1;

implementation

{$R *.DFM}


procedure TForm1.SetTransparentForm(AHandle : THandle; AValue : byte = 0);
var
  Info: TOSVersionInfo;
  SetLayeredWindowAttributes: TSetLayeredWindowAttributes;
begin
  //Check Windows version
  Info.dwOSVersionInfoSize := SizeOf(Info);
  GetVersionEx(Info);
  if (Info.dwPlatformId = VER_PLATFORM_WIN32_NT) and
  (Info.dwMajorVersion >= 5) then
    begin
      SetLayeredWindowAttributes := GetProcAddress(GetModulehandle(user32), 'SetLayeredWindowAttributes');
       if Assigned(SetLayeredWindowAttributes) then
        begin
         SetWindowLong(AHandle, GWL_EXSTYLE, GetWindowLong(AHandle, GWL_EXSTYLE) or WS_EX_LAYERED);
         //Make form transparent
         SetLayeredWindowAttributes(AHandle, 0, AValue, LWA_ALPHA);
       end;
    end;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  SetTransparentForm(Handle, 100);
end;

end.

Khronos 15-06-2008 14:04:02

El truco está mal, el procedimiento SetTransparentForm hay que ponerlo en el evento OnPaint del Form. Consigues el mismo efecto que con la propiedad AlphaBlend, de echo es el mismo código xD.

Para un delphi anterior al 6 esta bien.

Salu2

coso 15-06-2008 14:05:12

bueno si lo pones en OnPaint te estara ejecutando multiples veces algo q solo hace falta ejecutar una vez... a mi me va de perlas en el OnCreate

Khronos 15-06-2008 14:58:29

Yo lo probe en el Delphi 5 y en el evento OnCreate no funcionaba.

coso 15-06-2008 14:59:33

pues es extraño, tengo delphi 5 yo tambien...

coso 15-06-2008 15:00:55

bueno si lo pones en OnPaint te estara ejecutando multiples veces algo q solo hace falta ejecutar una vez... a mi me va de perlas en el OnCreate


La franja horaria es GMT +2. Ahora son las 20:22:17.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Traducción al castellano por el equipo de moderadores del Club Delphi