Sign in Join
Wiki copytemporary

Aero Glass/pl: what changed

Revision 1 to 2. Removed lines have a minus sign; added lines have a plus sign.

OldNewLine
11*(Windows only)*
22
33## Efekt szkła (Aero Glass) na formularzu
44
5-<figure>
6-<img src="aero_glass_lazarus.png" title="aero_glass_lazarus.png" />
7-<figcaption>aero_glass_lazarus.png</figcaption>
8-</figure>
5+![](/wiki-images/5/5b/Aero_glass_lazarus.png)
96
107Na początku utwórz moduł ,,glass.pas", zawierający poniższy kod:
118
129``` pascal
1310unit glass;
1411
1512{$mode delphi}
1613//{$mode objfpc}{$H+}
1714
1815interface
1916
2017uses
2118 Windows, Forms, Graphics;
2219
2320type
2421 _MARGINS = packed record
2522 cxLeftWidth : Integer;
2623 cxRightWidth : Integer;
2724 cyTopHeight : Integer;
2825 cyBottomHeight : Integer;
2926 end;
3027
3128 PMargins = ^_MARGINS;
3229 TMargins = _MARGINS;
3330
3431 DwmIsCompositionEnabledFunc = function(pfEnabled: PBoolean): HRESULT; stdcall;
3532 DwmExtendFrameIntoClientAreaFunc = function(destWnd: HWND; const pMarInset: PMargins): HRESULT; stdcall;
3633 SetLayeredWindowAttributesFunc = function(destWnd: HWND; cKey: TColor; bAlpha: Byte; dwFlags: DWord): BOOL; stdcall;
3734
3835const
3936 WS_EX_LAYERED = $80000;
4037 LWA_COLORKEY = 1;
4138
4239procedure GlassForm(frm: TForm; tmpMargins: TMargins; cBlurColorKey: TColor = clFuchsia);
4340function WindowsAeroGlassCompatible: Boolean;
4441
4542implementation
4643
4744function WindowsAeroGlassCompatible: Boolean;
4845var
4946 osVinfo: TOSVERSIONINFO;
5047begin
5148 ZeroMemory(@osVinfo, SizeOf(osVinfo));
5249 OsVinfo.dwOSVersionInfoSize := SizeOf(TOSVERSIONINFO);
5350 if (
5451 (GetVersionEx(osVInfo) = True) and
5552 (osVinfo.dwPlatformId = VER_PLATFORM_WIN32_NT) and
5653 (osVinfo.dwMajorVersion >= 6)
5754 )
5855 then Result:=True
5956 else Result:=False;
6057end;
6158
6259procedure GlassForm(frm: TForm; tmpMargins: TMargins; cBlurColorKey: TColor = clFuchsia);
6360var
6461 hDwmDLL: Cardinal;
6562 fDwmIsCompositionEnabled: DwmIsCompositionEnabledFunc;
6663 fDwmExtendFrameIntoClientArea: DwmExtendFrameIntoClientAreaFunc;
6764 fSetLayeredWindowAttributesFunc: SetLayeredWindowAttributesFunc;
6865 bCmpEnable: Boolean;
6966 mgn: TMargins;
7067begin
7168 { Kontynuuj, jeśli wersja Windowsa jest kompatybilna }
7269 if WindowsAeroGlassCompatible then begin
7370 { Kontynuuj, jeśli biblioteka ,,dwmapi" jest załadowana }
7471 hDwmDLL := LoadLibrary('dwmapi.dll');
7572 if hDwmDLL <> 0 then begin
7673 { Pobierz wartości }
7774 @fDwmIsCompositionEnabled := GetProcAddress(hDwmDLL, 'DwmIsCompositionEnabled');
7875 @fDwmExtendFrameIntoClientArea := GetProcAddress(hDwmDLL, 'DwmExtendFrameIntoClientArea');
7976 @fSetLayeredWindowAttributesFunc := GetProcAddress(GetModulehandle(user32), 'SetLayeredWindowAttributes');
8077 { Kontynuuj, jeśli wartości <> nil }
8178 if (
8279 (@fDwmIsCompositionEnabled <> nil) and
8380 (@fDwmExtendFrameIntoClientArea <> nil) and
8481 (@fSetLayeredWindowAttributesFunc <> nil)
8582 )
8683 then begin
8784 { Kontynuuj, jeżeli kompozycje systemowe są włączone }
8885 fDwmIsCompositionEnabled(@bCmpEnable);
8986 if bCmpEnable = True then begin
9087 { Ustaw kolor formy na cBlurColorKey }
9188 frm.Color := cBlurColorKey;
9289 { ... }
9390 SetWindowLong(frm.Handle, GWL_EXSTYLE, GetWindowLong(frm.Handle, GWL_EXSTYLE) or WS_EX_LAYERED);
9491 { ... }
9592 fSetLayeredWindowAttributesFunc(frm.Handle, cBlurColorKey, 0, LWA_COLORKEY);
9693 { Ustaw marginesy }
9794 ZeroMemory(@mgn, SizeOf(mgn));
9895 mgn.cxLeftWidth := tmpMargins.cxLeftWidth;
9996 mgn.cxRightWidth := tmpMargins.cxRightWidth;
10097 mgn.cyTopHeight := tmpMargins.cyTopHeight;
10198 mgn.cyBottomHeight := tmpMargins.cyBottomHeight;
10299 { Rozszerz formę }
103100 fDwmExtendFrameIntoClientArea(frm.Handle,@mgn);
104101 end;
105102 end;
106103 { Zwolnij bibliotekę ,,dwmapi" }
107104 FreeLibrary(hDWMDLL);
108105 end;
109106 end;
110107end;
111108
112109end.
113110```
114111
115112Następnie skopiuj powyższy plik do folderu głównego Twojej aplikacji (tu: MojProjekt):
116113
117114` MojProjekt\glass.pas`\
118115` `
119116
120117W sekcji ,,uses" dopisz nazwę powyższego modułu:
121118
122119``` pascal
123120unit form1;
124121
125122{$mode objfpc}{$H+}
126123
127124interface
128125
129126uses
130127 Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs
131128 glass; // Tu zawiera się procedura GlassForm
132129```
133130
134131Utwórz zdarzenie OnActivate i uzupełnij je, tak jak poniżej:
135132
136133``` pascal
137134procedure TForm1.FormActivate(Sender: TObject);
138135var
139136 tmpMargins: TMargins;
140137begin
141138 { Jeżeli marginesy mają wartość -1, to cała forma będzie pokryta szkłem }
142139 tmpMargins.cxLeftWidth := -1;
143140 tmpMargins.cxRightWidth := -1;
144141 tmpMargins.cyBottomHeight := -1;
145142 tmpMargins.cyTopHeight := -1;
146143 { NazwaFormularza ; Marginesy ; KolorPrzezroczystości }
147144 GlassForm(Self, tmpMargins, clFuchsia);
148145end;
149146```
150147
151148WAŻNE: Przed uruchomieniem aplikacji włącz kompozycje, wchodząc w Projekt \> Opcje projektu \> Użyj pliku manifest aby odblokować kompozycje.
152149
153150## Bugi
154151
155152Po włączeniu efektu szkła wyraźnie widać, iż napisy (TLabel) nie mają tzw. ,,otoczki szkła". Aby rozwiązać ten problem, należy odpowiednio zaprogramować napisy. Z pomocą przychodzą poniższe linki do komponentów zwanych ,,Glow Labels":
156153
157154- [GlowLabel for Delphi](http://development.mwcs.de/glowlabel.html)
158155- [Aero Glass - ein Text (Label) hintergrund "machen"](http://www.delphipraxis.net/953968-post4.html)
159156
160157Jeżeli ustawisz kolor części systemowych (np. kolor okna), to kliknięcie na formularz będzie niemożliwe (forma traci fokus przez szkło).
161158
162159## Informacje
163160
164161Powyższe kody zostały przekonwertowane do Lazarusa na podstawie "Aero Glass Effekt für Delphi-Forms, Delphi-Unit von Daniel Mitte (2006)":
165162
166163- [Aero Glass Effekt für Delphi-Forms](http://www.delphipraxis.net/74538-aero-glass-effekt-fuer-delphi-forms.html)
167164
168165Tu znajduje się komponent (przekonwertowany także do Lazarusa):
169166
170167- [D. Mitte in Torry's Delphi Page](http://www.torry.net/authorsmore.php?id=6179)
171168
172169**Tłumaczenie**
173170
174171Na język polski przełożył: --User:Matek.y 18:30, 12.12.2017
175172
176173---
177174*From the Free Pascal wiki, page "Aero Glass/pl", as it stood on 2020-02-04 after a change by GAN, out of the wiki's dump of 2024-05-26. Copyright stays with the author who wrote it, according to the old wiki's [[Licensing]] page. If you have concerns about this material, [message the admin](/wiki-contact).*

Back to history