Home » Developing U++ » U++ Developers corner » DarkTheme support
Re: Please check the list of 2019.1 changes [message #51156 is a reply to message #51155] |
Tue, 12 February 2019 12:44   |
Tom1
Messages: 1303 Registered: March 2007
|
Ultimate Contributor |
|
|
Hi,
I composed some code to pick up the Windows 10 light/dark theme and accent/colorization colors:
bool IsSystemThemeDark(){
#ifdef WIN32
HKEY SWKey;
HKEY MSKey;
HKEY WINKey;
HKEY CVKey;
HKEY ThemesKey;
HKEY PersonalizeKey;
LONG Status;
bool darkTheme=false;
Status = RegOpenKeyEx(HKEY_CURRENT_USER,TEXT("Software"),0,KEY_READ,&SWKey);
if(Status == ERROR_SUCCESS){
Status = RegOpenKeyEx(SWKey,TEXT("Microsoft"),0,KEY_READ,&MSKey);
if(Status == ERROR_SUCCESS){
Status = RegOpenKeyEx(MSKey,TEXT("Windows"),0,KEY_READ,&WINKey);
if(Status == ERROR_SUCCESS){
Status = RegOpenKeyEx(WINKey,TEXT("CurrentVersion"),0,KEY_READ,&CVKey);
if(Status == ERROR_SUCCESS){
Status = RegOpenKeyEx(CVKey,TEXT("Themes"),0,KEY_READ,&ThemesKey);
if(Status == ERROR_SUCCESS){
Status = RegOpenKeyEx(ThemesKey,TEXT("Personalize"),0,KEY_READ,&PersonalizeKey);
if(Status == ERROR_SUCCESS){
DWORD RegType;
DWORD BufferSize=16;
char pStr[16];
Status=RegQueryValueEx(PersonalizeKey,TEXT("AppsUseLightTheme"),NULL,&RegType,(LPBYTE)pStr,&BufferSize);
if(Status == ERROR_SUCCESS) if((*(DWORD*)pStr)==0) darkTheme=true;
RegCloseKey(PersonalizeKey);
}
RegCloseKey(ThemesKey);
}
RegCloseKey(CVKey);
}
RegCloseKey(WINKey);
}
RegCloseKey(MSKey);
}
RegCloseKey(SWKey);
}
if(Status == ERROR_SUCCESS) return darkTheme;
#endif
// Generic solution for GTK and older Windows
Color paper=SColorPaper();
if(paper.GetR()<128 && paper.GetG()<128 && paper.GetB()<128) return true; // Dark background
return false;
}
RGBA GetSystemColorizationColor(){
RGBA color=Gray(); // Default
#ifdef WIN32
HKEY SWKey;
HKEY MSKey;
HKEY WINKey;
HKEY DWMKey;
LONG Status;
// "Computer\HKEY_CURRENT_USER\Software\Microsoft\Windows\DWM"
Status = RegOpenKeyEx(HKEY_CURRENT_USER,TEXT("Software"),0,KEY_READ,&SWKey);
if(Status == ERROR_SUCCESS){
Status = RegOpenKeyEx(SWKey,TEXT("Microsoft"),0,KEY_READ,&MSKey);
if(Status == ERROR_SUCCESS){
Status = RegOpenKeyEx(MSKey,TEXT("Windows"),0,KEY_READ,&WINKey);
if(Status == ERROR_SUCCESS){
Status = RegOpenKeyEx(WINKey,TEXT("DWM"),0,KEY_READ,&DWMKey);
if(Status == ERROR_SUCCESS){
DWORD RegType;
DWORD BufferSize=16;
char pStr[16];
Status=RegQueryValueEx(DWMKey,TEXT("ColorizationColor"),NULL,&RegType,(LPBYTE)pStr,&BufferSize);
if(Status == ERROR_SUCCESS) color=(*(RGBA*)pStr);
RegCloseKey(DWMKey);
}
RegCloseKey(WINKey);
}
RegCloseKey(MSKey);
}
RegCloseKey(SWKey);
}
if(Status == ERROR_SUCCESS) return color; // Success
#endif
// TODO solve other sources
return color; // Default
}
RGBA GetSystemAccentColor(){
RGBA color=Gray(); // Default
#ifdef WIN32
HKEY SWKey;
HKEY MSKey;
HKEY WINKey;
HKEY DWMKey;
LONG Status;
// "Computer\HKEY_CURRENT_USER\Software\Microsoft\Windows\DWM"
Status = RegOpenKeyEx(HKEY_CURRENT_USER,TEXT("Software"),0,KEY_READ,&SWKey);
if(Status == ERROR_SUCCESS){
Status = RegOpenKeyEx(SWKey,TEXT("Microsoft"),0,KEY_READ,&MSKey);
if(Status == ERROR_SUCCESS){
Status = RegOpenKeyEx(MSKey,TEXT("Windows"),0,KEY_READ,&WINKey);
if(Status == ERROR_SUCCESS){
Status = RegOpenKeyEx(WINKey,TEXT("DWM"),0,KEY_READ,&DWMKey);
if(Status == ERROR_SUCCESS){
DWORD RegType;
DWORD BufferSize=16;
char pStr[16];
Status=RegQueryValueEx(DWMKey,TEXT("AccentColor"),NULL,&RegType,(LPBYTE)pStr,&BufferSize);
if(Status == ERROR_SUCCESS) color=(*(RGBA*)pStr);
RegCloseKey(DWMKey);
}
RegCloseKey(WINKey);
}
RegCloseKey(MSKey);
}
RegCloseKey(SWKey);
}
if(Status == ERROR_SUCCESS) return color; // Success
#endif
// TODO solve other sources
return color; // Default
}
At least this works on relatively current Windows 10, but I do not know how to make U++ tune its colors along these colors, so I'll just drop this here.
Best regards,
Tom
[Updated on: Tue, 12 February 2019 12:45] Report message to a moderator
|
|
|
 |
|
DarkTheme support
By: Tom1 on Fri, 08 February 2019 16:17
|
 |
|
Re: Please check the list of 2019.1 changes
By: mirek on Mon, 11 February 2019 11:52
|
 |
|
Re: Please check the list of 2019.1 changes
By: Tom1 on Mon, 11 February 2019 16:19
|
 |
|
Re: Please check the list of 2019.1 changes
By: Tom1 on Mon, 11 February 2019 21:03
|
 |
|
Re: Please check the list of 2019.1 changes
By: Tom1 on Tue, 12 February 2019 09:30
|
 |
|
Re: Please check the list of 2019.1 changes
By: Tom1 on Tue, 12 February 2019 12:44
|
 |
|
Re: Please check the list of 2019.1 changes
By: mirek on Tue, 12 February 2019 13:01
|
 |
|
Re: Please check the list of 2019.1 changes
By: Tom1 on Tue, 12 February 2019 13:50
|
 |
|
Re: Please check the list of 2019.1 changes
By: mirek on Tue, 12 February 2019 14:02
|
 |
|
Re: Please check the list of 2019.1 changes
By: mirek on Tue, 12 February 2019 14:15
|
 |
|
Re: Please check the list of 2019.1 changes
By: Tom1 on Tue, 12 February 2019 15:26
|
 |
|
Re: Please check the list of 2019.1 changes
By: mirek on Thu, 21 February 2019 09:52
|
 |
|
Re: Please check the list of 2019.1 changes
By: Tom1 on Tue, 12 February 2019 15:02
|
 |
|
Re: Please check the list of 2019.1 changes
By: mirek on Wed, 13 February 2019 09:38
|
 |
|
Re: Please check the list of 2019.1 changes
By: Tom1 on Wed, 13 February 2019 10:30
|
 |
|
Re: Please check the list of 2019.1 changes
By: mirek on Tue, 19 February 2019 12:10
|
 |
|
Re: Please check the list of 2019.1 changes
By: Tom1 on Tue, 19 February 2019 13:30
|
 |
|
Re: Please check the list of 2019.1 changes
By: mirek on Thu, 21 February 2019 09:53
|
 |
|
Re: Please check the list of 2019.1 changes
By: Tom1 on Fri, 22 February 2019 08:40
|
 |
|
Re: Please check the list of 2019.1 changes
By: mirek on Fri, 22 February 2019 19:04
|
 |
|
Re: Please check the list of 2019.1 changes
By: Tom1 on Thu, 07 March 2019 14:51
|
 |
|
Re: Please check the list of 2019.1 changes
By: mirek on Wed, 13 March 2019 00:16
|
 |
|
Re: Please check the list of 2019.1 changes
By: Tom1 on Wed, 13 March 2019 12:15
|
 |
|
Re: Please check the list of 2019.1 changes
By: Klugier on Sun, 17 March 2019 02:05
|
 |
|
Re: Please check the list of 2019.1 changes
By: mirek on Sun, 17 March 2019 10:15
|
 |
|
Re: Please check the list of 2019.1 changes
By: Klugier on Sun, 17 March 2019 11:54
|
 |
|
Re: Please check the list of 2019.1 changes
By: mirek on Sat, 23 March 2019 23:31
|
 |
|
Re: Please check the list of 2019.1 changes
By: mirek on Sun, 24 March 2019 09:53
|
 |
|
Re: Please check the list of 2019.1 changes
By: mirek on Sun, 24 March 2019 23:10
|
 |
|
Re: Please check the list of 2019.1 changes
By: Tom1 on Mon, 25 March 2019 11:45
|
 |
|
Re: Please check the list of 2019.1 changes
By: Tom1 on Mon, 25 March 2019 11:51
|
 |
|
Re: Please check the list of 2019.1 changes
By: mirek on Mon, 25 March 2019 12:29
|
 |
|
Re: Please check the list of 2019.1 changes
By: Tom1 on Mon, 25 March 2019 14:02
|
 |
|
Re: Please check the list of 2019.1 changes
By: Tom1 on Fri, 29 March 2019 09:30
|
 |
|
Re: Please check the list of 2019.1 changes
By: mirek on Fri, 29 March 2019 10:54
|
 |
|
Re: Please check the list of 2019.1 changes
By: Tom1 on Fri, 29 March 2019 16:31
|
 |
|
Re: Please check the list of 2019.1 changes
By: mirek on Sat, 30 March 2019 10:22
|
 |
|
Re: Please check the list of 2019.1 changes
By: Tom1 on Sat, 30 March 2019 12:50
|
Goto Forum:
Current Time: Wed May 14 02:24:00 CEST 2025
Total time taken to generate the page: 0.00487 seconds
|