Changing colours of every element Topic is solved
Changing colours of every element
I would like to change colour of "every" displayed element in our application, the desired appearance is to have something like dark mode. I do not know whether it is even feasible to do for one person, I have been working with wxWidgets for only one year.
I know about SetForegroundColour(), SetBackgroundColour() functions called on a wxWindow or its descendant, but they do not even closely solve the problem. I have not found any other function or tool in the documentation which would have colours under control.
Attached is a screenshot from our application with arrows pointing to elements, for which I would like to have possibility of changing colour. If an element can have more states (e.g. button can be enabled or disabled), I would like to control its colours for both states.
Would there be any way for example through "hacking" source code of the wxWidgets library, where I could tell "hey wxWidgets here for this wxWindow subclass use my colours not default system ones". I have tried to replace calls to GetSysColor() function (provided by Windows) in the library, but that affected only about 5% of displayed colours.
System: Windows 10
Compiling under: MinGW (g++)
Thanks in advance!
I know about SetForegroundColour(), SetBackgroundColour() functions called on a wxWindow or its descendant, but they do not even closely solve the problem. I have not found any other function or tool in the documentation which would have colours under control.
Attached is a screenshot from our application with arrows pointing to elements, for which I would like to have possibility of changing colour. If an element can have more states (e.g. button can be enabled or disabled), I would like to control its colours for both states.
Would there be any way for example through "hacking" source code of the wxWidgets library, where I could tell "hey wxWidgets here for this wxWindow subclass use my colours not default system ones". I have tried to replace calls to GetSysColor() function (provided by Windows) in the library, but that affected only about 5% of displayed colours.
System: Windows 10
Compiling under: MinGW (g++)
Thanks in advance!
- T-Rex
- Moderator
- Posts: 1249
- Joined: Sat Oct 23, 2004 9:58 am
- Location: Zaporizhzhya, Ukraine
- Contact:
Re: Changing colours of every element
That functionality is not wxWidgets-related but mostly OS-related.
You can try to use WinAPI for this.
https://stackoverflow.com/questions/215 ... enu-colors
https://forums.codeguru.com/showthread. ... a-edit-box
Also there were several solutions related to this at CodeProject
https://www.codeproject.com/Articles/13 ... Applicatio
You can try to use WinAPI for this.
https://stackoverflow.com/questions/215 ... enu-colors
https://forums.codeguru.com/showthread. ... a-edit-box
Also there were several solutions related to this at CodeProject
https://www.codeproject.com/Articles/13 ... Applicatio
Re: Changing colours of every element
There is no good solution for this yet, as Windows doesn't officially support dark mode for Win32 applications.
Check this earlier discussion:
https://groups.google.com/g/wx-users/c/2V-UlBfmCSw
https://github.com/prusa3d/PrusaSlicer/ ... -821064152
Check this earlier discussion:
https://groups.google.com/g/wx-users/c/2V-UlBfmCSw
https://github.com/prusa3d/PrusaSlicer/ ... -821064152
Use the source, Luke!
Re: Changing colours of every element
Thank you both for replies.
@T-Rex
So you suggest not to use wxWidgets at all and use WinAPI exclusivelly?
Or do you mean/think there is a way I could hijack wxWidgets library source code on certain places and dictate to WinAPi (which is AFAIK used in the background for displaying GUI elements by wxWidgets) my own colours to use for wxWindows? I had this idea, because I guess there must be something like this (to tell WinAPI to use custom colours for its elements in wxWidgets source code) - e.g. when you call SetForegroundColour() on wxButton it changes the default colour to whatever different one.
@T-Rex
So you suggest not to use wxWidgets at all and use WinAPI exclusivelly?
Or do you mean/think there is a way I could hijack wxWidgets library source code on certain places and dictate to WinAPi (which is AFAIK used in the background for displaying GUI elements by wxWidgets) my own colours to use for wxWindows? I had this idea, because I guess there must be something like this (to tell WinAPI to use custom colours for its elements in wxWidgets source code) - e.g. when you call SetForegroundColour() on wxButton it changes the default colour to whatever different one.
Re: Changing colours of every element
Hi,
First of all - are you using Windows exclusively? No other ports?
Will your software ever run on *nix/OSX?
Thank you.
First of all - are you using Windows exclusively? No other ports?
Will your software ever run on *nix/OSX?
Thank you.
Re: Changing colours of every element
Hi,
Then you can try to use the code suggested by T-Rex..
You should also wrap it with "#ifdef __WXMSW__" in case someone will want the implementation to be cross-platform.
One more question - is it for the dark mode implementation? Because if not - you will need to redo you palette. Also make sure that different themes will handle your colors correctly.
Thank you.
Then you can try to use the code suggested by T-Rex..
You should also wrap it with "#ifdef __WXMSW__" in case someone will want the implementation to be cross-platform.
One more question - is it for the dark mode implementation? Because if not - you will need to redo you palette. Also make sure that different themes will handle your colors correctly.
Thank you.
Re: Changing colours of every element
I believe it may be impossible to do for all elements.
IIRC, the scrollbars of a window (not the child controls) are basically impossible to change, I think there also may be an issue with some parts of notebooks.
And there are also system dialogs which should match the theme of your app, such as file/dir dialogs, printer settings etc. I would for example check the latest version of Notepad++, which is an open source Win32 application using ts own "dark mode" (in addition to wxWidgets-using Prusa Slicer referenced above). Please notice that some controls (and system dialogs) in "dark mode" are colored by the OS, and not by the application.
It is not a simple task, I would (a) think twice if I really needed it and (b) if Win32 API (wrapped by wxWidgets or pure) is the way to go. It also may note be possible without modifying wxWidgets sources which makes the issue much worse..
IIRC, the scrollbars of a window (not the child controls) are basically impossible to change, I think there also may be an issue with some parts of notebooks.
And there are also system dialogs which should match the theme of your app, such as file/dir dialogs, printer settings etc. I would for example check the latest version of Notepad++, which is an open source Win32 application using ts own "dark mode" (in addition to wxWidgets-using Prusa Slicer referenced above). Please notice that some controls (and system dialogs) in "dark mode" are colored by the OS, and not by the application.
It is not a simple task, I would (a) think twice if I really needed it and (b) if Win32 API (wrapped by wxWidgets or pure) is the way to go. It also may note be possible without modifying wxWidgets sources which makes the issue much worse..
- T-Rex
- Moderator
- Posts: 1249
- Joined: Sat Oct 23, 2004 9:58 am
- Location: Zaporizhzhya, Ukraine
- Contact:
Re: Changing colours of every element
Most likely you will not be able to do this in wxWidgets way. You will need, as suggested in previous posts, to have #ifdef for every platform and implement this behavior in a platform-specific way using native APIs. wxWidgets does not wrap the entire OS-related APIs, only those that can be used in a common way on multiple platforms. Some functionality can be achieved only with native APIs.
As an option, you can dig the code of the proposed solutions, find related API calls, dig the source code of wxWidgets and try to find the occurrences of these API calls (or constants or macros) and then try to use them in a similar way.
Re: Changing colours of every element
Thank you for your reply. Our application is used solely under Windows, with no plans to extend support for other OSs. In case you (or anyone else) have any idea where and how to start I'd be grateful, I have close to zero experience with WinAPI and have a feeling that using it is much less user friendly than using wxWidgets API.T-Rex wrote: ↑Mon Oct 18, 2021 12:43 pmMost likely you will not be able to do this in wxWidgets way. You will need, as suggested in previous posts, to have #ifdef for every platform and implement this behavior in a platform-specific way using native APIs. wxWidgets does not wrap the entire OS-related APIs, only those that can be used in a common way on multiple platforms. Some functionality can be achieved only with native APIs.
As an option, you can dig the code of the proposed solutions, find related API calls, dig the source code of wxWidgets and try to find the occurrences of these API calls (or constants or macros) and then try to use them in a similar way.
Re: Changing colours of every element
Hi,
Let me ask you again - is this to handle the "dark mode" on Windows?
Thank you.
Let me ask you again - is this to handle the "dark mode" on Windows?
Thank you.
Re: Changing colours of every element
Our client wants to have colour scheme of the application similar to other programs they use, and their "other programs" have dark colour scheme. So "dark mode" in Windows would most probably be a solution but any other way which could make our application have dark look would be acceptable.
- T-Rex
- Moderator
- Posts: 1249
- Joined: Sat Oct 23, 2004 9:58 am
- Location: Zaporizhzhya, Ukraine
- Contact:
Re: Changing colours of every element
There are some unofficial solutions.