Avatar of hidrau
hidrauFlag for Brazil asked on

Help with alphablend

Hello Guys,

is it possible to use alphablend only in a form without affects all the components on the form?

With alphablend property, when I use it, all the component are affected.

I use Delphi x4

Thanks
Alex
Delphi

Avatar of undefined
Last Comment
Marco Gasi

8/22/2022 - Mon
Marco Gasi

I'll google a few, but this is the code I used to make a form transparent without affecting other components:

//declare within your private variables
var
  FullRgn, ClientRgn, CtlRgn, TBordRgn, BBordRgn, LBordRgn, RBordRgn,
  EllRgn, EllRgn2, EllRgn3 : THandle;

//procedure which does the magic
procedure TBarFrm.DoInvisible;
var
  AControl : TControl;
  A, Margin, X, Y, CtlX, CtlY : Integer;
begin
  Margin := ( Width - ClientWidth ) div 2;
  //First, get form region
  FullRgn := CreateRectRgn(0, 0, Width, Height);
  //Find client area region
  X := Margin;
  Y := Height - ClientHeight - Margin;
  ClientRgn := CreateRectRgn( X, Y, X + ClientWidth, Y + ClientHeight );
  //'Mask' out all but non-client areas
  CombineRgn( FullRgn, FullRgn, ClientRgn, RGN_DIFF );

  //Now, walk through all the controls on the form and 'OR' them
  // into the existing Full region.
  for A := 0 to ControlCount - 1 do begin
    AControl := Controls[A];
    if ( AControl is TComboBox ) or (AControl is TRxSpeedButton)
        then with AControl do begin
      if Visible then begin
        CtlX := X + Left;
        CtlY := Y + Top;
        CtlRgn := CreateRectRgn( CtlX, CtlY, CtlX + Width, CtlY + Height );
        CombineRgn( FullRgn, FullRgn, CtlRgn, RGN_OR );
      end;
    end;
  end;
//here you can set different border accordingly to the user choice stored in regEntries.noBorder, regEntries.smallBord and so on. You can use only a little part of this code to set borders of your form

  if not regEntries.noBorder then
  begin
    if regEntries.smallBord then
    begin
      TBordRgn := CreateRectRgn(0, 0, 150, 2);     //left, top, right, bottom
      CombineRgn(FullRgn, FullRgn, TBordRgn, RGN_OR);
      BBordRgn := CreateRectRgn(0, 80, 150, 82);
      CombineRgn(FullRgn, FullRgn, BBordRgn, RGN_OR);
      LBordRgn := CreateRectRgn(0, 2, 2, 80);
      CombineRgn(FullRgn, FullRgn, LBordRgn, RGN_OR);
      RBordRgn := CreateRectRgn(148, 2, 150, 80);
      CombineRgn(FullRgn, FullRgn, RBordRgn, RGN_OR);
    end else if regEntries.medBord then
    begin
      TBordRgn := CreateRectRgn(0, 0, 150, 3);     //left, top, right, bottom
      CombineRgn(FullRgn, FullRgn, TBordRgn, RGN_OR);
      BBordRgn := CreateRectRgn(0, 79, 150, 82);
      CombineRgn(FullRgn, FullRgn, BBordRgn, RGN_OR);
      LBordRgn := CreateRectRgn(0, 3, 3, 79);
      CombineRgn(FullRgn, FullRgn, LBordRgn, RGN_OR);
      RBordRgn := CreateRectRgn(147, 3, 150, 80);
      CombineRgn(FullRgn, FullRgn, RBordRgn, RGN_OR);
    end else if regEntries.largeBord then
    begin
      TBordRgn := CreateRectRgn(0, 0, 150, 4);
      CombineRgn(FullRgn, FullRgn, TBordRgn, RGN_OR);
      BBordRgn := CreateRectRgn(0, 78, 150, 82);
      CombineRgn(FullRgn, FullRgn, BBordRgn, RGN_OR);
      LBordRgn := CreateRectRgn(0, 4, 4, 78);
      CombineRgn(FullRgn, FullRgn, LBordRgn, RGN_OR);
      RBordRgn := CreateRectRgn(146, 4, 150, 79);
      CombineRgn(FullRgn, FullRgn, RBordRgn, RGN_OR);
    end;
  end;

  // Create transparent form
  EllRgn := CreateRectRgn(11, 59, 28, 74);        //left, top, right, bottom
  CombineRgn(FullRgn, FullRgn, EllRgn, RGN_OR);
  EllRgn2 := CreateRectRgn(35, 59, 52, 74);
  CombineRgn(FullRgn, FullRgn, EllRgn2, RGN_OR);
  EllRgn3 := CreateRectRgn(59, 59, 76, 74);
  CombineRgn(FullRgn, FullRgn, EllRgn3, RGN_OR);
  //When the region is all ready, put it into effect:
  SetWindowRgn(Handle, FullRgn, TRUE);
