Skip to content

Commit 70c5749

Browse files
committed
Initial commit
0 parents  commit 70c5749

13 files changed

+1796
-0
lines changed

.gitattributes

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Auto detect text files and perform LF normalization
2+
* text=auto

.gitignore

+69
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
# Uncomment these types if you want even more clean repository. But be careful.
2+
# It can make harm to an existing project source. Read explanations below.
3+
#
4+
# Resource files are binaries containing manifest, project icon and version info.
5+
# They can not be viewed as text or compared by diff-tools. Consider replacing them with .rc files.
6+
#*.res
7+
#
8+
# Type library file (binary). In old Delphi versions it should be stored.
9+
# Since Delphi 2009 it is produced from .ridl file and can safely be ignored.
10+
#*.tlb
11+
#
12+
# Diagram Portfolio file. Used by the diagram editor up to Delphi 7.
13+
# Uncomment this if you are not using diagrams or use newer Delphi version.
14+
#*.ddp
15+
#
16+
# Visual LiveBindings file. Added in Delphi XE2.
17+
# Uncomment this if you are not using LiveBindings Designer.
18+
#*.vlb
19+
#
20+
# Deployment Manager configuration file for your project. Added in Delphi XE2.
21+
# Uncomment this if it is not mobile development and you do not use remote debug feature.
22+
#*.deployproj
23+
#
24+
# C++ object files produced when C/C++ Output file generation is configured.
25+
# Uncomment this if you are not using external objects (zlib library for example).
26+
#*.obj
27+
#
28+
29+
# Delphi compiler-generated binaries (safe to delete)
30+
*.exe
31+
*.dll
32+
*.bpl
33+
*.bpi
34+
*.dcp
35+
*.so
36+
*.apk
37+
*.drc
38+
*.map
39+
*.dres
40+
*.rsm
41+
*.tds
42+
*.dcu
43+
*.lib
44+
*.a
45+
*.o
46+
*.ocx
47+
48+
# Delphi autogenerated files (duplicated info)
49+
*.cfg
50+
*.hpp
51+
*Resource.rc
52+
53+
# Delphi local files (user-specific info)
54+
*.local
55+
*.identcache
56+
*.projdata
57+
*.tvsconfig
58+
*.dsk
59+
60+
# Delphi history and backups
61+
__history/
62+
__recovery/
63+
*.~*
64+
65+
# Castalia statistics file (since XE7 Castalia is distributed with Delphi)
66+
*.stat
67+
68+
# Boss dependency manager vendor folder https://github.com/HashLoad/boss
69+
modules/

LICENSE

+674
Large diffs are not rendered by default.

README.md

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# delphidarkmode
2+
Detecting and acting on Windows' Dark Mode theme setting

Unit1.dfm

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
object Form1: TForm1
2+
Left = 0
3+
Top = 0
4+
BorderIcons = [biSystemMenu]
5+
BorderStyle = bsDialog
6+
Caption = 'Dark mode test'
7+
ClientHeight = 241
8+
ClientWidth = 293
9+
Color = clBtnFace
10+
Font.Charset = DEFAULT_CHARSET
11+
Font.Color = clWindowText
12+
Font.Height = -11
13+
Font.Name = 'Tahoma'
14+
Font.Style = []
15+
OldCreateOrder = False
16+
Position = poScreenCenter
17+
PixelsPerInch = 96
18+
TextHeight = 13
19+
object Button1: TButton
20+
Left = 49
21+
Top = 24
22+
Width = 177
23+
Height = 25
24+
Caption = 'Check for system mode'
25+
TabOrder = 0
26+
OnClick = Button1Click
27+
end
28+
object RadioGroup1: TRadioGroup
29+
Left = 49
30+
Top = 80
31+
Width = 185
32+
Height = 105
33+
Caption = 'Set theme'
34+
ItemIndex = 1
35+
Items.Strings = (
36+
'Dark'
37+
'Light')
38+
TabOrder = 1
39+
OnClick = RadioGroup1Click
40+
end
41+
end

Unit1.pas

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
unit Unit1;
2+
3+
interface
4+
5+
uses
6+
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
7+
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Vcl.ExtCtrls;
8+
9+
type
10+
TForm1 = class(TForm)
11+
Button1: TButton;
12+
RadioGroup1: TRadioGroup;
13+
procedure Button1Click(Sender: TObject);
14+
procedure RadioGroup1Click(Sender: TObject);
15+
end;
16+
17+
var
18+
Form1: TForm1;
19+
20+
implementation
21+
uses WindowsDarkMode;
22+
23+
{$R *.dfm}
24+
25+
{ TForm1 }
26+
27+
procedure TForm1.Button1Click(Sender: TObject);
28+
begin
29+
if DarkModeIsEnabled then
30+
ShowMessage('Dark mode is enabled.')
31+
else
32+
ShowMessage('Dark mode is NOT enabled.');
33+
end;
34+
35+
procedure TForm1.RadioGroup1Click(Sender: TObject);
36+
begin
37+
SetSpecificThemeMode(RadioGroup1.ItemIndex = 0, 'Carbon', 'Windows10');
38+
end;
39+
40+
end.

