Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Need window with transparent portions

Posted on 2003-03-26
10
Medium Priority
?
366 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
  • 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 35

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 35

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 35

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

Become an Android App Developer

Ready to kick start your career in 2018? Learn how to build an Android app in January’s Course of the Month and open the door to new opportunities.

Question has a verified solution.

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

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
This is an update to some code that someone else posted on Experts Exchange. It is an alternate approach, I think a little easier to use, & makes sure that things like the Task Bar will update.
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
The Relationships Diagram is a good way to get an overall view of what a database is keeping track of. It is also where relationships are defined. A relationship specifies how two tables connect to each other. As you build tables in Microsoft Ac…

564 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