none
Get system colours information GetSysColor RRS feed

  • Question

  • Firstly, my issue that I am having is my company is moving to windows 10 and we have our legacy MFC application which is written in C++ on Visual Studio. It is used primarily in vehicles and has a day/night mode.  When the user switches to "Night" mode theme, we make a call to SetSysColors() to change the colours of various Window elements (titlebar, background, menubar, etc), so that the colours are easier on the eyes in low-light conditions.  In Windows 10, this no longer works like it used to.  SetSysColors will change colours of some of the elements, but not all of them.  The titlebar and menubar background, for example, are not affected.  Did something change along the way that causes these elements to not change color?  If so, how is the easiest and/or best way to programmatically change these elements for all open windows?  We do not need to restrict the color changes to just our application...we need to adjust the colours system-wide. 

     

    I am trying to create a basic visual c++ windows desktop application which will Retrieves the current color of the specified display element. Display elements are the parts of a window and the display that appear on the system display screen using the GetSysColor function.

     

    And then I want to be able to use the SetSysColor to Set the colors for the specified display elements. Display elements are the various parts of a window and the display that appear on the system display screen.

     

    It is has to very basic application as I want to test this function out on windows 7 then on Windows 10 as part of my main project that I am working on.

     

    I used the example https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-setsyscolors shown in this link, when I built the application and ran it, there was no change being shown at all.

     

    Please help me figure out what I need to do or am doing wrong currently. I want to be able to detect the current system colours. Also please can you share me your code for what you may try so I can look at it.

     

    Also I have another issue which is that a white rectangle on showing a window.  When I run my test application to build, it flashes a white coloured rectangle the size of my application window before it loads the application. This happens in all modes and on all operating systems which means it is a generic issue that is being caused. I have been facing this issue on all different modes such as high contrast mode, dark mode etc. If you would like a screenprint of the issue I will be able to provide that too.

    Tuesday, September 3, 2019 3:50 PM

All replies

  • Hello,

    Thank you for posting here.

    >>I used the example https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-setsyscolors shown in this link, when I built the application and ran it, there was no change being shown at all.

    According to your description, we reproduce your error. After several tests, we think this is an issue. Please submit your question on Developer Community. Here is the link:

    https://developercommunity.visualstudio.com/spaces/8/index.html

    >>If you would like a screenprint of the issue I will be able to provide that too.

    Can you provide the code and screenshots? We can't guess the cause of the error according to your description.

    Best Regards,

    Suarez Zhou

    Wednesday, September 4, 2019 6:05 AM
  • Also I have another issue which is that a white rectangle on showing a window. 

    Hello,

    this is another question. Open a second question that deals with this topic.

    Regards, Guido

    Wednesday, September 4, 2019 6:15 AM
  • Duplicate question. To your first original question, which you asked here already: https://social.msdn.microsoft.com/Forums/en-US/fe7b52ee-102c-469d-97c3-32b203b2d645/need-a-simple-application-which-displays-the-current-system-colours?forum=vcgeneral

    I gave you a link of a test programme how to color controls in a dialog. You can use it. Instead of defining the color in the source, use GetSysColor.

    If you need the color of a pixel on the screen (your "Display element": Display elements are the various parts of a window and the display that appear on the system display screen.), then have a look at this example: https://stackoverflow.com/questions/4839623/getting-pixel-color-in-c

    Regards, Guido

    Wednesday, September 4, 2019 6:19 AM
  • You use Get/SetSysColor on Windows 10, but not all colors of the applications are changed. This could be because of the Windows 10 Theme selected.

    Maybe, instead of using SetSysColor, you could add a new "night" theme to Windows 10 and toggle between the user theme and your new "night" theme. Have a look at this: https://social.msdn.microsoft.com/Forums/sqlserver/en-US/f05b7f43-1a01-4e89-aa46-728e760ea0b7/how-to-add-skintheme-to-vc-mfc-application?forum=vcgeneral

    Regards, Guido

    Wednesday, September 4, 2019 6:23 AM
  • As has been pointed out in various other threads that you have started on this subject GetSysColor/SetSysColors have a system-wide effect and so influence applications other than your own.  For that reason they are probably not the best solution to your problem.

    I don't use Windows 10 but have tested a simple dialog-based application on Windows 7 and Windows 8.1 and found that if themed drawing is disabled for your application then you can fully see the effect of the above functions.

    For example, on Windows 8.1 the dialog-based application ordinarily looks like this -

    After disabling themed drawing, the application looks like this BEFORE changing any colors for user interface elements -

    And after changing user interface element colors -

    In order to achieve the above effect, the following snippet of code uses SetThemeAppProperties and DwmSetWindowAttribute to disable themed drawing as follows during application startup -

    MSG msg;
    
    SetThemeAppProperties(GetThemeAppProperties() & ~(STAP_ALLOW_CONTROLS | STAP_ALLOW_NONCLIENT));
    
    m_hWnd = CreateDialogParam(m_hInst, MAKEINTRESOURCE(IDD_Win32DlgColors), NULL, s_DlgProc, reinterpret_cast<LPARAM>(this));
    
    if (!m_hWnd)
    	return -1;
    
    DWMNCRENDERINGPOLICY ncrp = DWMNCRP_DISABLED;
    
    HRESULT hr = DwmSetWindowAttribute(m_hWnd, DWMWA_NCRENDERING_POLICY, &ncrp, sizeof ncrp);
    
    ShowWindow(m_hWnd, nCmdShow);
    
    while (GetMessage(&msg, nullptr, 0, 0))
    {
    	if (!IsDialogMessage(m_hWnd, &msg))
    	{
    		TranslateMessage(&msg);
    		DispatchMessage(&msg);
    	}
    }
    

    Wednesday, September 4, 2019 10:28 AM
  • Can I please have this application you have made?
    Wednesday, September 4, 2019 1:05 PM
  • Can I please have this application you have made?

    The sample that I demonstrated only changes all of its own ui element colors.  Other applications that are running will not demonstrate the same result as they will continue to use themed drawing.

    Other than calling SetThemeAppProperties and DwmSetWindowAttribute as shown above it just calls GetSysColor to retrieve the system default colors and SetSysColors to change them or restore the system defaults.  The rest is scaffolding.  You should be able to write your own test program using the information provided.

    Wednesday, September 4, 2019 1:42 PM