WindowsDarkMode.pas

+97
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
unit WindowsDarkMode;
2+
3+
//
4+
// Originally written by Ian Barker
5+
// https://github.com/checkdigits
6+
// https://about.me/IanBarker
7+
8+
//
9+
// Free software - use for any purpose including commercial use.
10+
//
11+
12+
interface
13+
14+
// Checks the Windows registry to see if Windows Dark Mode is enabled
15+
function DarkModeIsEnabled: boolean;
16+
17+
// Automatically sets a Dark Mode theme is Windows is running in Dark Mode
18+
// To use:
19+
// 1. Got to project properties
20+
// 2. Select appearance and choose two or more themes. Note down the names!
21+
// 3. In your FormCreate (or wherever) put the following line:
22+
// SetAppropriateThemeMode(**name_of_the_dark_theme**, **namme_of_the_non_dark_theme**);
23+
//
24+
// For example:
25+
// SetAppropriateThemeMode('Carbon', 'Windows10');
26+
//
27+
procedure SetAppropriateThemeMode(const DarkModeThemeName, LightModeThemeName: string);
28+
29+
// Sets either a Dark Mode or non Dark mode theme based in the "AsDarkMode" boolean
30+
// For example:
31+
// SetSpecificThemeMode(False, 'TheDarkModeThemeName', 'TheLightModeThemeName');
32+
// Would change the application theme to the theme with the name 'TheLightModeThemeName'
33+
// if it exists.
34+
//
35+
procedure SetSpecificThemeMode(const AsDarkMode: Boolean; const DarkModeThemeName, LightModeThemeName: string);
36+
37+
38+
implementation
39+
uses
40+
{$IFDEF MSWINDOWS}
41+
Winapi.Windows, // for the pre-defined registry key constants
42+
System.Win.Registry, // for the registry read access
43+
{$ENDIF}
44+
VCL.themes; // Used for access to TStyleManager
45+
46+
procedure SetAppropriateThemeMode(const DarkModeThemeName, LightModeThemeName: string);
47+
begin
48+
SetSpecificThemeMode(DarkModeIsEnabled, DarkModeThemeName, LightModeThemeName);
49+
end;
50+
51+
procedure SetSpecificThemeMode(const AsDarkMode: Boolean; const DarkModeThemeName, LightModeThemeName: string);
52+
var
53+
ChosenTheme: string;
54+
begin
55+
if AsDarkMode then
56+
ChosenTheme := DarkModeThemeName
57+
else
58+
ChosenTheme := LightModeThemeName;
59+
TStyleManager.TrySetStyle(ChosenTheme, False);
60+
end;
61+
62+
function DarkModeIsEnabled: boolean;
63+
{$IFDEF MSWINDOWS}
64+
const
65+
TheKey = 'Software\Microsoft\Windows\CurrentVersion\Themes\Personalize\';
66+
TheValue = 'AppsUseLightTheme';
67+
var
68+
Reg: TRegistry;
69+
{$ENDIF}
70+
begin
71+
72+
Result := False; // There is no dark side - the Jedi are victorious!
73+
74+
// This relies on a registry setting only available on MS Windows
75+
// If the developer has somehow managed to get to this point then tell
76+
// them not to do this!
77+
{$IFNDEF MSWINDOWS}
78+
{$MESSAGE WARN '"DarkModeIsEnabled" will only work on MS Windows targets'}
79+
{$ELSE}
80+
Reg := TRegistry.Create(KEY_READ);
81+
try
82+
Reg.RootKey := HKEY_CURRENT_USER;
83+
if Reg.KeyExists(TheKey) then
84+
if Reg.OpenKey(TheKey, False) then
85+
try
86+
if Reg.ValueExists(TheValue) then
87+
Result := Reg.ReadInteger(TheValue) = 0;
88+
finally
89+
Reg.CloseKey;
90+
end;
91+
finally
92+
Reg.Free;
93+
end;
94+
{$ENDIF}
95+
end;
96+
97+
end.

sunnies.ico

5.3 KB
Binary file not shown.

sunnies_16.png

608 Bytes
Loading

sunnies_32.png

1.55 KB
Loading

vcltips1.dpr

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
program vcltips1;
2+
3+
uses
4+
Vcl.Forms,
5+
Unit1 in 'Unit1.pas' {Form1},
6+
Vcl.Themes,
7+
Vcl.Styles,
8+
WindowsDarkMode in 'WindowsDarkMode.pas';
9+
10+
{$R *.res}
11+
12+
begin
13+
Application.Initialize;
14+
Application.MainFormOnTaskbar := True;
15+
Application.Title := 'Dark mode test';
16+
TStyleManager.TrySetStyle('Windows10');
17+
Application.CreateForm(TForm1, Form1);
18+
Application.Run;
19+
end.

0 commit comments

Comments
 (0)