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 [Schattiere Fenster] - Schattierung ein/aus schalten (https://www.delphipraxis.net/89949-%5Bschattiere-fenster%5D-schattierung-ein-aus-schalten.html)

xZise 9. Apr 2007 08:51


[Schattiere Fenster] - Schattierung ein/aus schalten
 
Ich habe folgenden Code aus dem SwissDelphicenter benutzt um ein Fenster ein Schatten zu versehen:
Delphi-Quellcode:
procedure TInfoBox.CreateParams(var Params: TCreateParams);
begin
  inherited CreateParams(Params);
  if not (csDesigning in ComponentState) then
  begin
    Params.WindowClass.style := Params.WindowClass.style or CS_DROPSHADOW;
  end;
end;
(siehe SwissDelphiCenter)

Nun funktioniert das wunderbar, aber ich würde gerne den Schatten ein/ausschalten lassen wollen ... Wie bekommt man dass hin?

Flocke 9. Apr 2007 09:28

Re: [Schattiere Fenster] - Schattierung ein/aus schalten
 
Es könnte mit MSDN-Library durchsuchenSetClassLong/GCL_STYLE funktionieren, allerdings habe ich es nicht getestet:
Delphi-Quellcode:
if FDropShadow then
  SetClassLong(Handle, GCL_STYLE, GetClassLong(hWnd, GCL_STYLE) or CS_DROPSHADOW)
else
  SetClassLong(Handle, GCL_STYLE, GetClassLong(hWnd, GCL_STYLE) and not CS_DROPSHADOW);
Ggf. musst du dann selbst darum kümmern, den vom Schatten überdeckten Hintergrund neu zeichnen zu lassen (Parent.Invalidate?).

xaromz 9. Apr 2007 09:34

Re: [Schattiere Fenster] - Schattierung ein/aus schalten
 
Hallo,

einschalten kannst Du das so:
Delphi-Quellcode:
function ActivateDropShadow(const Handle: THandle): Boolean;

  function IsXP: Boolean;
  begin
    Result := (Win32Platform = VER_PLATFORM_WIN32_NT) and
      CheckWin32Version(5, 1);
  end;

const
  SPI_SETDROPSHADOW = $1025;
  CS_DROPSHADOW = $00020000;

var
  NewLong: Cardinal;
  B: Boolean;
begin
  B := True;
  if IsXP and SystemParametersInfo(SPI_SETDROPSHADOW, 0, @B, 0) then
  begin
    NewLong := GetClassLong(Handle, GCL_STYLE);
    NewLong := NewLong or CS_DROPSHADOW

    Result := SetClassLong(Handle, GCL_STYLE, NewLong) <> 0;
    if Result then
      SendMessage(Handle, CM_RECREATEWND, 0, 0);
  end else
    Result := False;
end;
Ausschalten hab ich leider noch nicht geschafft. Wenn das jemand weiß, ich bin sehr interessiert.

Gruß
xaromz

turboPASCAL 9. Apr 2007 10:22

Re: [Schattiere Fenster] - Schattierung ein/aus schalten
 
Zitat:

Zitat von xaromz
Ausschalten hab ich leider noch nicht geschafft.

Wieso ?

Delphi-Quellcode:
// ...
begin
  NewLong := GetClassLong(Handle, GCL_STYLE);
  NewLong := NewLong and not CS_DROPSHADOW;
  // ...

LizardKaiser 9. Apr 2007 10:44

Re: [Schattiere Fenster] - Schattierung ein/aus schalten
 
Hey,

ein kleiner Tip: xor-Operator :wink:

also:
Delphi-Quellcode:
// ersetze OR durch XOR um zu "togglen"
NewLong := NewLong xor CS_DROPSHADOW;

...
// am ende der funktion ist natürlich ein redraw nötig:
SetWindowPos(Handle, 0, 0, 0, 0, 0, SWP_NOSIZE or SWP_NOMOVE or SWP_DRAWFRAME);
müsste so funktionieren :gruebel:

turboPASCAL 9. Apr 2007 11:03

Re: [Schattiere Fenster] - Schattierung ein/aus schalten
 
:gruebel: xor hm, dann müsste man noch auf den Style prüfen ob er enthalten ist etc.


@xaromz, ich würde deine Funktion anders benennen:

Delphi-Quellcode:
function WindowShadow(const Handle: THandle; Mode: Boolean): Boolean;

  function IsXP: Boolean;
  begin
    Result := (Win32Platform = VER_PLATFORM_WIN32_NT) and
      CheckWin32Version(5, 1);
  end;

const
  SPI_SETDROPSHADOW = $1025;
  CS_DROPSHADOW = $00020000;

var
  ClassLong: Cardinal;
begin
  if IsXP and SystemParametersInfo(SPI_SETDROPSHADOW, 0, Pointer(TRUE), 0) then
  begin
    ClassLong := GetClassLong(Handle, GCL_STYLE);

    if Mode
      then ClassLong := ClassLong or CS_DROPSHADOW
      else ClassLong := ClassLong and not CS_DROPSHADOW;

    Result := SetClassLong(Handle, GCL_STYLE, ClassLong) <> 0;
    if Result then
      SendMessage(Handle, CM_RECREATEWND, 0, 0);

  end else
    Result := False;
end;

... mal sehen wie es mit dem XOR-Dinges ;) werden könnte...

