c++cwindows-10high-contrast

Enable High Contrast Mode in C/C++


I'm trying to make a .exe file in Visual that enables High Contrast Mode. I read

https://learn.microsoft.com/en-us/windows/desktop/api/winuser/nf-winuser-systemparametersinfoa and

https://learn.microsoft.com/en-us/windows/desktop/api/winuser/ns-winuser-taghighcontrasta

up and down but I can't find a complete answer. What goes in the uiParam and pvParam? Please tell me where you found the answer!

SystemParametersInfo(SPI_SETHIGHCONTRAST, , , SPIF_SENDCHANGE)


Solution

  • uiParam

    Type: UINT

    A parameter whose usage and format depends on the system parameter being queried or set. For more information about system-wide parameters, see the uiAction parameter. If not otherwise indicated, you must specify zero for this parameter.

    You'll use 0 for this.

    pvParam

    Type: PVOID

    Sets the parameters of the HighContrast accessibility feature. The pvParam parameter must point to a HIGHCONTRAST structure that contains the new parameters.

    You'll need a HIGHCONTRAST structure for this parameter, with the data you'd like to pass.

    That means you'll do:

    HIGHCONTRAST hc;
    ZeroMemory(&hc, sizeof(HIGHCONTRAST));
    hc.cbSize = sizeof(HIGHCONTRAST);
    hc.dwFlags = HCF_HIGHCONTRASTON;
    SystemParametersInfo(SPI_SETHIGHCONTRAST, 0, &hc, SPIF_SENDCHANGE);
    

    As a side note, you likely want to return the Windows environment back to the same state that it was in when your application started.

    You should call SystemParametersInfo with SPI_GETHIGHCONTRAST before you change it, store away that HIGHCONTRAST struct for later, then restore the system to that HIGHCONTRAST struct when your application exits.