2

Can you give me the names of the functions needed for this purpose? I'm using Delphi XE 5. I want to get this effect:

https://i.stack.imgur.com/OXjoc.jpg

Window: half transparent

Font: fully visible.

I will use "System" font (zero problems with AA)

What do I look on MSDN? What functions (name) do I need to use?

Rob Kennedy
  • 161,384
  • 21
  • 275
  • 467
  • Check for AlphaBlend property of TForm – MBo Dec 03 '13 at 15:36
  • 2
    but AlphaBlend do all window, all components, all fotns transparent but i dont want font transparency – user3062006 Dec 03 '13 at 15:48
  • You might find [`TTransparentCanvas`](http://itinerantdeveloper.blogspot.com/p/open-source.html) useful code. It lets you draw to a 32-bit transparent canvas, including drawing text and using the Vista glowing text background effect. You can then use that 32-bit bitmap as Remy advises below. – David Dec 04 '13 at 12:21

3 Answers3

4

This is basically the same idea as in Marcus' answer, but with some enhancements. You might have to adjust this to your needs, but the principle is the following:

Create form1 with the following properties:

AlphaBlend := True;
AlphaBlendValue := 128;
BorderStyle := bsNone;

Create form2 with the controls as desired and the following properties:

Color := clFuchsia; // or whatever color is not used
TransparentColor := true;
TransparentColorValue := Color;

Declare a Boolean field in form1 named AllowMove.

In TForm1.FormShow call the following code:

begin
  form2.BorderStyle := bsNone;
  form2.SetBounds(0, 0, ClientWidth, ClientHeight);
  form2.Show;
  AllowMove := true;
end;

Declare a Boolean field in form1 named AllowMove and a message handler for WM_MOVE:

procedure WMMOVE(var Message: TMessage); message WM_MOVE;

procedure TForm1.WMMOVE(var Message: TMessage);
begin
  inherited;
  if AllowMove then begin
    Form2.Left := Message.LParamLo;
    Form2.Top := Message.LParamHi;
  end;
  Message.Result := 0;
end;
Uwe Raabe
  • 45,288
  • 3
  • 82
  • 130
  • nice idea (thanks) but if i will try use TMemo to show text then i need new, better, harder idea? – user3062006 Dec 03 '13 at 17:53
  • If you want the memo to be opaque, just place it onto the form. If you want it to be transparent, set its color to clFuchsia. You can remove the border by setting the BorderStyle to bsNone. – Uwe Raabe Dec 03 '13 at 19:01
  • oh, it works quite well, thank you :). But procedure WMMOVE dont work – user3062006 Dec 03 '13 at 21:05
  • i cant move window (i cant move form1 and cant move form2) – user3062006 Dec 03 '13 at 21:13
  • btw. maybe use WM_NCHitTest or something? – user3062006 Dec 03 '13 at 21:18
  • this WM_Move works if you hold title bar but if you using BorderStyle := bsNone; on Form1 then you dont have title Bar so it (this procedure) dont work? Yes? – user3062006 Dec 03 '13 at 22:01
  • 2
    The form in the picture you showed doesn't have a title bar either. So I assumed you don't want one. To move a Window without a title bar: http://stackoverflow.com/questions/10921093/move-form-without-border-style – Uwe Raabe Dec 03 '13 at 22:48
2

The only way that I know to get that kind of effect is to render the window contents to an in-memory bitmap, then apply the desired alpha values to the non-font pixels, and then use UpdateLayeredWindow() to display the bitmap on a window. You cannot achieve that affect with a TForm as it relies on SetLayeredWindowAttributes() instead.

Create a 32bit bitmap and draw the desired background on it with alpha values, using a separate array to keep track of the current pixel values in the spots you are going to draw text on, then draw the actual text and use the array to detect which pixels were changed so you can clear the alpha values from just those pixels. Then display the bitmap.

Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770
2

You can get something close by layering two forms over each other. Set the bottom form's color to blue, enable AlphaBlend, and set AlphaBlend to something like 100. That just provides the blue background.

On second form, set TransparentColor to clBtnFace, and put your label there. Set the label font's quality to fqAntialiased.

Set both form's BorderStyle to bsNone.

Lay the second form over the first form, and there you go.

This might be workable if you don't plan on letting the user move the forms, or you move them together.

Marcus Adams
  • 53,009
  • 9
  • 91
  • 143