Articles   Members Online:
-Article/Tip Search
-News Group Search over 21 Million news group articles.
-Delphi/Pascal
-CBuilder/C++
-C#Builder/C#
-JBuilder/Java
-Kylix
Member Area
-Home
-Account Center
-Top 10 NEW!!
-Submit Article/Tip
-Forums Upgraded!!
-My Articles
-Edit Information
-Login/Logout
-Become a Member
-Why sign up!
-Newsletter
-Chat Online!
-Indexes NEW!!
Employment
-Build your resume
-Find a job
-Post a job
-Resume Search
Contacts
-Contacts
-Feedbacks
-Link to us
-Privacy/Disclaimer
Embarcadero
Visit Embarcadero
Embarcadero Community
JEDI
Links
How to set the level of transparency for a TForm Turn on/off line numbers in source code. Switch to Orginial background IDE or DSP color Comment or reply to this aritlce/tip for discussion. Bookmark this article to my favorite article(s). Print this article
28-Oct-02
Category
VCL-Forms
Language
Delphi 2.x
Views
106
User Rating
No Votes
# Votes
0
Replies
0
Publisher:
DSP, Administrator
Reference URL:
DKB
			Author: Jonas Bilinkevicius

I want to create a form that has some degree of transparency. I know that in 
Windows 2000 SDK there is a very good resource to do that 
(SetLayeredWindowAttributes), but this one is not implemented in Windows.pas. I 
tried to import directly from user32.dll, and I even could find the value for some 
constants (WS_EX_LAYERED) with non documented value (MS C++.net), but at the end, I 
got some weird messages of "invalid variant type conversion" when trying to use 
this function. Does somebody have any example written in Delphi using this function?

Answer:

Solve 1:

1   { ... }
2   const
3     WS_EX_LAYERED = $80000;
4     LWA_COLORKEY = 1;
5     LWA_ALPHA = 2;
6   type
7     TSetLayeredWindowAttributes = function(
8       hwnd: HWND; {handle to the layered window}
9       crKey: TColor; {specifies the color key}
10      bAlpha: byte; {value for the blend function}
11      dwFlags: DWORD {action}
12      ): BOOL; stdcall;
13  
14  procedure TfBaseSplash.FormCreate(Sender: TObject);
15  var
16    Info: TOSVersionInfo;
17    F: TSetLayeredWindowAttributes;
18  begin
19    inherited;
20    Info.dwOSVersionInfoSize := SizeOf(Info);
21    GetVersionEx(Info);
22    if (Info.dwPlatformId = VER_PLATFORM_WIN32_NT) and (Info.dwMajorVersion >= 5) then
23    begin
24      F := GetProcAddress(GetModulehandle(user32), 'SetLayeredWindowAttributes');
25      if Assigned(F) then
26      begin
27        SetWindowLong(Handle, GWL_EXSTYLE, GetWindowLong(Handle,
28          GWL_EXSTYLE) or WS_EX_LAYERED);
29        F(Handle, 0, Round(255 * 80 / 100), LWA_ALPHA);
30      end;
31    end;
32  end;



Solve 2:

Make sure you check that the OS supports it. Here's how I do it:

33  function ALLOWALPHA: Boolean;
34  type
35    TSetLayeredWindowAttributes = function(hwnd: HWND; crKey: LongInt; bAlpha: Byte;
36      dwFlags: LongInt): LongInt; stdcall;
37  var
38    FhUser32: THandle;
39    SetLayeredWindowAttributes: TSetLayeredWindowAttributes;
40  begin
41    AllowAlpha := False;
42    FhUser32 := LoadLibrary('USER32.DLL');
43    if FhUser32 <> 0 then
44    begin
45      @SetLayeredWindowAttributes := GetProcAddress(FhUser32,
46        'SetLayeredWindowAttributes');
47      if @SetLayeredWindowAttributes <> nil then
48      begin
49        FreeLibrary(FhUser32);
50        Result := TRUE;
51      end
52      else
53      begin
54        FreeLibrary(FhUser32);
55        Result := False;
56      end;
57    end;
58  end;


			
Vote: How useful do you find this Article/Tip?
Bad Excellent
1 2 3 4 5 6 7 8 9 10

 

Advertisement
Share this page
Advertisement
Download from Google

Copyright © Mendozi Enterprises LLC