end;

//Free memory
procedure TForm1FormDestroy(Sender: TObject);
begin
  //Clean up the regions we created
  DeleteObject(ClientRgn);
  DeleteObject(FullRgn);
  DeleteObject(CtlRgn);
end;

Open in new window


Hope this helps
Cheers
Marco Gasi

I found this tutorial which seems to be interesting: you can see if it makes sense for you: http://melander.dk/articles/alphasplash/
ASKER
hidrau

marqusG,

I am having problem in this part:

Checking project dependencies...
Compiling Project2.dproj (Debug configuration)
[DCC Error] Unit1.pas(64): E2003 Undeclared identifier: 'regEntries'
[DCC Error] Unit1.pas(64): E2029 'THEN' expected but identifier 'noBorder' found
[DCC Error] Unit1.pas(66): E2029 'THEN' expected but identifier 'smallBord' found
[DCC Error] Unit1.pas(76): E2029 'THEN' expected but identifier 'medBord' found
[DCC Error] Unit1.pas(86): E2029 'THEN' expected but identifier 'largeBord' found
[DCC Hint] Unit1.pas(16): H2219 Private symbol 'DoInvisible' declared but never used
[DCC Fatal Error] Project2.dpr(5): F2063 Could not compile used unit 'Unit1.pas'
Failed
Elapsed time: 00:00:00.1
All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck
Marco Gasi

All those variables have to be replaced by actual values: I posted the code as I used but regEntries was a unit when I initialized values loading from registry or storing them in registry. NoNorder, smallBord, medBord, largeBord are variables you must declare. My code allows you to set borders but you have to set if you want a smallBorder or a largeBorder.

DoInvisible is a procedure: declare it in your private clause and be sure your form is called Form1, otherwise you have to change

procedure TForm1.DoInvisible

with TYourFormName.DoInvisible
Marco Gasi

Use this code as it is: it will draw a small border around. If you don't want the border comment out lines 32-39.
Remember to change TForm1 with the actual form you're using and to declare the procedure DoInvisible in your private clause.

procedure TForm1.DoInvisible;
var
  AControl : TControl;
  A, Margin, X, Y, CtlX, CtlY : Integer;
