Home » Developing U++ » U++ Developers corner » Dynamic skin changes...
Re: Dynamic skin changes... [message #61201 is a reply to message #61200] |
Wed, 04 December 2024 07:48   |
Tom1
Messages: 1303 Registered: March 2007
|
Ultimate Contributor |
|
|
mirek wrote on Tue, 03 December 2024 21:22Does not make sense at all.... I guess you want those function to mean something else than I intended...
Anyway, just for you (I guess), I have added Win32 only
void ChHostSkinLight();
void ChHostSkinDark();
Use with Ctrl::SetSkin ... I guess this should solve your problem.
Hi Mirek!
And thank you very much! This is exactly what I needed. Early Christmas this year 
Now the dynamic/static theming sample becomes:
#include <CtrlLib/CtrlLib.h>
using namespace Upp;
struct MainWindow : public TopWindow{
MenuBar menu;
MainWindow() {
Title("Dynamic Theming Sample").Sizeable();
AddFrame(menu);
menu.Set([=](Bar& bar) {
bar.Sub("Theme",[=](Bar& bar) {
bar.Add("System",[=] { Ctrl::SetSkin(ChHostSkin); });
#ifdef WIN32
bar.Add("Light",[=] { Ctrl::SetSkin(ChHostSkinLight); });
bar.Add("Dark",[=] { Ctrl::SetSkin(ChHostSkinDark); });
#endif
bar.Add("Custom",[=] { Ctrl::SetSkin(ChStdSkin); });
});
});
}
};
GUI_APP_MAIN{
Ctrl::SkinChangeSensitive(true);
Ctrl::SetDarkThemeEnabled(true);
MainWindow().Run();
}
Best regards,
Tom
|
|
|
Re: Dynamic skin changes... [message #61204 is a reply to message #61201] |
Wed, 04 December 2024 12:48   |
Tom1
Messages: 1303 Registered: March 2007
|
Ultimate Contributor |
|
|
Hi,
For those looking for rapid theme switching on Windows, I composed a tray utility to does just that. You may wish to put it in auto start, so it will be always available...
#include <CtrlLib/CtrlLib.h>
using namespace Upp;
#ifndef WIN32
#error Sorry, but this program is only available for Windows at this time.
#endif
struct App : TrayIcon {
typedef App CLASSNAME;
bool IsSystemThemeDark(){
return !GetWinRegInt("AppsUseLightTheme", "Software\\Microsoft\\Windows\\CurrentVersion\\Themes\\Personalize", HKEY_CURRENT_USER);
}
void SetDarkTheme(){
SetWinRegInt(0, "SystemUsesLightTheme", "Software\\Microsoft\\Windows\\CurrentVersion\\Themes\\Personalize", HKEY_CURRENT_USER);
SetWinRegInt(0, "AppsUseLightTheme", "Software\\Microsoft\\Windows\\CurrentVersion\\Themes\\Personalize", HKEY_CURRENT_USER);
SetWinRegInt(0, "AccentColorMenu", "Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Accent", HKEY_CURRENT_USER);
Sleep(500);
SetWinRegInt(0xff1d3f58, "AccentColorMenu", "Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Accent", HKEY_CURRENT_USER);
}
void SetLightTheme(){
SetWinRegInt(1, "SystemUsesLightTheme", "Software\\Microsoft\\Windows\\CurrentVersion\\Themes\\Personalize", HKEY_CURRENT_USER);
SetWinRegInt(1, "AppsUseLightTheme", "Software\\Microsoft\\Windows\\CurrentVersion\\Themes\\Personalize", HKEY_CURRENT_USER);
SetWinRegInt(0, "AccentColorMenu", "Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Accent", HKEY_CURRENT_USER);
Sleep(500);
SetWinRegInt(0xff1d3f58, "AccentColorMenu", "Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Accent", HKEY_CURRENT_USER);
}
virtual void LeftUp() {
if(IsSystemThemeDark()) SetLightTheme();
else SetDarkTheme();
}
virtual void Menu(Bar& bar) {
bool dark = IsSystemThemeDark();
bar.Add("Light", [=](){ SetLightTheme(); }).Check(!dark);
bar.Add("Dark", [=](){ SetDarkTheme(); }).Check(dark);
bar.Separator();
bar.Add("Exit", [=](){ Break(); });
}
App() {
Icon(Image::Hand());
}
};
GUI_APP_MAIN
{
Ctrl::SetDarkThemeEnabled(true);
#if (UPP_VERSION>=0x20241100)
Ctrl::SkinChangeSensitive(true);
#endif
App().Run();
}
Feel free to include this in U++ or use wherever you need it.
Best regards,
Tom
EDIT: You may also wish to give it a nice tray icon instead of "Image::Hand()"
[Updated on: Wed, 04 December 2024 12:50] Report message to a moderator
|
|
|
|
|
|
|
|
|
|
Goto Forum:
Current Time: Thu Jun 12 20:31:38 CEST 2025
Total time taken to generate the page: 0.05154 seconds
|