Delphi-PRAXiS
Seite 1 von 2  1 2   

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Object-Pascal / Delphi-Language (https://www.delphipraxis.net/32-object-pascal-delphi-language/)
-   -   Delphi Set & Windows Konstanten - abfragen & setzen (https://www.delphipraxis.net/201256-set-windows-konstanten-abfragen-setzen.html)

Andreas L. 5. Jul 2019 10:13

Delphi-Version: 2009

Set & Windows Konstanten - abfragen & setzen
 
Hallo,

ich habe folgenden Enumerator & ein Set:

Delphi-Quellcode:
  // https://docs.microsoft.com/de-de/windows/win32/api/winuser/nf-winuser-animatewindow
  TlcfWindowAnimationOption = (
    lwaoActivate,            // AW_ACTIVATE      = 0x00020000 - Nicht mit Hide verwenden!
    lwaoBlend,               // AW_BLEND         = 0x00080000
    lwaoCenter,              // AW_CENTER        = 0x00000010 -
    lwaoHide,                // AW_HIDE          = 0x00010000 -
    lwaoHorizontalPositive,  // AW_HOR_POSITIVE  = 0x00000001 - Wird ignoriert bei AW_CENTER oder AW_BLEND
    lwaoHorizontalNegative,  // AW_HOR_NEGATIVE  = 0x00000002 - Wird ignoriert bei AW_CENTER oder AW_BLEND
    lwaoSlide,               // AW_SLIDE         = 0x00040000 - Wird ignoriert bei AW_CENTER
    lwaoVerticalPositive,    // AW_VER_POSITIVE  = 0x00000004 - Wird ignoriert bei AW_CENTER oder AW_BLEND
    lwaoVerticalNegative     // AW_VER_NEGATIVE  = 0x00000008 - Wird ignoriert bei AW_CENTER oder AW_BLEND
  );

  TlcfWindowAnimationOptions = set of TlcfWindowAnimationOption;
Wie kann ich alle in einer DWORD-Variable gesetzten Werte ermitteln um das Set (TlcfWindowAnimationOptions) zu füllen?

Ich habe folgendes versucht:

Delphi-Quellcode:
class function TlcfWindowHelper.GetWindowAnimations(
  AWindowAnimation: DWORD): TlcfWindowAnimationOptions;
begin
  Result := [];

  if AW_ACTIVATE in AWindowAnimation then
    Result := Result + [lwaoActivate];

  //...
end;
Ist das so richtig?

Wenn ich außerdem das selbe nur andersrum machen will, muss ich die Werte mit "and" oder "or" verknüpfen?

Delphi-Quellcode:
class function TlcfWindowHelper.GetWindowAnimations(
  AWindowAnimation: TlcfWindowAnimationOptions): DWORD;
begin
  Result := 0;

  if lwaoActivate in AWindowAnimation then
    Result := Result or AW_ACTIVATE; // oder mit and???
end;
Ist es außerdem richtig das Result mit 0 zu initialisieren?

Schöne Grüße,
Andreas Lauß

Luckie 5. Jul 2019 10:23

AW: Set & Windows Konstanten - abfragen & setzen
 
Setzen bzw. hinzufügen mit or, nicht mit +! Abfragen mit and.
http://michael-puff.de/Programmierun...itMasken.shtml

Andreas L. 5. Jul 2019 10:31

AW: Set & Windows Konstanten - abfragen & setzen
 
Zitat:

Zitat von Luckie (Beitrag 1436053)
Setzen bzw. hinzufügen mit or, nicht mit +! Abfragen mit and.
http://michael-puff.de/Programmierun...itMasken.shtml

Bei folgende Code erhalte ich die Meldung "Ausdruckstyp muss BOOLEAN sein" vom Compiler. Wie muss ich die Abfrage formulieren?

Delphi-Quellcode:
  if AWindowAnimations and AW_ACTIVATE then
    Result := Result + [lwaoActivate];
EDIT: Hab deinen Link eben erst gesehen. So müsste es stimmen, oder?

Delphi-Quellcode:
  if AWindowAnimations and AW_ACTIVATE = AW_ACTIVATE then
    Result := Result + [lwaoActivate];

Neutral General 5. Jul 2019 10:32

AW: Set & Windows Konstanten - abfragen & setzen
 
Delphi-Quellcode:
if (AWindowAnimations and AW_ACTIVATE) <> 0 then

EWeiss 5. Jul 2019 10:36

AW: Set & Windows Konstanten - abfragen & setzen
 
Zitat:

Zitat von Andreas L. (Beitrag 1436055)
Zitat:

Zitat von Luckie (Beitrag 1436053)
Setzen bzw. hinzufügen mit or, nicht mit +! Abfragen mit and.
http://michael-puff.de/Programmierun...itMasken.shtml

Bei folgende Code erhalte ich die Meldung "Ausdruckstyp muss BOOLEAN sein" vom Compiler. Wie muss ich die Abfrage formulieren?

Delphi-Quellcode:
  if AWindowAnimations and AW_ACTIVATE then
    Result := Result + [lwaoActivate];
EDIT: Hab deinen Link eben erst gesehen. So müsste es stimmen, oder?

Delphi-Quellcode:
  if AWindowAnimations and AW_ACTIVATE = AW_ACTIVATE then
    Result := Result + [lwaoActivate];

Ja wenn du auf Gleichheit prüfen willst ansonsten gilt das von @Neutral General <> also ungleich.

gruss

Luckie 5. Jul 2019 10:37

AW: Set & Windows Konstanten - abfragen & setzen
 
Der Code ist noch vom vorm Kriech. Eventuell sogar mit Delphi 7 erstellt. Eventuell hat sich da was geändert in den neueren Delphis. Das kann ich jetzt aber nicht überprüfen. Jedenfalls hat der Code compiliert, sonst hätte ich ihn so nicht veröffentlicht.

Schokohase 5. Jul 2019 10:38

AW: Set & Windows Konstanten - abfragen & setzen
 
Du könntest das als Vorlage verwenden
Delphi-Quellcode:
uses
  Winapi.Windows;

type
  // https://docs.microsoft.com/de-de/windows/win32/api/winuser/nf-winuser-animatewindow
  TlcfWindowAnimationOption = ( //
    lwaoActivate, // AW_ACTIVATE = 0x00020000 - Nicht mit Hide verwenden!
    lwaoBlend, // AW_BLEND = 0x00080000
    lwaoCenter, // AW_CENTER = 0x00000010 -
    lwaoHide, // AW_HIDE = 0x00010000 -
    lwaoHorizontalPositive, // AW_HOR_POSITIVE = 0x00000001 - Wird ignoriert bei AW_CENTER oder AW_BLEND
    lwaoHorizontalNegative, // AW_HOR_NEGATIVE = 0x00000002 - Wird ignoriert bei AW_CENTER oder AW_BLEND
    lwaoSlide, // AW_SLIDE = 0x00040000 - Wird ignoriert bei AW_CENTER
    lwaoVerticalPositive, // AW_VER_POSITIVE = 0x00000004 - Wird ignoriert bei AW_CENTER oder AW_BLEND
    lwaoVerticalNegative // AW_VER_NEGATIVE = 0x00000008 - Wird ignoriert bei AW_CENTER oder AW_BLEND
    );

  TlcfWindowAnimationOptions = set of TlcfWindowAnimationOption;

  THelperForTlcfWindowAnimationOptions = record helper for TlcfWindowAnimationOptions
  private const
    Values: array [TlcfWindowAnimationOption] of DWORD = (AW_ACTIVATE, AW_BLEND, AW_CENTER, AW_HIDE, AW_HOR_POSITIVE, AW_HOR_NEGATIVE, AW_SLIDE,
      AW_VER_POSITIVE, AW_VER_NEGATIVE);
  public
    function ToDword(): DWORD;
    class function FromDword(Value: DWORD): TlcfWindowAnimationOptions; static;
  end;

implementation

{ THelperForTlcfWindowAnimationOptions }

class function THelperForTlcfWindowAnimationOptions.FromDword(Value: DWORD): TlcfWindowAnimationOptions;
var
  enum: TlcfWindowAnimationOption;
begin
  Result := [];
  for enum := Low(TlcfWindowAnimationOption) to High(TlcfWindowAnimationOption) do
  begin
    if Values[enum] and Value = Values[enum] then
      Result := Result + [enum];
  end;
end;

function THelperForTlcfWindowAnimationOptions.ToDword: DWORD;
var
  enum: TlcfWindowAnimationOption;
begin
  Result := 0;
  for enum := Low(TlcfWindowAnimationOption) to High(TlcfWindowAnimationOption) do
    if enum in Self then
      Result := Result or Values[enum];
end;

Andreas L. 5. Jul 2019 10:40

AW: Set & Windows Konstanten - abfragen & setzen
 
Zitat:

Zitat von Neutral General (Beitrag 1436057)
Delphi-Quellcode:
if (AWindowAnimations and AW_ACTIVATE) <> 0 then

Also muss es so lauten:

Delphi-Quellcode:
  if AWindowAnimations and AW_ACTIVATE <> 0 then
    Result := Result + [lwaoActivate];
Der Compiler akzeptiert es jedenfalls...

Danke für euer Hilfe :)

EWeiss 5. Jul 2019 10:41

AW: Set & Windows Konstanten - abfragen & setzen
 
Zitat:

Zitat von Andreas L. (Beitrag 1436064)
Zitat:

Zitat von Neutral General (Beitrag 1436057)
Delphi-Quellcode:
if (AWindowAnimations and AW_ACTIVATE) <> 0 then

Also muss es so lauten:

Delphi-Quellcode:
  if AWindowAnimations and AW_ACTIVATE <> 0 then
    Result := Result + [lwaoActivate];
Der Compiler akzeptiert es jedenfalls...

Danke für euer Hilfe :)

Das ist die frage wir wissen ja nicht was du willst.
Auf Gleichheit abfragen oder ungleich..

PS:
Ja ich weis was er abfragen und welches Ergebnis er erwartet aber hat er verstanden um was es geht?

gruss

Andreas L. 5. Jul 2019 10:44

AW: Set & Windows Konstanten - abfragen & setzen
 
Ein record helper kann mit einem Enumerator bzw. Set verwendet werden? Wow... Gibt es den record helper schon in Delphi 2009 Pro?


Alle Zeitangaben in WEZ +1. Es ist jetzt 08:40 Uhr.
Seite 1 von 2  1 2   

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