Sign in Join
Wiki copytemporary

Aero Glass/de: what changed

Revision 3 to 4. Removed lines have a minus sign; added lines have a plus sign.

OldNewLine
11## Der Aero-Glass-Effekt in einem Lazarus-Formular
22
33![](/wiki-images/5/5b/Aero_glass_lazarus.png)
44
55**Hinweis:** Funktioniert nur mit Windows !
66
77Speichern Sie zuerst den nachfolgenden Code in einer Textdatei namens "glass.pas":
88
99``` pascal
1010// Aero Glass Effekt für Delphi-Forms
1111//
1212// Mit der Methode GlassForm kann für eine Form der
1313// Aero Glass Effekt unter Vista aktiviert werden.
1414// Der erste Parameter ist die Form-Klasse, der zweite
1515// optionale Parameter ist der BlurColorKey. Mit dem
1616// BlurColorKey wird eine Farbe festgelegt, auf dem
1717// der Effekt wirken soll, d.h. benutzt eine Komponente,
1818// auf der Form, für visuelle Darstellungen (Linien, Punkte,
1919// Bilder, ...), diese Farbe, so wird an dieser Stelle der
2020// Effekt wirksam. Der Standardwert für BlurColorKey ist
2121// clFuchsia.
2222//
2323// Hinweis: Für die Aktivierung wird zusätzlich TXPManifest
2424// bzw. eine RES-Datei die die Manifest-Daten
2525// enthält benötigt.
2626//
2727//
2828// Delphi-Unit von Daniel Mitte (2006)
2929//
3030//
3131// Beispiel:
3232//
3333// uses glass;
3434//
3535// [...]
3636//
3737// procedure TForm1.FormActivate(Sender: TObject);
3838// begin
3939// GlassForm(Form1);
4040// // oder mit anderem BlurColorKey
4141// // GlassForm(Form1, clBlue)
4242// end;
4343
4444unit glass;
4545
4646interface
4747
4848{$mode delphi}
4949
5050uses
5151 Windows,
5252 Forms,
5353 Graphics;
5454
5555procedure GlassForm(frm: TForm; cBlurColorKey: TColor = clFuchsia);
5656
5757implementation
5858
5959procedure GlassForm(frm: TForm; cBlurColorKey: TColor = clFuchsia);
6060const
6161 WS_EX_LAYERED = $80000;
6262 LWA_COLORKEY = 1;
6363
6464type
6565 _MARGINS = packed record
6666 cxLeftWidth: Integer;
6767 cxRightWidth: Integer;
6868 cyTopHeight: Integer;
6969 cyBottomHeight: Integer;
7070 end;
7171 PMargins = ^_MARGINS;
7272 TMargins = _MARGINS;
7373
7474 DwmIsCompositionEnabledFunc = function(pfEnabled: PBoolean): HRESULT; stdcall;
7575 DwmExtendFrameIntoClientAreaFunc = function(destWnd: HWND; const pMarInset: PMargins): HRESULT; stdcall;
7676 SetLayeredWindowAttributesFunc = function(destWnd: HWND; cKey: TColor; bAlpha: Byte; dwFlags: DWord): BOOL; stdcall;
7777
7878var
7979 hDWMDLL: Cardinal;
8080 osVinfo: TOSVERSIONINFO;
8181 fDwmIsCompositionEnabled: DwmIsCompositionEnabledFunc;
8282 fDwmExtendFrameIntoClientArea: DwmExtendFrameIntoClientAreaFunc;
8383 fSetLayeredWindowAttributesFunc: SetLayeredWindowAttributesFunc;
8484 bCmpEnable: Boolean;
8585 mgn: TMargins;
8686
8787begin
8888 ZeroMemory(@osVinfo, SizeOf(osVinfo));
8989 OsVinfo.dwOSVersionInfoSize := SizeOf(TOSVERSIONINFO);
9090
9191 if ((GetVersionEx(osVInfo) = True) and (osVinfo.dwPlatformId = VER_PLATFORM_WIN32_NT) and (osVinfo.dwMajorVersion >= 6)) then
9292 begin
9393 hDWMDLL := LoadLibrary('dwmapi.dll');
9494
9595 if hDWMDLL <> 0 then
9696 begin
9797 @fDwmIsCompositionEnabled := GetProcAddress(hDWMDLL, 'DwmIsCompositionEnabled');
9898 @fDwmExtendFrameIntoClientArea := GetProcAddress(hDWMDLL, 'DwmExtendFrameIntoClientArea');
9999 @fSetLayeredWindowAttributesFunc := GetProcAddress(GetModulehandle(user32), 'SetLayeredWindowAttributes');
100100
101101 if ((@fDwmIsCompositionEnabled <> nil) and (@fDwmExtendFrameIntoClientArea <> nil) and (@fSetLayeredWindowAttributesFunc <> nil)) then
102102 begin
103103 fDwmIsCompositionEnabled(@bCmpEnable);
104104
105105 if bCmpEnable = True then
106106 begin
107107 frm.Color := cBlurColorKey;
108108
109109 SetWindowLong(frm.Handle, GWL_EXSTYLE, GetWindowLong(frm.Handle, GWL_EXSTYLE) or WS_EX_LAYERED);
110110 fSetLayeredWindowAttributesFunc(frm.Handle, cBlurColorKey, 0, LWA_COLORKEY);
111111
112112 ZeroMemory(@mgn, SizeOf(mgn));
113113 mgn.cxLeftWidth := -1;
114114 mgn.cxRightWidth := -1;
115115 mgn.cyTopHeight := -1;
116116 mgn.cyBottomHeight := -1;
117117
118118 fDwmExtendFrameIntoClientArea(frm.Handle, @mgn);
119119 end;
120120 end;
121121
122122 FreeLibrary(hDWMDLL);
123123 end;
124124 end;
125125end;
126126
127127end.
128128```
129129
130130Kopieren Sie die Datei "glass.pas" in den Hauptordner Ihres Projektes:
131131
132-```
132+```text
133133 MeinProjekt\glass.pas
134134```
135135
136136Fügen Sie im Abschnitt "uses" Ihres Projektes das Wort "glass" hinzu:
137137
138138``` pascal
139139unit form1;
140140
141141{$mode objfpc}{$H+}
142142
143143interface
144144
145145uses
146146 Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs
147147 glass; // Dadurch wird die Prozedur 'GlassForm' verfügbar gemacht
148148```
149149
150150Rufen Sie diese Prozedur im 'OnActivate'-Ereignis eines jeden Formulars auf:
151151
152152``` pascal
153153procedure TForm1.FormActivate(Sender: TObject);
154154begin
155155 GlassForm(Form1,clBlue); // Dies wendet den Aero-Glass-Effekt auf Form1 an
156156end;
157157```
158158
159159Außerdem müssen Sie *Themen* aktivieren, um diese Prozedur einsetzen zu können. Gehen Sie dazu zu Projektinspektor \> Einstellungen \> Projekteinstellungen \> und wählen Sie "Themen mit Manifest-Datei einschalten (nur in Windows)".
160160
161161## Fehler
162162
163163Wie Sie sehen können, werden die Labels im ersten Bild nicht sehr schön dargestellt in Aero Glass. Es folgen einige Links zu Komponenten und Code die zeigen, wie man "Labels zum Leuchten bringt":
164164
165165- [GlowLabel for Delphi](http://development.mwcs.de/glowlabel.html)
166166- [Aero Glass - ein Text (Label) hintergrund "machen"](http://www.delphipraxis.net/953968-post4.html)
167167
168168## Über
169169
170170Diese Komponente wurde zu Lazarus konvertiert mit "{\$mode delphi}". Sie stammt her von "Aero Glass Effekt für Delphi-Forms, Delphi-Unit von Daniel Mitte (2006)":
171171
172172- [Aero Glass Effekt für Delphi-Forms](http://www.delphipraxis.net/74538-aero-glass-effekt-fuer-delphi-forms.html)
173173
174174Es gibt eine Delphi-Komponente (die nach Lazarus portiert werden könnte) hier:
175175
176176- [D. Mitte in Torry's Delphi Page](http://www.torry.net/authorsmore.php?id=6179)
177177
178178---
179179*From the Free Pascal wiki, page "Aero Glass/de", 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).*
180180Category: Tutorials/de

Back to history