• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 731
  • Last Modified:

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
0
hidrau
Asked:
hidrau
  • 14
  • 9
1 Solution
 
Marco GasiFreelancerCommented:
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
0
 
Marco GasiFreelancerCommented:
I found this tutorial which seems to be interesting: you can see if it makes sense for you: http://melander.dk/articles/alphasplash/
0
 
hidrauAuthor Commented:
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
0
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
Marco GasiFreelancerCommented:
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
0
 
Marco GasiFreelancerCommented:
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

0
 
hidrauAuthor Commented:
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?
0
 
hidrauAuthor Commented:
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.
0
 
Marco GasiFreelancerCommented:
Have tak a look at the link I posted above? I didn't read it but it seems interesting... I talk about translucent form.
0
 
Marco GasiFreelancerCommented:
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
0
 
Marco GasiFreelancerCommented:
Ooops, jpg is not a ggod format to post that image:

png more near to the real effect
0
 
Marco GasiFreelancerCommented:
A better sample:)

This is good enough, I think...
0
 
Marco GasiFreelancerCommented:
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...
0
 
Marco GasiFreelancerCommented:
Lol, I dodn't follow the link you psted above so I didn't know you had solved the problem yet :)
Cheers
0
 
hidrauAuthor Commented:
Hello marqusG,

Thanks very much, I will download it and try it.
0
 
Marco GasiFreelancerCommented:
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?
0
 
hidrauAuthor Commented:
Ok, I didn't install the component. Thanks for the concerning.

I use Delphi X4.
0
 
Marco GasiFreelancerCommented:
I know Delphi 4 and Delphi XE4, but not Delphi X4 :) Am i missing something?
0
 
hidrauAuthor Commented:
Sorry, I made a mistake with my x4 LOL, you are right, it is XE4 :)
0
 
Marco GasiFreelancerCommented:
Lol.
So you can use GlassFrame property of the form, isn't it?
0
 
hidrauAuthor Commented:
Yeah, it is correct.
Thanks
0
 
hidrauAuthor Commented:
thanks
0
 
Marco GasiFreelancerCommented:
Thanks for undeserved points and good luck with your project.
0

Featured Post

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

  • 14
  • 9
Tackle projects and never again get stuck behind a technical roadblock.
Join Now