To see it in action (and if you happen to have more than 1 monitor), move the window between monitors.
The displayed refresh rate should change, but this will only happen if your monitors have different refresh rates set obviously.
What is this procedure good for anyway?
Well, it might be nice to sync visual updates/drawing with the refresh rate of the desktop or monitor the program window is currently on.
There may be an alternative way to get this info using even less code,
but the quick tests I did on Window DC's didn't work, the window stats was always showing the same refresh rate for some reason.
It's a shame there is no way to do a GetDeviceCaps on a HMON handle or similar.
Anyway, it is possible to make a platform independent variant of this procedure, but I'm too lazy to replicate the behavior of MonitorFromWindow_(hwnd,#MONITOR_DEFAULTTONEAREST) and messy RECT calculations.

Who knows, maybe you can bribe freak or Fred to make a GetWindowRefresh() that behaves similar to this source

Code: Select all
EnableExplicit
#MONITORINFOF_PRIMARY=1
#MONITOR_DEFAULTTONULL=0
#MONITOR_DEFAULTTOPRIMARY=1
#MONITOR_DEFAULTTONEAREST=2
Structure MONITORINFOEX
cbSize.l
rcMonitor.RECT
rcWork.RECT
dwFlags.l
szDevice.s{#CCHDEVICENAME}
EndStructure
Procedure.i GetMonitorRefreshFromWindow(window.i)
Protected result.i=#Null,hwnd.i,hmon.i,mi.MONITORINFOEX,n.i,i.i
If IsWindow(window)
hwnd=WindowID(window)
mi\cbSize=SizeOf(mi)
hmon=MonitorFromWindow_(hwnd,#MONITOR_DEFAULTTONEAREST)
If hmon
If GetMonitorInfo_(hmon,mi)
n=ExamineDesktops()-1
For i=0 To n
If mi\szDevice=DesktopName(i)
result=DesktopFrequency(i)
EndIf
Next
EndIf
EndIf
EndIf
ProcedureReturn result ;If #null, there was an error or monitor not found.
EndProcedure
#Window_Main=1
Define.i event,quit,i.i,fEnabled.l,hz.i,oldhz.i
If OpenWindow(#Window_Main,100,200,195,260,"PureBasic Window",#PB_Window_SystemMenu|#PB_Window_MinimizeGadget|#PB_Window_MaximizeGadget)
oldhz=0
Repeat
event=WaitWindowEvent()
If event=#PB_Event_CloseWindow
quit=1
ElseIf event=#PB_Event_MoveWindow
hz=GetMonitorRefreshFromWindow(#Window_Main)
If hz<>oldhz
oldhz=hz
Debug Str(hz)+" Hz"
EndIf
EndIf
Until quit=1
EndIf