Aero Glass: what changed
Revision 1 to 2. Removed lines have a minus sign; added lines have a plus sign.
| Old | New | Line | |
|---|---|---|---|
| 1 | - | ||
| 2 | - | ||
| 3 | - | ||
| 4 | - | ||
| 5 | - | ||
| 6 | - | ||
| 7 | - | ||
| 8 | - | ||
| 9 | - | ||
| 10 | - | ||
| 11 | - | ||
| 12 | - | ||
| 13 | - | ||
| 14 | - | ||
| 15 | - | ||
| 16 | - | ||
| 17 | - | ||
| 18 | - | ||
| 19 | - | ||
| 20 | - | ||
| 21 | - | ||
| 1 | + | [](</File:Windows_logo_-_2012.svg>) | |
| 22 | 2 | ||
| 23 | - | ||
| 24 | - | ||
| 25 | - | ||
| 26 | - | ||
| 27 | - | ||
| 28 | - | ||
| 29 | - | ||
| 3 | + | This article applies to [Windows](</Category:Windows> "Category:Windows") only. | |
| 30 | 4 | ||
| 31 | - | ||
| 32 | - | ||
| 5 | + | See also: [[Multiplatform Programming Guide]] | |
| 33 | 6 | ||
| 34 | - | ||
| 35 | - | ||
| 36 | - | ||
| 7 | + | │ **[[Aero Glass/de|Deutsch (de)]]** │ **English (en)** │ **[[Aero Glass/es|español (es)]]** │ **[[Aero Glass/pl|polski (pl)]]** │ | |
| 8 | + | **** | |
| 37 | 9 | ||
| 38 | - | ||
| 39 | - | ||
| 40 | - | ||
| 10 | + | ## Contents | |
| 41 | 11 | ||
| 42 | - | ||
| 43 | - | ||
| 12 | + | * 1 Aero Glass effect on Lazarus Form | |
| 13 | + | * 2 Windows 10 | |
| 14 | + | * 3 Bugs | |
| 15 | + | * 4 About | |
| 44 | 16 | ||
| 45 | - | ||
| 17 | + | ## Aero Glass effect on Lazarus Form | |
| 46 | 18 | ||
| 47 | - | ||
| 48 | - | ||
| 49 | - | ||
| 50 | - | ||
| 51 | - | ||
| 52 | - | ||
| 53 | - | ||
| 54 | - | ||
| 55 | - | ||
| 56 | - | ||
| 57 | - | ||
| 58 | - | ||
| 59 | - | ||
| 60 | - | ||
| 19 | + | [](</File:aero_glass_lazarus.png>) | |
| 61 | 20 | ||
| 62 | - | ||
| 63 | - | ||
| 64 | - | ||
| 65 | - | ||
| 66 | - | ||
| 67 | - | ||
| 68 | - | ||
| 69 | - | ||
| 70 | - | ||
| 71 | - | ||
| 72 | - | ||
| 73 | - | ||
| 74 | - | ||
| 75 | - | ||
| 76 | - | ||
| 77 | - | ||
| 78 | - | ||
| 79 | - | ||
| 80 | - | ||
| 21 | + | First save the above code to a text file "glass.pas": | |
| 22 | + | ``` | |
| 23 | + | unit glass; | |
| 24 | + | ||
| 25 | + | {$mode delphi} | |
| 26 | + | //{$mode objfpc}{$H+} | |
| 27 | + | ||
| 28 | + | interface | |
| 29 | + | ||
| 30 | + | uses | |
| 31 | + | Windows, Forms, Graphics; | |
| 32 | + | ||
| 33 | + | type | |
| 34 | + | _MARGINS = packed record | |
| 35 | + | cxLeftWidth : Integer; | |
| 36 | + | cxRightWidth : Integer; | |
| 37 | + | cyTopHeight : Integer; | |
| 38 | + | cyBottomHeight : Integer; | |
| 39 | + | end; | |
| 40 | + | ||
| 41 | + | PMargins = ^_MARGINS; | |
| 42 | + | TMargins = _MARGINS; | |
| 43 | + | ||
| 44 | + | DwmIsCompositionEnabledFunc = function(pfEnabled: PBoolean): HRESULT; stdcall; | |
| 45 | + | DwmExtendFrameIntoClientAreaFunc = function(destWnd: HWND; const pMarInset: PMargins): HRESULT; stdcall; | |
| 46 | + | SetLayeredWindowAttributesFunc = function(destWnd: HWND; cKey: TColor; bAlpha: Byte; dwFlags: DWord): BOOL; stdcall; | |
| 47 | + | ||
| 48 | + | const | |
| 49 | + | WS_EX_LAYERED = $80000; | |
| 50 | + | LWA_COLORKEY = 1; | |
| 51 | + | ||
| 52 | + | procedure GlassForm(frm: TForm; tmpMargins: TMargins; cBlurColorKey: TColor = clFuchsia); | |
| 53 | + | function WindowsAeroGlassCompatible: Boolean; | |
| 54 | + | ||
| 55 | + | implementation | |
| 56 | + | ||
| 57 | + | function WindowsAeroGlassCompatible: Boolean; | |
| 58 | + | var | |
| 59 | + | osVinfo: TOSVERSIONINFO; | |
| 60 | + | begin | |
| 61 | + | ZeroMemory(@osVinfo, SizeOf(osVinfo)); | |
| 62 | + | OsVinfo.dwOSVersionInfoSize := SizeOf(TOSVERSIONINFO); | |
| 81 | 63 | if ( | |
| 82 | - | ||
| 83 | - | ||
| 84 | - | ||
| 64 | + | (GetVersionEx(osVInfo) = True) and | |
| 65 | + | (osVinfo.dwPlatformId = VER_PLATFORM_WIN32_NT) and | |
| 66 | + | (osVinfo.dwMajorVersion >= 6) | |
| 85 | 67 | ) | |
| 86 | - | ||
| 87 | - | ||
| 88 | - | ||
| 89 | - | ||
| 90 | - | ||
| 91 | - | ||
| 92 | - | ||
| 93 | - | ||
| 94 | - | ||
| 95 | - | ||
| 96 | - | ||
| 97 | - | ||
| 98 | - | ||
| 99 | - | ||
| 100 | - | ||
| 101 | - | ||
| 102 | - | ||
| 103 | - | ||
| 68 | + | then Result:=True | |
| 69 | + | else Result:=False; | |
| 70 | + | end; | |
| 71 | + | ||
| 72 | + | procedure GlassForm(frm: TForm; tmpMargins: TMargins; cBlurColorKey: TColor = clFuchsia); | |
| 73 | + | var | |
| 74 | + | hDwmDLL: Cardinal; | |
| 75 | + | fDwmIsCompositionEnabled: DwmIsCompositionEnabledFunc; | |
| 76 | + | fDwmExtendFrameIntoClientArea: DwmExtendFrameIntoClientAreaFunc; | |
| 77 | + | fSetLayeredWindowAttributesFunc: SetLayeredWindowAttributesFunc; | |
| 78 | + | bCmpEnable: Boolean; | |
| 79 | + | mgn: TMargins; | |
| 80 | + | begin | |
| 81 | + | { Continue if Windows version is compatible } | |
| 82 | + | if WindowsAeroGlassCompatible then begin | |
| 83 | + | { Continue if 'dwmapi' library is loaded } | |
| 84 | + | hDwmDLL := LoadLibrary('dwmapi.dll'); | |
| 85 | + | if hDwmDLL <> 0 then begin | |
| 86 | + | { Get values } | |
| 87 | + | @fDwmIsCompositionEnabled := GetProcAddress(hDwmDLL, 'DwmIsCompositionEnabled'); | |
| 88 | + | @fDwmExtendFrameIntoClientArea := GetProcAddress(hDwmDLL, 'DwmExtendFrameIntoClientArea'); | |
| 89 | + | @fSetLayeredWindowAttributesFunc := GetProcAddress(GetModulehandle(user32), 'SetLayeredWindowAttributes'); | |
| 90 | + | { Continue if values are <> nil } | |
| 91 | + | if ( | |
| 92 | + | (@fDwmIsCompositionEnabled <> nil) and | |
| 93 | + | (@fDwmExtendFrameIntoClientArea <> nil) and | |
| 94 | + | (@fSetLayeredWindowAttributesFunc <> nil) | |
| 95 | + | ) | |
| 96 | + | then begin | |
| 97 | + | { Continue if composition is enabled } | |
| 98 | + | fDwmIsCompositionEnabled(@bCmpEnable); | |
| 99 | + | if bCmpEnable = True then begin | |
| 100 | + | { Set Form Color same as cBlurColorKey } | |
| 101 | + | frm.Color := cBlurColorKey; | |
| 102 | + | { ... } | |
| 103 | + | SetWindowLong(frm.Handle, GWL_EXSTYLE, GetWindowLong(frm.Handle, GWL_EXSTYLE) or WS_EX_LAYERED); | |
| 104 | + | { ... } | |
| 105 | + | fSetLayeredWindowAttributesFunc(frm.Handle, cBlurColorKey, 0, LWA_COLORKEY); | |
| 106 | + | { Set margins } | |
| 107 | + | ZeroMemory(@mgn, SizeOf(mgn)); | |
| 108 | + | mgn.cxLeftWidth := tmpMargins.cxLeftWidth; | |
| 109 | + | mgn.cxRightWidth := tmpMargins.cxRightWidth; | |
| 110 | + | mgn.cyTopHeight := tmpMargins.cyTopHeight; | |
| 111 | + | mgn.cyBottomHeight := tmpMargins.cyBottomHeight; | |
| 112 | + | { Extend Form } | |
| 113 | + | fDwmExtendFrameIntoClientArea(frm.Handle,@mgn); | |
| 114 | + | end; | |
| 115 | + | end; | |
| 116 | + | { Free loaded 'dwmapi' library } | |
| 117 | + | FreeLibrary(hDWMDLL); | |
| 104 | 118 | end; | |
| 105 | 119 | end; | |
| 106 | - | ||
| 107 | - | ||
| 108 | 120 | end; | |
| 109 | - | ||
| 110 | - | ||
| 111 | - | ||
| 112 | - | ||
| 121 | + | ||
| 122 | + | end. | |
| 113 | 123 | ``` | |
| 114 | 124 | ||
| 115 | - | ||
| 116 | - | ||
| 117 | - | ||
| 118 | - | ||
| 119 | - | ||
| 120 | - | ||
| 125 | + | Copy the "glass.pas" file to the main folder of your project: | |
| 126 | + | ``` | |
| 127 | + | MyProject\glass.pas | |
| 128 | + | ``` | |
| 121 | 129 | ||
| 122 | - | ||
| 130 | + | In the "uses" section of your project you need to add "glass": | |
| 131 | + | ``` | |
| 123 | 132 | unit form1; | |
| 124 | - | ||
| 125 | - | ||
| 126 | - | ||
| 127 | - | ||
| 128 | - | ||
| 129 | - | ||
| 130 | - | ||
| 131 | - | ||
| 133 | + | ||
| 134 | + | {$mode objfpc}{$H+} | |
| 135 | + | ||
| 136 | + | interface | |
| 137 | + | ||
| 138 | + | uses | |
| 139 | + | Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs | |
| 140 | + | glass; // This includes GlassForm procedure | |
| 132 | 141 | ``` | |
| 133 | 142 | ||
| 134 | - | ||
| 135 | - | ||
| 136 | - | ||
| 143 | + | OnActivate event of each form call the procedure in this way: | |
| 144 | + | ``` | |
| 137 | 145 | procedure TForm1.FormActivate(Sender: TObject); | |
| 138 | - | ||
| 139 | - | ||
| 140 | - | ||
| 141 | - | ||
| 142 | - | ||
| 143 | - | ||
| 144 | - | ||
| 145 | - | ||
| 146 | - | ||
| 147 | - | ||
| 148 | - | ||
| 146 | + | var | |
| 147 | + | tmpMargins: TMargins; | |
| 148 | + | begin | |
| 149 | + | { If all margins are -1 the whole form will be aero glass} | |
| 150 | + | tmpMargins.cxLeftWidth := -1; | |
| 151 | + | tmpMargins.cxRightWidth := -1; | |
| 152 | + | tmpMargins.cyBottomHeight := -1; | |
| 153 | + | tmpMargins.cyTopHeight := -1; | |
| 154 | + | { FormName ; Margins ; TransparentColor } | |
| 155 | + | GlassForm(Self, tmpMargins, clFuchsia); | |
| 156 | + | end; | |
| 149 | 157 | ``` | |
| 150 | 158 | ||
| 151 | - | ||
| 159 | + | Also you need to enable Themes to use this procedure, go to Options > Project Options > then select "Use Manifest to Enable Themes (Windows)". | |
| 152 | 160 | ||
| 153 | 161 | ## Windows 10 | |
| 154 | 162 | ||
| 155 | - | ||
| 156 | - | ||
| 157 | - | ||
| 158 | - | ||
| 159 | - | ||
| 160 | - | ||
| 163 | + | [](</File:aeroglasswin10.png>) | |
| 164 | + | ``` | |
| 161 | 165 | { | |
| 162 | - | ||
| 163 | - | ||
| 164 | - | ||
| 165 | - | ||
| 166 | - | ||
| 167 | - | ||
| 168 | - | ||
| 169 | - | ||
| 170 | - | ||
| 171 | - | ||
| 172 | - | ||
| 173 | - | ||
| 174 | - | ||
| 175 | - | ||
| 176 | - | ||
| 177 | - | ||
| 178 | - | ||
| 179 | - | ||
| 180 | - | ||
| 181 | - | ||
| 182 | - | ||
| 183 | - | ||
| 184 | - | ||
| 185 | - | ||
| 186 | - | ||
| 187 | - | ||
| 188 | - | ||
| 189 | - | ||
| 190 | - | ||
| 191 | - | ||
| 192 | - | ||
| 193 | - | ||
| 194 | - | ||
| 195 | - | ||
| 196 | - | ||
| 197 | - | ||
| 198 | - | ||
| 199 | - | ||
| 200 | - | ||
| 201 | - | ||
| 202 | - | ||
| 203 | - | ||
| 204 | - | ||
| 205 | - | ||
| 206 | - | ||
| 207 | - | ||
| 208 | - | ||
| 209 | - | ||
| 210 | - | ||
| 211 | - | ||
| 212 | - | ||
| 213 | - | ||
| 214 | - | ||
| 215 | - | ||
| 216 | - | ||
| 217 | - | ||
| 218 | - | ||
| 219 | - | ||
| 220 | - | ||
| 221 | - | ||
| 222 | - | ||
| 223 | - | ||
| 224 | - | ||
| 225 | - | ||
| 226 | - | ||
| 227 | - | ||
| 228 | - | ||
| 229 | - | ||
| 230 | - | ||
| 231 | - | ||
| 232 | - | ||
| 233 | - | ||
| 234 | - | ||
| 235 | - | ||
| 236 | - | ||
| 237 | - | ||
| 238 | - | ||
| 239 | - | ||
| 240 | - | ||
| 241 | - | ||
| 242 | - | ||
| 243 | - | ||
| 244 | - | ||
| 245 | - | ||
| 246 | - | ||
| 247 | - | ||
| 248 | - | ||
| 249 | - | ||
| 250 | - | ||
| 166 | + | author: vhanla | |
| 167 | + | http://vhanla.codigobit.info | |
| 168 | + | } | |
| 169 | + | unit Unit1; | |
| 170 | + | ||
| 171 | + | interface | |
| 172 | + | ||
| 173 | + | uses | |
| 174 | + | Windows, Messages, SysUtils, Variants, Classes, Graphics, | |
| 175 | + | Controls, Forms, Dialogs, DWMApi, png, IntfGraphics, FPImage, GraphType, | |
| 176 | + | StdCtrls, ExtCtrls, BCButtonFocus, BCLabel, Registry, LMessages, LCLType, LCLIntf; | |
| 177 | + | ||
| 178 | + | type | |
| 179 | + | ||
| 180 | + | { TForm1 } | |
| 181 | + | ||
| 182 | + | TForm1 = class(TForm) | |
| 183 | + | BCButtonFocus1: TBCButtonFocus; | |
| 184 | + | BCLabel1: TBCLabel; | |
| 185 | + | Image1: TImage; | |
| 186 | + | Image2: TImage; | |
| 187 | + | Panel1: TPanel; | |
| 188 | + | ||
| 189 | + | procedure BCButtonFocus1Click(Sender: TObject); | |
| 190 | + | procedure FormCreate(Sender: TObject); | |
| 191 | + | procedure Button1Click(Sender: TObject); | |
| 192 | + | procedure Panel1MouseDown(Sender: TObject; Button: TMouseButton; | |
| 193 | + | Shift: TShiftState; X, Y: Integer); | |
| 194 | + | private | |
| 195 | + | { Private declarations } | |
| 196 | + | function TaskbarAccented:boolean; | |
| 197 | + | function TaskbarTranslucent:boolean; | |
| 198 | + | procedure EnableBlur; | |
| 199 | + | procedure AeroGlass; | |
| 200 | + | procedure UpdateColorization; | |
| 201 | + | function GetAccentColor:TColor; | |
| 202 | + | public | |
| 203 | + | { Public declarations } | |
| 251 | 204 | end; | |
| 252 | - | ||
| 253 | - | ||
| 254 | - | ||
| 255 | - | ||
| 256 | - | ||
| 205 | + | ||
| 206 | + | AccentPolicy = packed record | |
| 207 | + | AccentState: Integer; | |
| 208 | + | AccentFlags: Integer; | |
| 209 | + | GradientColor: Integer; | |
| 210 | + | AnimationId: Integer; | |
| 211 | + | end; | |
| 212 | + | ||
| 213 | + | TWinCompAttrData = packed record | |
| 214 | + | attribute: THandle; | |
| 215 | + | pData: Pointer; | |
| 216 | + | dataSize: ULONG; | |
| 217 | + | end; | |
| 218 | + | ||
| 219 | + | ||
| 220 | + | var | |
| 221 | + | Form1: TForm1; | |
| 222 | + | ||
| 223 | + | var | |
| 224 | + | SetWindowCompositionAttribute: function (Wnd: HWND; const AttrData: TWinCompAttrData): BOOL; stdcall = Nil; | |
| 225 | + | implementation | |
| 226 | + | ||
| 227 | + | {$R *.lfm} | |
| 228 | + | ||
| 229 | + | procedure SetAlphaColorPicture( | |
| 230 | + | const Col: TColor; | |
| 231 | + | const Alpha: Integer; | |
| 232 | + | Picture: TPicture; | |
| 233 | + | const _width: Integer; | |
| 234 | + | const _height: Integer | |
| 235 | + | ); | |
| 236 | + | var | |
| 237 | + | IM: TLazIntfImage; | |
| 238 | + | x,y: integer; | |
| 239 | + | sl: pByteArray; | |
| 240 | + | I, J, W, H: Integer; | |
| 241 | + | FC: TFPColor; | |
| 242 | + | begin | |
| 243 | + | IM := TLazIntfImage.Create(0, 0, [riqfRGB, riqfAlpha]); | |
| 244 | + | try | |
| 245 | + | IM.SetSize(_width, _height); | |
| 246 | + | for I := 0 to _width - 1 do | |
| 247 | + | begin | |
| 248 | + | for J := 0 to _height - 1 do | |
| 249 | + | begin | |
| 250 | + | FC.red := (128 + I) shl 8; | |
| 251 | + | FC.green := (128 + J) shl 8; | |
| 252 | + | FC.blue := 128 shl 8; | |
| 253 | + | FC.alpha := 128 shl 8; // now works fine | |
| 254 | + | IM.Colors[I, J] := FC; | |
| 255 | + | end; | |
| 256 | + | end; | |
| 257 | + | Picture.Assign(IM); | |
| 258 | + | ||
| 259 | + | ||
| 260 | + | finally | |
| 261 | + | IM.Free; | |
| 262 | + | ||
| 263 | + | end; | |
| 257 | 264 | end; | |
| 258 | - | ||
| 259 | - | ||
| 260 | - | ||
| 261 | - | ||
| 262 | - | ||
| 263 | - | ||
| 264 | - | ||
| 265 | - | ||
| 266 | - | ||
| 267 | - | ||
| 268 | - | ||
| 269 | - | ||
| 270 | - | ||
| 271 | - | ||
| 272 | - | ||
| 273 | - | ||
| 274 | - | ||
| 275 | - | ||
| 276 | - | ||
| 277 | - | ||
| 278 | - | ||
| 279 | - | ||
| 280 | - | ||
| 281 | - | ||
| 282 | - | ||
| 283 | - | ||
| 265 | + | ||
| 266 | + | procedure TForm1.Button1Click(Sender: TObject); | |
| 284 | 267 | begin | |
| 285 | - | ||
| 286 | - | ||
| 287 | - | ||
| 288 | - | ||
| 289 | - | ||
| 290 | - | ||
| 291 | - | ||
| 292 | - | ||
| 293 | - | ||
| 294 | - | ||
| 295 | - | ||
| 296 | - | ||
| 297 | - | ||
| 298 | - | ||
| 299 | - | ||
| 300 | - | ||
| 301 | - | ||
| 302 | - | ||
| 303 | - | ||
| 304 | - | ||
| 305 | - | ||
| 306 | - | ||
| 307 | - | ||
| 308 | - | ||
| 309 | - | ||
| 310 | - | ||
| 311 | - | ||
| 312 | - | ||
| 313 | - | ||
| 268 | + | Close; | |
| 269 | + | end; | |
| 270 | + | ||
| 271 | + | procedure TForm1.Panel1MouseDown(Sender: TObject; Button: TMouseButton; | |
| 272 | + | Shift: TShiftState; X, Y: Integer); | |
| 273 | + | begin | |
| 274 | + | ReleaseCapture; | |
| 275 | + | SendMessage(Form1.Handle, LM_SYSCOMMAND, 61458, 0) ; | |
| 276 | + | end; | |
| 277 | + | ||
| 278 | + | procedure TForm1.AeroGlass; | |
| 279 | + | var | |
| 280 | + | Aero: BOOL; | |
| 281 | + | Area: TRect; | |
| 282 | + | hDWM: THandle; | |
| 283 | + | begin | |
| 284 | + | hDWM:=LoadLibrary('dwmapi.dll'); | |
| 314 | 285 | try | |
| 315 | - | ||
| 316 | - | ||
| 286 | + | @DwmIsCompositionEnabled:=GetProcAddress(hDWM,'DwmIsCompositionEnabled'); | |
| 287 | + | if @DwmIsCompositionEnabled<>nil then | |
| 288 | + | DwmIsCompositionEnabled(Aero); | |
| 289 | + | if Aero then | |
| 317 | 290 | begin | |
| 318 | - | ||
| 319 | - | ||
| 320 | - | ||
| 321 | - | ||
| 322 | - | ||
| 323 | - | ||
| 324 | - | ||
| 325 | - | ||
| 326 | - | ||
| 291 | + | Area:=Rect(-1,-1,-1,-1); | |
| 292 | + | Color:=clBlack; | |
| 293 | + | @DwmExtendFrameIntoClientArea:=GetProcAddress(hDWM,'DwmExtendFrameIntoClientArea'); | |
| 294 | + | if @DwmExtendFrameIntoClientArea<>nil then | |
| 295 | + | DwmExtendFrameIntoClientArea(Handle,@Area); | |
| 296 | + | ||
| 327 | 297 | end | |
| 328 | - | ||
| 329 | - | ||
| 330 | - | ||
| 331 | - | ||
| 298 | + | else ShowMessage('Aero is Disabled'); | |
| 332 | 299 | finally | |
| 333 | - | ||
| 300 | + | FreeLibrary(hDWM); | |
| 334 | 301 | end; | |
| 335 | - | ||
| 336 | - | ||
| 337 | - | ||
| 338 | - | ||
| 339 | - | ||
| 340 | - | ||
| 341 | - | ||
| 342 | - | ||
| 343 | - | ||
| 344 | - | ||
| 345 | - | ||
| 346 | - | ||
| 347 | - | ||
| 348 | - | ||
| 349 | - | ||
| 350 | - | ||
| 351 | - | ||
| 352 | - | ||
| 353 | - | ||
| 354 | - | ||
| 355 | - | ||
| 356 | - | ||
| 357 | - | ||
| 358 | - | ||
| 359 | - | ||
| 360 | - | ||
| 361 | - | ||
| 362 | - | ||
| 363 | - | ||
| 364 | - | ||
| 365 | - | ||
| 366 | - | ||
| 367 | - | ||
| 368 | - | ||
| 302 | + | end; | |
| 303 | + | ||
| 304 | + | procedure TForm1.EnableBlur; | |
| 305 | + | const | |
| 306 | + | WCA_ACCENT_POLICY = 19; | |
| 307 | + | ACCENT_ENABLE_BLURBEHIND = 3; | |
| 308 | + | ACCENT_ENABLE_ACRYLICBLURBEHIND = 4; | |
| 309 | + | DrawLeftBorder = $20; | |
| 310 | + | DrawTopBorder = $40; | |
| 311 | + | DrawRightBorder = $80; | |
| 312 | + | DrawBottomBorder = $100; | |
| 313 | + | var | |
| 314 | + | dwm10: THandle; | |
| 315 | + | data : TWinCompAttrData; | |
| 316 | + | accent: AccentPolicy; | |
| 317 | + | begin | |
| 318 | + | ||
| 319 | + | dwm10 := LoadLibrary('user32.dll'); | |
| 320 | + | try | |
| 321 | + | @SetWindowCompositionAttribute := GetProcAddress(dwm10, 'SetWindowCompositionAttribute'); | |
| 322 | + | if @SetWindowCompositionAttribute <> nil then | |
| 323 | + | begin | |
| 324 | + | accent.AccentState := ACCENT_ENABLE_BLURBEHIND ; | |
| 325 | + | //accent.AccentState := ACCENT_ENABLE_ACRYLICBLURBEHIND; | |
| 326 | + | accent.GradientColor := (100 SHL 24) or ($00E3E0DE); | |
| 327 | + | accent.AccentFlags := DrawLeftBorder or DrawTopBorder or DrawRightBorder or DrawBottomBorder; | |
| 328 | + | ||
| 329 | + | data.Attribute := WCA_ACCENT_POLICY; | |
| 330 | + | data.dataSize := SizeOf(accent); | |
| 331 | + | data.pData := @accent; | |
| 332 | + | SetWindowCompositionAttribute(self.Handle, data); | |
| 333 | + | end | |
| 334 | + | else | |
| 335 | + | begin | |
| 336 | + | ShowMessage('Not found Windows 10 blur API'); | |
| 337 | + | end; | |
| 338 | + | finally | |
| 339 | + | FreeLibrary(dwm10); | |
| 340 | + | end; | |
| 341 | + | ||
| 342 | + | end; | |
| 343 | + | ||
| 344 | + | procedure TForm1.FormCreate(Sender: TObject); | |
| 345 | + | begin | |
| 346 | + | DoubleBuffered := True; | |
| 347 | + | Color := clBlack; | |
| 348 | + | BorderStyle := bsnoNe; | |
| 349 | + | BorderIcons := [biSystemMenu, biMinimize, biMaximize]; | |
| 350 | + | //AeroGlass; | |
| 351 | + | if TaskbarTranslucent then | |
| 352 | + | EnableBlur; | |
| 353 | + | ||
| 354 | + | UpdateColorization; | |
| 355 | + | end; | |
| 356 | + | ||
| 357 | + | procedure TForm1.BCButtonFocus1Click(Sender: TObject); | |
| 358 | + | begin | |
| 359 | + | close; | |
| 360 | + | end; | |
| 361 | + | ||
| 362 | + | function TForm1.TaskbarAccented: boolean; | |
| 363 | + | var | |
| 364 | + | reg: TRegistry; | |
| 365 | + | begin | |
| 369 | 366 | Result := False; | |
| 367 | + | reg := TRegistry.Create; | |
| 368 | + | try | |
| 369 | + | reg.RootKey := HKEY_CURRENT_USER; | |
| 370 | + | reg.OpenKeyReadOnly('SOFTWARE\Microsoft\Windows\CurrentVersion\Themes\Personalize'); | |
| 371 | + | try | |
| 372 | + | if reg.ReadInteger('ColorPrevalence') = 1 then | |
| 373 | + | Result := True; | |
| 374 | + | except | |
| 375 | + | Result := False; | |
| 376 | + | end; | |
| 377 | + | reg.CloseKey; | |
| 378 | + | ||
| 379 | + | finally | |
| 380 | + | reg.Free; | |
| 381 | + | end; | |
| 370 | 382 | end; | |
| 371 | - | ||
| 372 | - | ||
| 373 | - | ||
| 374 | - | ||
| 375 | - | ||
| 376 | - | ||
| 377 | - | ||
| 378 | - | ||
| 379 | - | ||
| 380 | - | ||
| 381 | - | ||
| 382 | - | ||
| 383 | - | ||
| 384 | - | ||
| 385 | - | ||
| 386 | - | ||
| 387 | - | ||
| 388 | - | ||
| 389 | - | ||
| 390 | - | ||
| 383 | + | ||
| 384 | + | function TForm1.TaskbarTranslucent: boolean; | |
| 385 | + | var | |
| 386 | + | reg: TRegistry; | |
| 387 | + | begin | |
| 391 | 388 | Result := False; | |
| 389 | + | reg := TRegistry.Create; | |
| 390 | + | try | |
| 391 | + | reg.RootKey := HKEY_CURRENT_USER; | |
| 392 | + | reg.OpenKeyReadOnly('SOFTWARE\Microsoft\Windows\CurrentVersion\Themes\Personalize'); | |
| 393 | + | try | |
| 394 | + | if reg.ReadInteger('EnableTransparency') = 1 then | |
| 395 | + | Result := True; | |
| 396 | + | except | |
| 397 | + | Result := False; | |
| 398 | + | end; | |
| 399 | + | reg.CloseKey; | |
| 400 | + | ||
| 401 | + | finally | |
| 402 | + | reg.Free; | |
| 403 | + | end; | |
| 392 | 404 | end; | |
| 393 | - | ||
| 394 | - | ||
| 395 | - | ||
| 396 | - | ||
| 397 | - | ||
| 398 | - | ||
| 399 | - | ||
| 400 | - | ||
| 401 | - | ||
| 402 | - | ||
| 403 | - | ||
| 404 | - | ||
| 405 | - | ||
| 406 | - | ||
| 407 | - | ||
| 408 | - | ||
| 409 | - | ||
| 410 | - | ||
| 411 | - | ||
| 412 | - | ||
| 413 | - | ||
| 414 | - | ||
| 415 | - | ||
| 416 | - | ||
| 417 | - | ||
| 418 | - | ||
| 419 | - | ||
| 420 | - | ||
| 421 | - | ||
| 422 | - | ||
| 423 | - | ||
| 424 | - | ||
| 425 | - | ||
| 426 | - | ||
| 427 | - | ||
| 428 | - | ||
| 429 | - | ||
| 430 | - | ||
| 431 | - | ||
| 432 | - | ||
| 433 | - | ||
| 434 | - | ||
| 435 | - | ||
| 436 | - | ||
| 437 | - | ||
| 438 | - | ||
| 439 | - | ||
| 440 | - | ||
| 441 | - | ||
| 442 | - | ||
| 443 | - | ||
| 444 | - | ||
| 445 | - | ||
| 446 | - | ||
| 447 | - | ||
| 448 | - | ||
| 405 | + | ||
| 406 | + | ||
| 407 | + | ||
| 408 | + | procedure TForm1.UpdateColorization; | |
| 409 | + | begin | |
| 410 | + | if TaskbarTranslucent then | |
| 411 | + | begin | |
| 412 | + | SetAlphaColorPicture(clblack, 200, Image1.Picture, 10,10 ); | |
| 413 | + | Image1.Align := alClient; | |
| 414 | + | Image1.Stretch := True; | |
| 415 | + | Image1.Visible := True; | |
| 416 | + | end | |
| 417 | + | else | |
| 418 | + | Image1.Visible := False; | |
| 419 | + | ||
| 420 | + | if TaskbarAccented then | |
| 421 | + | begin | |
| 422 | + | SetAlphaColorPicture(9338482, 110, Image2.Picture, 10, 10); | |
| 423 | + | Image2.Visible := True; | |
| 424 | + | Image2.Align := alClient; | |
| 425 | + | Image2.Stretch := True; | |
| 426 | + | end | |
| 427 | + | else | |
| 428 | + | Image2.Visible := False; | |
| 429 | + | end; | |
| 430 | + | ||
| 431 | + | function TForm1.GetAccentColor:TColor; | |
| 432 | + | var | |
| 433 | + | col: cardinal; | |
| 434 | + | opaque: longbool; | |
| 435 | + | newcolor: TColor; | |
| 436 | + | a,r,g,b: byte; | |
| 437 | + | begin | |
| 438 | + | DwmGetColorizationColor(col, opaque); | |
| 439 | + | a := Byte(col shr 24); | |
| 440 | + | r := Byte(col shr 16); | |
| 441 | + | g := Byte(col shr 8); | |
| 442 | + | b := Byte(col); | |
| 443 | + | ||
| 444 | + | ||
| 445 | + | newcolor := RGB( | |
| 446 | + | round(r*(a/255)+255-a), | |
| 447 | + | round(g*(a/255)+255-a), | |
| 448 | + | round(b*(a/255)+255-a) | |
| 449 | + | ); | |
| 450 | + | ||
| 451 | + | Result := newcolor; | |
| 452 | + | ||
| 453 | + | ||
| 454 | + | end; | |
| 455 | + | ||
| 456 | + | ||
| 457 | + | initialization | |
| 458 | + | SetWindowCompositionAttribute := GetProcAddress(GetModuleHandle(user32), 'SetWindowCompositionAttribute'); | |
| 459 | + | end. | |
| 449 | 460 | ``` | |
| 450 | 461 | ||
| 451 | 462 | ## Bugs | |
| 452 | 463 | ||
| 453 | - | ||
| 464 | + | As you can see in the first image Labels aren't displayed fine in Aero Glass, there are links with components and code that show how to make "Glow Labels": | |
| 454 | 465 | ||
| 455 | - | ||
| 456 | - | ||
| 466 | + | * [GlowLabel for Delphi](<http://development.mwcs.de/glowlabel.html>) | |
| 467 | + | * [Aero Glass - ein Text (Label) hintergrund "machen"](<http://www.delphipraxis.net/953968-post4.html>) | |
| 457 | 468 | ||
| 458 | - | ||
| 469 | + | Also if you clic the transparent part of the window the back window / desktop is selected (focus is lost in the form with aero glass). | |
| 459 | 470 | ||
| 460 | 471 | ## About | |
| 461 | 472 | ||
| 462 | - | ||
| 473 | + | This was converted to Lazarus using "{$mode delphi}" from "Aero Glass Effekt für Delphi-Forms, Delphi-Unit von Daniel Mitte (2006)": | |
| 463 | 474 | ||
| 464 | - | ||
| 475 | + | * [Aero Glass Effekt für Delphi-Forms](<http://www.delphipraxis.net/74538-aero-glass-effekt-fuer-delphi-forms.html>) | |
| 465 | 476 | ||
| 466 | - | ||
| 477 | + | There is a Delphi component here (to be ported in Lazarus): | |
| 467 | 478 | ||
| 468 | - | ||
| 479 | + | * [D. Mitte in Torry's Delphi Page](<http://www.torry.net/authorsmore.php?id=6179>) | |
| 469 | 480 | ||
| 470 | 481 | --- | |
| 471 | - | ||
| 472 | - | ||
| 473 | - | ||
| 482 | + | *From the Free Pascal wiki, page "Aero Glass", as the Internet Archive kept it on 2024-01-21. 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).* |
