Simple code to change the monitor frequency

Just starting out? Need help? Post your questions and find answers here.
Simo_na
Enthusiast
Enthusiast
Posts: 177
Joined: Sun Mar 03, 2013 9:01 am

Simple code to change the monitor frequency

Post by Simo_na »

Hello
exists a simple code to change the monitor frequency to 120 Hz to 60 Hz or inverse ?
BarryG
Addict
Addict
Posts: 3292
Joined: Thu Apr 18, 2019 8:17 am

Re: Simple code to change the monitor frequency

Post by BarryG »

For Windows, start reading here (and the posts after it) -> https://www.purebasic.fr/english/viewto ... 54#p159754
User avatar
Mijikai
Addict
Addict
Posts: 1360
Joined: Sun Sep 11, 2016 2:17 pm

Re: Simple code to change the monitor frequency

Post 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 :D
Simo_na
Enthusiast
Enthusiast
Posts: 177
Joined: Sun Mar 03, 2013 9:01 am

Re: Simple code to change the monitor frequency

Post 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 :)
Simo_na
Enthusiast
Enthusiast
Posts: 177
Joined: Sun Mar 03, 2013 9:01 am

Re: Simple code to change the monitor frequency

Post 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 

Simo_na
Enthusiast
Enthusiast
Posts: 177
Joined: Sun Mar 03, 2013 9:01 am

Re: Simple code to change the monitor frequency

Post 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...
User avatar
Mijikai
Addict
Addict
Posts: 1360
Joined: Sun Sep 11, 2016 2:17 pm

Re: Simple code to change the monitor frequency

Post 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:

Code: Select all

EnumDisplayDevices_()
And change the Frequency with:

Code: Select all

ChangeDisplaySettingsEx_()
Simo_na
Enthusiast
Enthusiast
Posts: 177
Joined: Sun Mar 03, 2013 9:01 am

Re: Simple code to change the monitor frequency

Post by Simo_na »

Thank you
Post Reply