10-04-2016 09:54 AM
Is there a .net command or other way to detect a screens refresh rate?
Thanks
Graham
10-04-2016 11:44 AM
A quick search reveals there is a user32.dll function (EnumDisplaySettings) that will return this information but don't ask me how to set it up.
10-12-2022 01:01 PM
This post is rather old, but it is always the first forum post I see when searching for calls to EnumDisplaySettings. The only code submissions I've seen have been VB dlls.
Attached is a labview example of a call to EnumDisplaySettingsA. It was meant to replicate functionality of an old 32-bit only library called "lvwinutil.lib"; I created the library in LabView after I migrated to 64-bit.
Please be aware that the MSDN documentation is a bit misleading, as in C programs, parts of the structure are joined as a union and are technically stored under the same offset! Always refer to VB examples where the structure is defined as "sequential" to determine the order in which clustered items should appear. To make this call in Labview, DMPositionX and DMPositionY should appear at the end of the cluster. There are also some excessive items listed on the MSDN page, for some unknown reason.
TO USE:
Open WinUtils->lvwinutil.lib->WinDisplay->WIN_GetDisplayMode.vi
Use device name: \\.\DISPLAY1
and iModenum: -1
If you only have one monitor to preview, \\.\DISPLAY1 will give you the results you need. For extended monitors, you'll have to increase the numeric value ex: \\.\DISPLAY2.
Be aware however that if your primary monitor is a laptop that is closed at the time of the call, the laptop is still considered the #1 enumeration, but calling it will return an error.
iModeNum value of -1 returns the active settings and caches settings to memory. Incrementing iModeNum will allow you to enumerate all possible settings for the display device.
I had to use 32-byte length clusters because you can't send an an initialized array in a cluster through to a library call; the library will treat it as an empty array and your offset will be wrong.
10-13-2022 04:19 AM - edited 10-13-2022 04:23 AM
@grahamwebb wrote:
Is there a .net command or other way to detect a screens refresh rate?
Thanks
Graham
Does this mean:
a) detect refresh rates (get an event if a refresh rate happens) or
b) read the refresh rate (get the refresh rate value, e.g. 60 Hz).
a) could probably be done with DirectX. (DirectX WaitForVerticalBlank, which will poll the status). I do have a faint recollection of trying stuff like this, but that must have been at least 15 years ago.
Note there's a vertical and horizontal refresh rate. Age ago these where both used to do funky graphical stuff in assembly.
Searching for Vertical black or vertical refresh rate will give better results, although nobody seems to care for this anymore. It's all being dealt with at a driver\library level.