views:

131

answers:

2

Hi,

I try to use the following technique in order to enable/disable the shadow effect for a window: (The CreateParams is of course overriden. The TToolWindow descends from TForm).

procedure TToolWindow.CreateParams(var Params: TCreateParams); 
var
  LShadow: boolean;

begin
  inherited;

  if (Win32Platform = VER_PLATFORM_WIN32_NT)
    and ((Win32MajorVersion > 5)
    or ((Win32MajorVersion = 5) and (Win32MinorVersion >= 1))) then //Win XP or higher
      if SystemParametersInfo(SPI_GETDROPSHADOW, 0, @LShadow, 0) then
      begin
        if LShadow and HasShadow then
          Params.WindowClass.Style := Params.WindowClass.Style or CS_DROPSHADOW;
      end;
end;

While this works ok for the first instance of the TToolWindow class, the following instances keep the setting from the first instance, regardless of the value of HasShadow (which is a published property of the TToolWindow class).

How can I have different shadow settings on different instances of TToolWindow?

TIA

A: 

Just a guess... are the subsequent instances children of your TToolWindow? Perhaps they are inheriting the style from the parent.

Edit: Actually, I read online that if you give items a WS_CHILD style, it will ignore CS_DROPSHADOW. So that might be one way to hack around your issue if all else fails.

Drew Hoskins
+2  A: 

The VCL registers the necessary window classes for form classes on the fly, once each time the first instance of a given class is created. That explains why all secondary instances of your TToolWindow have the same shadow as the first instance, regardless of the HasShadow value. You are creating windows of the same window class, so they all have the same class style.

What you could do is registering two classes, one with the drop shadow, the other without it. The VCL will register a new window class if the class name is different from the previously registered class.

Something like this:

procedure TToolWindow.CreateParams(var Params: TCreateParams); 
var
  LShadow: boolean;
begin
  inherited;

  if (Win32Platform = VER_PLATFORM_WIN32_NT)
    and ((Win32MajorVersion > 5)
    or ((Win32MajorVersion = 5) and (Win32MinorVersion >= 1))) 
  then begin
    //Win XP or higher
    if SystemParametersInfo(SPI_GETDROPSHADOW, 0, @LShadow, 0)
      and LShadow and HasShadow
    then begin
      Params.WindowClass.Style := Params.WindowClass.Style or CS_DROPSHADOW;
      StrLCopy(Params.WinClassName, 'TDelphiToolWindowWithShadow', 63);
    end else begin
      Params.WindowClass.Style := Params.WindowClass.Style and not CS_DROPSHADOW;
      StrLCopy(Params.WinClassName, 'TDelphiToolWindowNoShadow', 63);
    end;
  end;
end;
mghie