Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Help with alphablend

Posted on 2013-11-11
23
Medium Priority
?
690 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 14
  • 9
23 Comments
 
LVL 31

Expert Comment

by:Marco Gasi
ID: 39638423
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 31

Expert Comment

by:Marco Gasi
ID: 39638428
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
ID: 39638484
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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 31

Expert Comment

by:Marco Gasi
ID: 39638598
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 31

Expert Comment

by:Marco Gasi
ID: 39638664
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
ID: 39638934
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
ID: 39638963
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 31

Expert Comment

by:Marco Gasi
ID: 39638980
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 31

Expert Comment

by:Marco Gasi
ID: 39639395
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 31

Expert Comment

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

png more near to the real effect
0
 
LVL 31

Expert Comment

by:Marco Gasi
ID: 39639432
A better sample:)

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

Expert Comment

by:Marco Gasi
ID: 39639441
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 31

Expert Comment

by:Marco Gasi
ID: 39639447
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
ID: 39639475
Hello marqusG,

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

Expert Comment

by:Marco Gasi
ID: 39639486
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
ID: 39639734
Ok, I didn't install the component. Thanks for the concerning.

I use Delphi X4.
0
 
LVL 31

Expert Comment

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

Author Comment

by:hidrau
ID: 39641244
Sorry, I made a mistake with my x4 LOL, you are right, it is XE4 :)
0
 
LVL 31

Accepted Solution

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

Author Comment

by:hidrau
ID: 39642038
Yeah, it is correct.
Thanks
0
 
LVL 1

Author Closing Comment

by:hidrau
ID: 39642041
thanks
0
 
LVL 31

Expert Comment

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

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Suggested Courses

650 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