?
Solved

Need window with transparent portions

Posted on 2003-03-26
10
Medium Priority
?
358 Views
Last Modified: 2010-04-03
Can anybody help me to create windows (forms?) with alpha channel, that is, having transparent or semitransparent portions inside the bounding rectangle? I saw something like that on the about box of Photoshop 7 and on Norton Safeguard from Norton Utilities. Notice that simply copying and blending the background image on the form is not a really good idea because it's wery hard to update it dynamically. Just consider that our form is "always on top" and an other window is going to be moved behind our form.
0
Comment
Question by:zoltan082098
[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
  • 3
  • 3
  • 3
  • +1
10 Comments
 
LVL 27

Expert Comment

by:kretzschmar
ID: 8209907
go www.cooldev.com -> CoolControls
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 8209930
see there about the components

TCoolFormHook, TCoolImageShape
0
 
LVL 10

Expert Comment

by:kacor
ID: 8210072
Hi,

próbáld meg a www.softwareonline.hu oldalon, a korábbi delphi cikkekben vagy 10 foglalkozik az átlátszó ablak kérdésével

János
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 27

Expert Comment

by:kretzschmar
ID: 8210092
? what, kacor
0
 

Author Comment

by:zoltan082098
ID: 8212781
kretzschmar,

TCoolFormHook with TCoolImageShape does work well, but not enough smart for me. The above mentioned "alpha channel" means that there is a supplementary gray-level bitmap only for specifying the amount of transparency for each pixel from the form (this may be an easy way for a form not just to have an irregular form but also a drop shadow similar to xp menus). TCoolImageShape can't do this. In addition, it isn't free...
BTW, don't worry about kacor. It's easy to recognize that I'm Hungarian so he has recommended me a Hungarian site. (What a pity, the articles mentioned on this site are unaccesible unless paying an access fee.)
I rather would be happy with some ideas to help me developing such a component...

Zoltan
0
 
LVL 34

Expert Comment

by:Slick812
ID: 8219803
hello zoltan, if you can do with out the Alpha Blend for protions of the Form, you could use a Region to create transparent areas of your form using
SetWindowRgn(Handle, hRgn, True);

you might could use an Alpha Channel form behind the Region Form to have areas of Alpha blend and solid areas. . .
0
 

Author Comment

by:zoltan082098
ID: 8225869
Slick,
Thanks for your tip, it seems to be a really "cheap" (I mean free) solution for transparent windows. Please standby couple of days to find out if really works for me.
In meantime it would be great to tell me more about "Alpha Channel form"; I still cannot understand how you can specify for each pixel of the form its own transparency level.
thanks,
Zoltan
0
 
LVL 34

Expert Comment

by:Slick812
ID: 8228001
As Far as I have used the Alpha Blend Form, you can not define pixels for transparency, all of the form's pixels are the same transparency. . . Here is some code for setting the region And an Alpha Blend Form. . . Notice that this Alpha Blend is only for Win 2000 and Newer -



unit AlphaBlend1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls;

type
  TForm1 = class(TForm)
    but_Exit: TButton;
    procedure but_ExitClick(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure FormPaint(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.but_ExitClick(Sender: TObject);
begin
Close;
end;

procedure TForm1.FormCreate(Sender: TObject);
type
 TSetLayeredWindowAttributes = function(hWnd: HWND; CrKey: COLORREF;
                        bAlpha: Byte; dwFlags: DWORD):BOOL; stdcall;

var
 SetLayerWA: TSetLayeredWindowAttributes;
 hLib, hRgn1, hRgn2: Integer;
 Color: Cardinal;
const
 LWA_COLORKEY = 1;
 LWA_ALPHA  = 2;
 WS_EX_LAYERED = $80000;
begin
Height := 300;
Width :=  400;
Color := $0000FF;
{if you set the LWA_COLORKEY flag, then all of the pixels
that are Color on the form will be Transparent AND NOT in this
window's Region, see the OnPaint Event for the Red Rectagle}
if(Win32Platform = VER_PLATFORM_WIN32_NT) and (Win32MajorVersion >= 5) then
  begin
  hLib := LoadLibrary('USER32.DLL');
  if hLib > 0 then
    try
    SetWindowLong(Handle, GWL_EXSTYLE, WS_EX_LAYERED);
    SetLayerWA := GetProcAddress(hLib, 'SetLayeredWindowAttributes') ;
    if @SetLayerWA <> nil then
    SetLayerWA(Handle, Color, 164, LWA_ALPHA or LWA_COLORKEY);
    finally
    FreeLibrary(hLib);
    end;
  end;

hRgn1 := CreateRectRgn(0,Height-38, Width, Height);
hRgn2 := CreateEllipticRgn(-10,-150, Width+10, 250);
CombineRgn(hRgn1, hRgn1, hRgn2, RGN_OR);
SetWindowRgn(Handle, hRgn1, False);
DeleteObject(hRgn2);
end;

procedure TForm1.FormPaint(Sender: TObject);
begin
Canvas.Brush.Color := $0000FF;
Canvas.Rectangle(20,20,120,120);
{this Red Rect will NOT be part of this window}
end;

end.



- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
There is also the UpdateLayeredWindow( ) function, which I have never used, but is supposed to let you do more stuff with the Layer (Alpha Blend). . . . maybe you can vary the blend or transparency with it? ? ?
0
 
LVL 34

Accepted Solution

by:
Slick812 earned 2000 total points
ID: 8228071
maybe you could look at these MSDN pages about window layers


http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnwui/html/layerwin.asp
0
 

Author Comment

by:zoltan082098
ID: 8233731
I think there are enough given informations here to close the question and to thank for slick its contribution. I also apologize to kretzschmar and kacor about their essentially correct answers but the slick's one was which helped me to really understand the transparency mechanism.
Thanks,
Zoltan
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
Suggested Courses

770 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