Rectangle 27 0

Okay... I've finally figured this out, and it is the most absurd thing I've ever come across.

I'm posting my findings here for the benefit of others (to save you going through the nuisance I've just been through).

To get all of the controls on your Deskband Form to display and function properly, simply set the Visible property of your Form (in the IDE designer) to True.

Ridiculous, I know, but it works and is easily repeatable.

Visible
False

LOOOL!! this is really something for the wall of "WTF" good finding!

TForm.Visible defaulting to False has been true since Delphi 1, and makes sense most of the time - you don't want the form visible until you're ready to Show or ShowModal. It apparently didn't work right in this case, though. Are you using Application.CreateForm as usual in the DFM to set up your main form?.

delphi - How to make my Deskband's (Taskbar Toolbar) Form transparent ...

delphi taskbar delphi-xe2 deskband
Rectangle 27 0

Seems that Andreas Hausladen stumbled upon a similar problem and has already implemented a solution: he rewrote TJvTransparentForm in the JVCL library.

Even if you are not going to use that component directly you may gain some insight by studying the source.

Here is the link to Andreas' article.

-1 for a link with no explanation.

Please honor the license of JVCL. Even when copying source from it the license will stay intact.

Sign up for our newsletter and get our top new questions delivered to your inbox (see an example).

delphi - How to make the form into fully transparent 32bit alpha? - St...

delphi forms alphablending
Rectangle 27 0

If you need partial transparency, then TransparentColor/TransparentColorValue won't help.

When Aero is disabled or not present, then you will have to use some sort of hack:

  • Make screenshot of the desktop wia BitBlt+GetDC+GetDesktopWindow. Your window won't be on that screenshot.
  • Draw on your form part of screenshot that has same position and size as your form. In fact you will be drawing whatever is behind your form, that is why it will look like transparent.

delphi - How to make form transparent while keeping the component visi...

delphi transparency transparent-control
Rectangle 27 0

The usual way would be drawing all graphics to one destination canvas (which could be the bitmap of an TImage), but even with many overlapping TImages this can be done. Be aware that you can't overlap TWinControls. Since a 32 bit Bitmap support transparency this can be reached by converting the contained graphic to an bitmap (if needed). By setting Alphaformat := afDefined the bitmap will be drawn with the transparency informations from the alphachannel. We need a copy of the bitmap since setting the AlphaFormat will let us loose the pixelinformations. Using scanlines the pixelinformation from the copy can be transferred to the destination, the alpha channel is set to the desired value.

type
  pRGBQuadArray = ^TRGBQuadArray;
  TRGBQuadArray = ARRAY [0 .. 0] OF TRGBQuad;

procedure SetImageAlpha(Image:TImage; Alpha: Byte);
var
  pscanLine32,pscanLine32_src: pRGBQuadArray;
  nScanLineCount, nPixelCount : Integer;
  BMP1,BMP2:TBitMap;
  WasBitMap:Boolean;
begin
  if assigned(Image.Picture) then
    begin
       // check if another graphictype than an bitmap is assigned
       // don't check Assigned(Image.Picture.Bitmap) which will return always true
       // since a bitmap is created if needed and the graphic will be discared   
       WasBitMap := Not Assigned(Image.Picture.Graphic);
       if not WasBitMap then
          begin   // let's create a new bitmap from the graphic
            BMP1 := TBitMap.Create;
            BMP1.Assign(Image.Picture.Graphic);
          end
       else BMP1 := Image.Picture.Bitmap;  // take the bitmap

       BMP1.PixelFormat := pf32Bit;

       // we need a copy since setting Alphaformat:= afDefined will clear the Bitmap
       BMP2 := TBitMap.Create;
       BMP2.Assign(BMP1);

       BMP1.Alphaformat := afDefined;

    end;
    for nScanLineCount := 0 to BMP1.Height - 1 do
    begin
      pscanLine32 := BMP1.Scanline[nScanLineCount];
      pscanLine32_src := BMP2.ScanLine[nScanLineCount];
      for nPixelCount := 0 to BMP1.Width - 1 do
        begin
          pscanLine32[nPixelCount].rgbReserved := Alpha;
          pscanLine32[nPixelCount].rgbBlue := pscanLine32_src[nPixelCount].rgbBlue;
          pscanLine32[nPixelCount].rgbRed  := pscanLine32_src[nPixelCount].rgbRed;
          pscanLine32[nPixelCount].rgbGreen:= pscanLine32_src[nPixelCount].rgbGreen;
        end;
    end;
    If not WasBitMap then
      begin  // assign and free Bitmap if we had to create it
      Image.Picture.Assign(BMP1);
      BMP1.Free;
      end;
    BMP2.Free; // free the copy
end;



procedure TForm3.Button1Click(Sender: TObject);
begin  // call for the example image
  SetImageAlpha(Image1,200);
  SetImageAlpha(Image2,128);
  SetImageAlpha(Image3,80);

