Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   GUI-Design mit VCL / FireMonkey / Common Controls (https://www.delphipraxis.net/18-gui-design-mit-vcl-firemonkey-common-controls/)
-   -   Delphi Alphablend? (https://www.delphipraxis.net/17430-alphablend.html)

mgubler 5. Mär 2004 13:52


Alphablend?
 
Hi!

Diejenigen von euch, die D6+ verwenden kennen diese Funktion!
Aber wie erzeuge ich diese Funktion mit D5?
Kann mit jemand helfen?

Danke im voraus!
mgubler

DelphiDeveloper 5. Mär 2004 14:03

Re: Alphablend?
 
hatte ich auch mal zu D5 zeiten gebraucht hatte aber damals schwierigkeiten
mit win98

versuchs mal mit folgendem code und D5

Delphi-Quellcode:
unit Unit1;

interface

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

const
  WS_EX_LAYERED = $80000;
  LWA_COLORKEY = 1;
  LWA_ALPHA = 2;

type
  TSetLayeredWindowAttributes = function(
    hwnd: HWND; // handle fuers fenster
    crKey: TColor; // die farbe
    bAlpha: byte; // wert fuer die blend funktion
    dwFlags: DWORD //
    ): BOOL; stdcall;

  TForm1 = class(TForm)
    procedure FormCreate(Sender: TObject);
  private
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

procedure SetTransparentForm(AHandle: THandle; AValue: byte = 0);
var
  Info: TOSVersionInfo;
  SetLayeredWindowAttributes: TSetLayeredWindowAttributes;
begin
 // geht meines wissen ab win2000
  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);
        //und jetzt transparent zeichnen
      SetLayeredWindowAttributes(AHandle, 0, AValue, LWA_ALPHA);
    end;
  end;
end;




procedure TForm1.FormCreate(Sender: TObject);
begin
    // 0 --> voll transparent
    // 255 --> nicht trabsparent
  SetTransparentForm(Handle, 240);

end;

end.
[edit=Admin]CODE-Tags in DELPHI-Tags gewandelt. ;-) Mfg, Daniel[/edit]

MathiasSimmack 5. Mär 2004 14:37

Re: Alphablend?
 
Gibt´s eigentlich einen Grund, das ins "interface" zu schreiben?`
Zitat:

Zitat von DelphiDeveloper
Code:
unit Unit1;

interface

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

const
  WS_EX_LAYERED = $80000;
  LWA_COLORKEY = 1;
  LWA_ALPHA = 2;

type
  TSetLayeredWindowAttributes = function(
    hwnd: HWND; // handle fuers fenster
    crKey: TColor; // die farbe
    bAlpha: byte; // wert fuer die blend funktion
    dwFlags: DWORD //
    ): BOOL; stdcall;


{ ... }

implementation


{ ... }

end.

Wenn du´s nicht außerhalb der Form noch mal brauchst, dann passt es sehr schön in den "implementation"-Teil der Unit.

Als Alternative noch eine extra Unit zum einfacheren Wiederkäu... äh -verwenden des Codes.


Alle Zeitangaben in WEZ +1. Es ist jetzt 01:51 Uhr.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz