What is the window API for changing the screen refresh rate?

Can I specify the windows API that I need to use in order to programmatically change the screen refresh rate?

+3
source share
2 answers

you can use ChangeDisplaySettings as described above. But you should use EnumDisplaySettings to get a list of valid combinations (color decode, width, height, mode and frequency).

Code example (in Delphi, but translation should be trivial)

Get Valid Display Modes

i := 0;
while EnumDisplaySettings(nil, i, dm) do begin
  Memo1.Lines.Add(Format('Color Depth: %d', [dm.dmBitsPerPel]));
  Memo1.Lines.Add(Format('Resolution: %d, %d', [dm.dmPelsWidth, dm.dmPelsHeight]));
  Memo1.Lines.Add(Format('Display mode: %d', [dm.dmDisplayFlags]));
  Memo1.Lines.Add(Format('Frequency: %d', [dm.dmDisplayFrequency]));
  Inc(i);
end;

Set display mode

// In this case i is an index in the list of valid display modes.
if EnumDisplaySettings(nil, i, dm) then begin
  // Sanity check!
  if ChangeDisplaySettings(dm, CDS_TEST) = 0) then
    ChangeDisplaySettings(dm, 0);  // Use CDS_UPDATEREGISTRY if this is the new default mode.
end;

!

+4

Source: https://habr.com/ru/post/1697631/


All Articles