Changing colours of every element Topic is solved

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
cervenyk
In need of some credit
In need of some credit
Posts: 5
Joined: Mon Jun 21, 2021 11:16 am

Changing colours of every element

Post by cervenyk »

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!
Attachments
Screenshot from our application
Screenshot from our application
User avatar
T-Rex
Moderator
Moderator
Posts: 1249
Joined: Sat Oct 23, 2004 9:58 am
Location: Zaporizhzhya, Ukraine
Contact:

Re: Changing colours of every element

Post by T-Rex »

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
User avatar
doublemax
Moderator
Moderator
Posts: 19160
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: Changing colours of every element

Post by doublemax »

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
Use the source, Luke!
cervenyk
In need of some credit
In need of some credit
Posts: 5
Joined: Mon Jun 21, 2021 11:16 am

Re: Changing colours of every element

Post by cervenyk »

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.
ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 7477
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: Changing colours of every element

Post by ONEEYEMAN »

Hi,
First of all - are you using Windows exclusively? No other ports?
Will your software ever run on *nix/OSX?

Thank you.
cervenyk
In need of some credit
In need of some credit
Posts: 5
Joined: Mon Jun 21, 2021 11:16 am

Re: Changing colours of every element

Post by cervenyk »

ONEEYEMAN wrote: Mon Oct 18, 2021 11:54 am Hi,
First of all - are you using Windows exclusively? No other ports?
Will your software ever run on *nix/OSX?

Thank you.
Yes, no ports.
ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 7477
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: Changing colours of every element

Post by ONEEYEMAN »

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.
PB
Part Of The Furniture
Part Of The Furniture
Posts: 4204
Joined: Sun Jan 03, 2010 5:45 pm

Re: Changing colours of every element

Post by PB »

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..
User avatar
T-Rex
Moderator
Moderator
Posts: 1249
Joined: Sat Oct 23, 2004 9:58 am
Location: Zaporizhzhya, Ukraine
Contact:

Re: Changing colours of every element

Post by T-Rex »

cervenyk wrote: Mon Oct 18, 2021 10:52 am Thank you both for replies.

@T-Rex
So you suggest not to use wxWidgets at all and use WinAPI exclusivelly?
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.
cervenyk
In need of some credit
In need of some credit
Posts: 5
Joined: Mon Jun 21, 2021 11:16 am

Re: Changing colours of every element

Post by cervenyk »

T-Rex wrote: Mon Oct 18, 2021 12:43 pm
cervenyk wrote: Mon Oct 18, 2021 10:52 am Thank you both for replies.

@T-Rex
So you suggest not to use wxWidgets at all and use WinAPI exclusivelly?
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.
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.
ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 7477
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: Changing colours of every element

Post by ONEEYEMAN »

Hi,
Let me ask you again - is this to handle the "dark mode" on Windows?

Thank you.
cervenyk
In need of some credit
In need of some credit
Posts: 5
Joined: Mon Jun 21, 2021 11:16 am

Re: Changing colours of every element

Post by cervenyk »

ONEEYEMAN wrote: Tue Oct 19, 2021 2:33 pm Hi,
Let me ask you again - is this to handle the "dark mode" on Windows?

Thank you.
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.
User avatar
T-Rex
Moderator
Moderator
Posts: 1249
Joined: Sat Oct 23, 2004 9:58 am
Location: Zaporizhzhya, Ukraine
Contact:

Re: Changing colours of every element

Post by T-Rex »

ONEEYEMAN wrote: Tue Oct 19, 2021 2:33 pm Hi,
Let me ask you again - is this to handle the "dark mode" on Windows?

Thank you.
There are some unofficial solutions.
Post Reply