How to modify display refresh rate programmatically using Windows API

I’m working on a project where I need to adjust the monitor’s refresh rate through code. I’ve been searching for the right Windows API functions but I’m not sure which ones to use.

Basically, I want to create a program that can detect the current refresh rate and then change it to a different value like switching from 60Hz to 144Hz or vice versa. I know this should be possible since display settings can do this manually, but I need to do it programmatically.

Could anyone point me to the specific Windows API calls that handle display refresh rate modifications? Any code examples or documentation references would be really helpful. Thanks in advance!

I ran into this exact problem two years ago building a gaming utility. You want ChangeDisplaySettings() and EnumDisplaySettings(). First, use EnumDisplaySettings() to check what refresh rates your monitor actually supports at your resolution. Then call ChangeDisplaySettings() with a modified DEVMODE structure. Set dmDisplayFrequency to your target refresh rate and make sure dmFields includes DM_DISPLAYFREQUENCY. Here’s the gotcha - some monitors report weird values like 59Hz instead of 60Hz, so always enumerate first to see what’s really available. You might need admin privileges depending on your system.

Try the newer Display Configuration API instead - SetDisplayConfig() and QueryDisplayConfig(). They’re way more reliable than the old ChangeDisplaySettings() method, especially with multi-monitor setups. You’ll work with DISPLAYCONFIG_PATH_INFO and DISPLAYCONFIG_MODE_INFO structures. Just query the current config, tweak the refresh rate in the mode info, then apply it back. I’ve found this handles edge cases much better - different display adapters, multiple refresh rates, all that stuff. Yeah, it’s more complex, but you get way finer control over display properties.

both methods r cool, but honestly, ChangeDisplaySettings() is easier for what u need. just keep an eye on the return value to see if it worked or needs a restart. also, some games like to mess with your refresh rate when they launch, so be careful.