Page 1 of 1
Simple code to change the monitor frequency
Posted: Fri Jul 01, 2022 10:47 am
by Simo_na
Hello
exists a simple code to change the monitor frequency to 120 Hz to 60 Hz or inverse ?
Re: Simple code to change the monitor frequency
Posted: Fri Jul 01, 2022 10:58 am
by BarryG
For Windows, start reading here (and the posts after it) ->
https://www.purebasic.fr/english/viewto ... 54#p159754
Re: Simple code to change the monitor frequency
Posted: Fri Jul 01, 2022 11:04 am
by Mijikai
On Windows u can give this a try (untested):
Code: Select all
Procedure.i SetMonitorFrequency(Value.i)
Protected dv.DEVMODE
Protected state.i
dv\dmDisplayFrequency = Value
dv\dmFields = #DM_DISPLAYFREQUENCY
dv\dmSize = SizeOf(DEVMODE)
state = ChangeDisplaySettings_(@dv,#Null)
If state = #DISP_CHANGE_SUCCESSFUL
ProcedureReturn 1
ElseIf state = #DISP_CHANGE_RESTART;changed after restart!
ProcedureReturn 2
EndIf
ProcedureReturn #Null
EndProcedure
Imho. changing the Frequency of the Montor is not a good idea.
According to some posts it could even damaged the Monitor!
About the API:
https://docs.microsoft.com/en-us/window ... ysettingsa
Just noticed that BarryG already answered

Re: Simple code to change the monitor frequency
Posted: Fri Jul 01, 2022 11:31 am
by Simo_na
Mijikai wrote: Fri Jul 01, 2022 11:04 am
According to some posts it could even damaged the Monitor!
Thank you
now just find the (enumerate) table of frequencies supported by the monitor

Re: Simple code to change the monitor frequency
Posted: Fri Jul 01, 2022 11:56 am
by Simo_na
a very primitive and brutal way....but it is still a beginning..
Code: Select all
; www.purearea.net (Sourcecode collection by cnesm)
; Author: Andreas
; Date: 22. November 2003
;#############################
;Author : Andreas
;16.06.2003
;#############################
;--- Modified by Simo
NewList Display.DEVMODE()
EnumDisplaySettings_(0,x,dev.DEVMODE)
Debug dev\dmDisplayFrequency
End
Re: Simple code to change the monitor frequency
Posted: Fri Jul 01, 2022 2:19 pm
by Simo_na
Code: Select all
;/ Initialize PureBasic desktop library
ExamineDesktops()
;/ Iterate through supported display settings and display only select criteria
While EnumDisplaySettings_(0,i,@DevMode.DEVMODE)
If DesktopWidth(0)*1.0/DesktopHeight(0)=DevMode\dmPelsWidth*1.0/DevMode\dmPelsHeight
Debug Str(DevMode\dmPelsWidth)+" "+Str(DevMode\dmPelsHeight)+" "+Str(DevMode\dmDisplayFrequency)
EndIf
i+1
Wend
a decent approach now
but
can't figure out how to locate a second monitor, DesktopWidth(0) or DesktopWidth(1) doesn't change anything...
Re: Simple code to change the monitor frequency
Posted: Sat Jul 02, 2022 1:33 pm
by Mijikai
You forgot to select the actual Desktop/Device - change:
Code: Select all
DesktopWidth(0) -> DesktopWidth(i)
If you want to use API select the Desktop/Device with:
And change the Frequency with:
Re: Simple code to change the monitor frequency
Posted: Sun Jul 10, 2022 12:03 pm
by Simo_na
Thank you