begin
  Margin := ( Width - ClientWidth ) div 2;
  //First, get form region
  FullRgn := CreateRectRgn(0, 0, Width, Height);
  //Find client area region
  X := Margin;
  Y := Height - ClientHeight - Margin;
  ClientRgn := CreateRectRgn( X, Y, X + ClientWidth, Y + ClientHeight );
  //'Mask' out all but non-client areas
  CombineRgn( FullRgn, FullRgn, ClientRgn, RGN_DIFF );

  //Now, walk through all the controls on the form and 'OR' them
  // into the existing Full region.
  for A := 0 to ControlCount - 1 do begin
    AControl := Controls[A];
    if ( AControl is TComboBox ) or (AControl is TRxSpeedButton)
        then with AControl do begin
      if Visible then begin
        CtlX := X + Left;
        CtlY := Y + Top;
        CtlRgn := CreateRectRgn( CtlX, CtlY, CtlX + Width, CtlY + Height );
        CombineRgn( FullRgn, FullRgn, CtlRgn, RGN_OR );
      end;
    end;
  end;
  
  //this will you give a small border
  TBordRgn := CreateRectRgn(0, 0, 150, 2);     //left, top, right, bottom
  CombineRgn(FullRgn, FullRgn, TBordRgn, RGN_OR);
  BBordRgn := CreateRectRgn(0, 80, 150, 82);
  CombineRgn(FullRgn, FullRgn, BBordRgn, RGN_OR);
  LBordRgn := CreateRectRgn(0, 2, 2, 80);
  CombineRgn(FullRgn, FullRgn, LBordRgn, RGN_OR);
  RBordRgn := CreateRectRgn(148, 2, 150, 80);
  CombineRgn(FullRgn, FullRgn, RBordRgn, RGN_OR);
  
  EllRgn := CreateRectRgn(11, 59, 28, 74);        //left, top, right, bottom
  CombineRgn(FullRgn, FullRgn, EllRgn, RGN_OR);
  EllRgn2 := CreateRectRgn(35, 59, 52, 74);
  CombineRgn(FullRgn, FullRgn, EllRgn2, RGN_OR);
  EllRgn3 := CreateRectRgn(59, 59, 76, 74);
  CombineRgn(FullRgn, FullRgn, EllRgn3, RGN_OR);
  //When the region is all ready, put it into effect:
  SetWindowRgn(Handle, FullRgn, TRUE);
end;

Open in new window

ASKER
hidrau

marqusG,

I don't want the invisible form, that I can do with transparentcolor.

I'd like a alphablend form opacity but that all my buttons, edits could not be affected.

Even though, I thank you  very much to trying to help me.

But Did you get it?
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
ASKER
hidrau

ASKER
hidrau

Well, I think I found the way, as you can see the answer on that link I gave to you, but it only works on windows vista upper, it doesn't work on windows XP.

And as we can see, it is different from alpha blend. the form gets a like a blue color transparent. It wasn't what I'd like. I'd like an effect like a glass.
Marco Gasi

Have tak a look at the link I posted above? I didn't read it but it seems interesting... I talk about translucent form.
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck
Marco Gasi

I found teh component TAeroGlass that you can find on a dedicated Torry's page.

The component is declared for D2 up to Delphi 2006 but I've installed in Delphi XE3 and it works without problem. It gives you full transparency, glass effect in a region you can define settings margin values and a full translucent effect as you can see in the image below. For this effect you have to set component's properties as follows:

DragGlass: dgNone
MarginBottom, MarginLeft, MarginRight, MarginTop as they are
SheetOfGlass: True

Glass form with normal components
Marco Gasi

Ooops, jpg is not a ggod format to post that image:

png more near to the real effect
Marco Gasi

A better sample:)

This is good enough, I think...
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
Marco Gasi

I just seen that not always teh form is translucent: launching the exe file sometimes is translucent, somtimes is transparent, so this component is not affordable, but its source code can teach you something interesting about the effect you want...
Marco Gasi

Lol, I dodn't follow the link you psted above so I didn't know you had solved the problem yet :)
Cheers
ASKER
hidrau

Hello marqusG,

Thanks very much, I will download it and try it.
This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
rwheeler23
Marco Gasi

WAIT, WAIT! Don't install that component: study the source, but don't install it. I've just uninstalled because it is malformed: when you try to remove it from the form it raises an error saying it isn't possible cancel an external created thread plus other errors of the IDE. So I repeat: don't install it.

Let's me ask a thing: in the link you posted above there is a solution simple and clear: the FlassFrame property which is native in Delphi XE3 so I suppose you have it also in your Delphi XE4... or Delphi x4 is another thing?
ASKER
hidrau

Ok, I didn't install the component. Thanks for the concerning.

I use Delphi X4.
Marco Gasi

I know Delphi 4 and Delphi XE4, but not Delphi X4 :) Am i missing something?
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
ASKER
hidrau

Sorry, I made a mistake with my x4 LOL, you are right, it is XE4 :)
ASKER CERTIFIED SOLUTION
Marco Gasi

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
See how we're fighting big data
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
ASKER
hidrau

Yeah, it is correct.
Thanks
ASKER
hidrau

thanks
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy
Marco Gasi

Thanks for undeserved points and good luck with your project.