end;

image - How to make alpha transparent TImage in Delphi? - Stack Overfl...

image delphi transparency alpha-transparency
Rectangle 27 0

It seems like a bug to me. The VCL Styles use Style hooks to intercept the paint methods and the Windows messages related to these operations, So in this case you must focus your atention in the PaintBackground method of the TFormStyleHook class located in the Vcl.Forms, from here you create a new style hook class (which descends from TFormStyleHook), override the PaintBackground method, fix the code and finally before to use it call the RegisterStyleHook method to register the New style hook. check this article Fixing a VCL Style bug in the TPageControl and TTabControl components to see an example.

unit Unit138;

interface

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
  Vcl.Controls, Vcl.Forms, Vcl.Dialogs;

type
  TForm138 = class(TForm)
    procedure FormCreate(Sender: TObject);
  private
    procedure CreateParams(var Params:TCreateParams); override;
  public
  end;


var
  Form138: TForm138;

implementation

 Uses
   Vcl.Themes,
   Vcl.Styles,
   uPatch;

{$R *.dfm}

procedure TForm138.CreateParams(var Params: TCreateParams);
begin
 inherited CreateParams(Params);
 Params.ExStyle := WS_EX_TRANSPARENT or WS_EX_TOPMOST;
end;

procedure TForm138.FormCreate(Sender: TObject);
begin
 Brush.Style:=bsClear;
 BorderStyle:=bsNone;
end;

initialization
 TStyleManager.Engine.UnRegisterStyleHook(TForm, TFormStyleHook);//unregister the original style hook
 TStyleManager.Engine.RegisterStyleHook(TForm, TMyStyleHookClass); //register the new style hook

end.
unit uPatch;

interface

uses
  Vcl.Graphics,
  Vcl.Forms;

type
  TMyStyleHookClass= class(TFormStyleHook)
  protected
   procedure PaintBackground(Canvas: TCanvas); override;
  end;

implementation

uses
  Winapi.Windows,
  System.Types,
  Vcl.Themes;


procedure TMyStyleHookClass.PaintBackground(Canvas: TCanvas);
{This is only a basic sample for fix a specific scenario}
var
  Details: TThemedElementDetails;
  R: TRect;
begin
  if StyleServices.Available then
  begin
    if (GetWindowLong(Form.Handle,GWL_EXSTYLE) AND WS_EX_TRANSPARENT) = WS_EX_TRANSPARENT  then
    if Form.Brush.Style = bsClear then Exit;

    Details.Element := teWindow;
    Details.Part := 0;
    R := Rect(0, 0, Control.ClientWidth, Control.ClientHeight);
    StyleServices.DrawElement(Canvas.Handle, Details, R);
  end;
end;

end.

delphi - how to make a transparent form when a VCL Style is enabled? -...

delphi delphi-xe2 vcl-styles
Rectangle 27 0

FireMonkey images use a 32-bit per pixel schema with 8 bits each for red, green and blue plus an extra 8 bits for transparency, also called an alpha channel. If the value of the alpha channel is #FF the pixel will be opaque, #00 will be completely transparent and values in between will vary the transparency accordingly.

Therefore a colour in FireMonkey (actually a TAlphaColor) can be set with an 8 digit hex number where the bits map to #AARRGGBB where AA is the transparency/alpha channel.

Thus, #FF00FF00 is opaque green and #88FF0000 is semi-transparent red. Any color value in which the first two digits are #00 with be completely transparent.

FireMonkey includes are pre-defined constant claNull for a completely transparent colour.

You can also use the TAlphaColorRec record to access individual colours of a TAlphaColor variable using it's fields, A, R, G and B. E.g.

Delphi XE5 Firemonkey - How to make image background transparent runti...

image delphi runtime transparent firemonkey
Rectangle 27 0

TImage itself (and any other UI control, for that matter) cannot be alpha blended on top of other controls. However, you can display an alpha blended GIF image inside of a TImage using the TGIFImage class.

A GIF image block is limited to 256 colors because it uses a palette, but a GIF can have multiple image blocks, each with its own palette. Multiple image blocks can then be tiled/overlayed to produce an overall display that has more than 256 colors total. If you look at the example GIF displayed on Wikipedia, it uses 1859 colors total.

image - How to make alpha transparent TImage in Delphi? - Stack Overfl...

image delphi transparency alpha-transparency
Rectangle 27 0

On a separate note, have you tried using the TransparentColor and TranparentColorValue properties instead of manipulating the window styles in CreateParams()?

TransparentColor:=True; TransparentColorValue:=TStyleManager.ActiveStyle.GetStyleColor(scGenericBackground);

Are you sure scGenericBackground is the right color actually being used during painting, and that GetStyleColor() is returning the correct TColor value? Have you tried hard-coding the TransparentColorValue property to a specific TColor value that you know is being shown onscreen?