xZise 9. Apr 2007 11:10

Re: [Schattiere Fenster] - Schattierung ein/aus schalten
 
Zitat:

Zitat von xaromz
Hallo,

einschalten kannst Du das so:
Delphi-Quellcode:
function ActivateDropShadow(const Handle: THandle): Boolean;

  function IsXP: Boolean;
  begin
    Result := (Win32Platform = VER_PLATFORM_WIN32_NT) and
      CheckWin32Version(5, 1);
  end;

const
  SPI_SETDROPSHADOW = $1025;
  CS_DROPSHADOW = $00020000;

var
  NewLong: Cardinal;
  B: Boolean;
begin
  B := True;
  if IsXP and SystemParametersInfo(SPI_SETDROPSHADOW, 0, @B, 0) then
  begin
    NewLong := GetClassLong(Handle, GCL_STYLE);
    NewLong := NewLong or CS_DROPSHADOW

    Result := SetClassLong(Handle, GCL_STYLE, NewLong) <> 0;
    if Result then
      SendMessage(Handle, CM_RECREATEWND, 0, 0);
  end else
    Result := False;
end;
Ausschalten hab ich leider noch nicht geschafft. Wenn das jemand weiß, ich bin sehr interessiert.

Gruß
xaromz

Danke... Aber:
Zitat:

[Pascal Fehler] infobox.pas(59): E2003 Undefinierter Bezeichner: 'Win32Platform'
PS: Ich habe es mal mit xor probiert ;) Aber mit dem komplieren ^^

xaromz 9. Apr 2007 11:13

Re: [Schattiere Fenster] - Schattierung ein/aus schalten
 
Hallo,

Zitat:

Zitat von turboPASCAL
Zitat:

Zitat von xaromz
Ausschalten hab ich leider noch nicht geschafft.

Wieso ?

Delphi-Quellcode:
// ...
begin
  NewLong := GetClassLong(Handle, GCL_STYLE);
  NewLong := NewLong and not CS_DROPSHADOW;
  // ...

Hast Du das auch ausprobiert? Sieht lustig aus. Das Form hat keinen Schatten mehr, aber der alte Schatten ist auf dem Screen "festgenagelt" :wink: .

@xZise: SysUtils einbinden.

Gruß
xaromz

xZise 9. Apr 2007 11:20

Re: [Schattiere Fenster] - Schattierung ein/aus schalten
 
Hi xaromx!
Danke ;) Die Hilfe meinte irgendwas mit Indy :mrgreen:

Also mit xor funzt es wunderbar :D Nur isses leider eben mit dem festgenagelten Schatten etwas unschön xD

turboPASCAL 9. Apr 2007 13:36

Re: [Schattiere Fenster] - Schattierung ein/aus schalten
 
Zitat:

Zitat von xaromz
Hast Du das auch ausprobiert?

Japp. ;)

Zitat:

Zitat von xaromz
Sieht lustig aus. Das Form hat keinen Schatten mehr, aber der alte Schatten ist auf dem Screen "festgenagelt" :wink:

Japp. :mrgreen:

Äh, wenn man das Fenster Minimiert und dann wieder herstellt ist das Schattenartefact wech.
So richtig Versteh ich den Mechhanismus noch nicht. Die Funktion macht das was sie machen soll
nicht immer 100%. :gruebel:


Alle Zeitangaben in WEZ +1. Es ist jetzt 23:39 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