Solved

Help with alphablend

Posted on 2013-11-11
23
580 Views
Last Modified: 2013-11-12
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
Comment
Question by:hidrau
  • 14
  • 9
23 Comments
 
LVL 30

Expert Comment

by:Marco Gasi
Comment Utility
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
 
LVL 30

Expert Comment

by:Marco Gasi
Comment Utility
I found this tutorial which seems to be interesting: you can see if it makes sense for you: http://melander.dk/articles/alphasplash/
0
 
LVL 1

Author Comment

by:hidrau
Comment Utility
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
 
LVL 30

Expert Comment

by:Marco Gasi
Comment Utility
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
 
LVL 30

Expert Comment

by:Marco Gasi
Comment Utility
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
 
LVL 1

Author Comment

by:hidrau
Comment Utility
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
 
LVL 1

Author Comment

by:hidrau
Comment Utility
0
 
LVL 1

Author Comment

by:hidrau
Comment Utility
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
 
LVL 30

Expert Comment

by:Marco Gasi
Comment Utility
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
 
LVL 30

Expert Comment

by:Marco Gasi
Comment Utility
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
 
LVL 30

Expert Comment

by:Marco Gasi
Comment Utility
Ooops, jpg is not a ggod format to post that image:

png more near to the real effect
0
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 
LVL 30

Expert Comment

by:Marco Gasi
Comment Utility
A better sample:)

This is good enough, I think...
0
 
LVL 30

Expert Comment

by:Marco Gasi
Comment Utility
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
 
LVL 30

Expert Comment

by:Marco Gasi
Comment Utility
Lol, I dodn't follow the link you psted above so I didn't know you had solved the problem yet :)
Cheers
0
 
LVL 1

Author Comment

by:hidrau
Comment Utility
Hello marqusG,

Thanks very much, I will download it and try it.
0
 
LVL 30

Expert Comment

by:Marco Gasi
Comment Utility
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
 
LVL 1

Author Comment

by:hidrau
Comment Utility
Ok, I didn't install the component. Thanks for the concerning.

I use Delphi X4.
0
 
LVL 30

Expert Comment

by:Marco Gasi
Comment Utility
I know Delphi 4 and Delphi XE4, but not Delphi X4 :) Am i missing something?
0
 
LVL 1

Author Comment

by:hidrau
Comment Utility
Sorry, I made a mistake with my x4 LOL, you are right, it is XE4 :)
0
 
LVL 30

Accepted Solution

by:
Marco Gasi earned 500 total points
Comment Utility
Lol.
So you can use GlassFrame property of the form, isn't it?
0
 
LVL 1

Author Comment

by:hidrau
Comment Utility
Yeah, it is correct.
Thanks
0
 
LVL 1

Author Closing Comment

by:hidrau
Comment Utility
thanks
0
 
LVL 30

Expert Comment

by:Marco Gasi
Comment Utility
Thanks for undeserved points and good luck with your project.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now