I'm pretty sure, maybe can you edit your question adding the code which you suggest?.

delphi - how to make a transparent form when a VCL Style is enabled? -...

delphi delphi-xe2 vcl-styles
Rectangle 27 0

Just drop this code with a button in your Form and you'll see your Form with your PNG becoming transparent:

procedure SetTransparent(Aform: TForm; AValue: Boolean);
begin
  Aform.TransparentColor := AValue;
  Aform.TransparentColorValue := Aform.Color;
end;

procedure TForm2.Button1Click(Sender: TObject);
begin
  SetTransparent(Self, True);
end;

delphi - How to make form transparent while keeping the component visi...

delphi transparency transparent-control
Rectangle 27 0

I suspect you're trying to create something like a transparent splashscreen, if that's the case, you can read these great articles, they describes a nice way to use a transparent png in a delphi form.

delphi - How can I make a form transparent according to a PNG image? -...

delphi forms png transparency delphi-2010
Rectangle 27 0

It is possible, but any controls you put on such form will not be visible.

Here is some base code to get you started, but I have never used it on forms with border, so there might be possible issues with border functionality. Most likely, you will have to create bitmap that will include window border and set alpha for that part to 255;

Bitmaps you use have to be 32-bit bitmaps. If you want to blend whole bitmap with some alpha value, you can use PremultiplyBitmapAlpha procedure, and if your bitmap has alpha channel you can then use PremultiplyBitmap procedure.

For speed improvements you can use premultiplied byte table like this:

var
  PreMult: array[byte, byte] of byte;

procedure InitializePreMult;
var
  Row, Col: Integer;
begin
  // precalculate all possible values of a*b
  for Row := 0 to 255 do
    for Col := Row to 255 do
      PreMult[Row, Col] := Row*Col div 255;
end;

and then PremultiplyBitmap procedure would use that lookup table:

procedure PremultiplyBitmap(Bitmap: TBitmap);
var
  Row, Col: integer;
  p: PRGBQuad;
begin
  for Row := 0 to Bitmap.Height-1 do
  begin
    Col := Bitmap.Width;
    p := Bitmap.ScanLine[Row];
    while (Col > 0) do
    begin
      p.rgbBlue := PreMult[p.rgbReserved, p.rgbBlue];
      p.rgbGreen := PreMult[p.rgbReserved, p.rgbGreen];
      p.rgbRed := PreMult[p.rgbReserved, p.rgbRed];
      inc(p);
      dec(Col);
    end;
  end;
end;

delphi - How to make the form transparent without the border? - Stack ...

delphi delphi-xe2
Rectangle 27 0

I presume what you're trying to accomplish is a little more complicated than simply writing text with a transparent background; i.e. you are trying to get some form of alpha-blended text written on the image. The simplest method would be to make use of the GDI+ routines. They are encapsulated for delphi and available for download from http://www.progdigy.com/. There are many examples there which should be usable as an example.

It appears as though there was some disagreement between the developer of GDI plus for Delphi and Embarcadero, I don't know if it's been pulled in response to this. You could try searching for some alternatives such as Erik Van Bilsen's GDI plus.

delphi - Writing Transparent Text on Image - Stack Overflow

delphi image-processing
Rectangle 27 0

If you want to use a PNG to control transparency you might want to look into "layered windows":

  • SetWindowLong(Handle, GWL_EXSTYLE, GetWindowLong(Handle, GWL_EXSTYLE) or WS_EX_LAYERED);

This allows you to have variable transparency accross the window, just as PNG allows! The problem is, controls on layered windows don't really work, I guess it's a Windows issue. My solution was to actually brake up the big window into multiple smaller windows, with all the controls on non-layered windows. This creates yet an other problem, because you now have multiple windows and you want them to move like a single window. The solution: implement your own algorithm for moving the window accross the screen and use:

... to move all windows at once, so the user has no idea she's looking at multiple windows! Finally, if you want to get fancy, you might want to look into SetWindowRgn: this allows you to create a window with a non-rectangular shape.

P.S: Reading Andrea's link from Uwe Raabe, he's using the same technique, only he packaged it ready for action!

delphi - How to make the form into fully transparent 32bit alpha? - St...

delphi forms alphablending
Rectangle 27 0

I use OverridePaintNC := False to prevent draw Styles on NC area. And there is OverrideEraseBkgnd too. Maybe this help.

delphi - how to make a transparent form when a VCL Style is enabled? -...

delphi delphi-xe2 vcl-styles
Rectangle 27 0

Your settings are wrong. I am doing this (With a bitmap).

The Form.TransparentColourValue should be the colour of the part of The TImage that you want to be transparent.

[Edit] It does not matter what colour the form is if the Image covers it completely

delphi - How can I make a form transparent according to a PNG image? -...

delphi forms png transparency delphi-2010