As in all things there are fashions in UI and UX design. Right now perhaps the biggest trend is “dark mode”. Unless you’ve been living under a rock you probably know this is where the operating system – Windows, iOS, macOS and Android – supports a user interface theme where the elements can be set to a “dark mode” which generally means all those big swathes of white automagically turn to a dark charcoal or black color.
Windows 10 supports such a mode. If you’re running one of the later builds you’ll find that all sorts of things can be ‘dark’.
I personally run all my devices – I use Windows, macOS, iOS and Android every day – in dark mode. I suffer from a harmless but annoying visual issue which people commonly call “floaters”. It’s a factor of my age and eyesight. This means that bright white screens are not optimal since these little whispy things float around in my field of view while I am trying to get on with the job of coding. With Dark Mode enabled the floaters, which are also dark, are almost completely mitigated to the point where I don’t even notice them.
So, for me, and perhaps others, Dark Mode is a huge benefit rather than just an aesthetic choice and I want every app I can to support it.
This is where my CodeRage 2019 video (below) comes in. We can detect whether Windows 10 is running in Dark or regular ‘light’ mode using standard and fairly straight-forward Delphi code. When we know what mode the OS is running in we can use the power of Delphi’s VCL to swap the entire visual experience of our application to an appropriate theme.
In the video I show you how to do this with a simple Delphi unit I wrote which you can include in your own apps. There’s also a demo project you can play with.
One thing I don’t discuss is what to do if your app is already running and then the user changes the Windows theme from light to dark or vice versa.
To cope with that scenario you need to trap the WM_SYSCOLORCHANGE Windows message.
procedure WMSysColorChange(var Message: TWMSysColorChange); message WM_SYSCOLORCHANGE;
When the WM_SYSCOLORCHANGE message is triggered you then need to check the Windows theme mode and react accordingly. Like so:
Note that all of this pertains to Microsoft Windows – and Windows 10 onwards. Other OS do it differently. Note also that Delphi 10.3.3 Rio has just been released and this includes specific code for Dark mode in your apps.
The link to the full video is here:
The code samples can be found on my GitHub pages: https://github.com/checkdigits/delphidarkmode