- 1 year ago
Change Ease of Access Settings via Windows API: SystemParametersInfo
Yes, you can use the SystemParametersInfo
function from the Windows API to change Ease of Access settings programmatically in a Windows application. The SystemParametersInfo
function allows you to modify various system-wide parameters, including accessibility-related settings.
Here's an example of how you can use SystemParametersInfo
to change the high contrast setting:
c++#include <Windows.h>
// Function to toggle high contrast
void ToggleHighContrast(bool enable)
{
// Specify the SPI_SETSCREENHIGHCONTRAST flag to modify the high contrast setting
UINT uiAction = enable ? SPI_SETSCREENHIGHCONTRAST : SPI_SETHIGHCONTRAST;
// Prepare the HIGHCONTRAST structure
HIGHCONTRAST hc;
hc.cbSize = sizeof(HIGHCONTRAST);
hc.dwFlags = HCF_HIGHCONTRASTON;
hc.lpszDefaultScheme = nullptr;
// Call SystemParametersInfo to change the high contrast setting
SystemParametersInfo(uiAction, sizeof(HIGHCONTRAST), &hc, SPIF_SENDCHANGE);
}
int main()
{
// Enable high contrast
ToggleHighContrast(true);
// Disable high contrast
ToggleHighContrast(false);
return 0;
}
In this example, the ToggleHighContrast
function takes a boolean parameter enable
to specify whether to enable or disable high contrast. It prepares a HIGHCONTRAST
structure and calls SystemParametersInfo
with the appropriate flags to modify the high contrast setting. The SPIF_SENDCHANGE
flag is used to broadcast a system-wide setting change notification.
Note that there are various other accessibility-related settings that can be modified using SystemParametersInfo
, such as keyboard settings, mouse settings, visual effects, etc. You can refer to the Windows API documentation for more details on the available parameters and flags.
Ensure that you have the necessary permissions to modify system parameters, and be mindful of the impact that changing these settings programmatically may have on the user experience.