Refresh monitor info in windows

I've tested the code in the first post of this page, and I do get the correct refresh rate of my monitor. Hope this helps.

http://stackoverflow.com/question...get-the-refresh-rate-of-a-monitor

I'd prefer to use the function "GetTickCount()" to limit the framerate with the info of the monitor refresh rate (if you don't want to use a fixed value)

Edited by Quaiton on
Yeah it looks like EnumDisplaySettings() is the call for getting the refresh rate. I get 60 Hz as expected.

1
2
3
4
5
	
DEVMODE dm = { 0 };
dm.dmSize = sizeof(DEVMODE);
if(EnumDisplaySettings(NULL, ENUM_CURRENT_SETTINGS, &dm))
	printf("%d\n", dm.dmDisplayFrequency);


The 0 or 1 it may return is when the refresh rate is set by hardware switches, then I guess Windows can't actually get the rate so returns "default" and you have to interpret that yourself.

Edited by Dejan on
Never saw that EnumDisplaySettings() return 0 or 1 in dmDisplayFrequency for "common" display modes.

At least you can pick up any mode you want with particular frequency.
We can certainly try this and just use 60 for "unknown" modes, although it would be nice to know what is going on under the hood... maybe someone from MS could post about this?

- Casey
GetCaps DC, VREFRESH

gives 60 on my nachine which is correct.

Maybe I have misunderstood something, but isnt this what you want?
The problem we're trying to figure out is just that Windows is allowed to return "0 or 1" for that value - this was discussed on the stream. So we're debating what to do about that. Should we just use it, and if it's 0 or 1, assume 60? Or should we try to do something fancier? Etc., etc.

- Casey
It's easy to get from WMI:

1
2
$(Get-WmiObject Win32_DisplayConfiguration).DisplayFrequency
60


But I know that is not very helpful in a C program. I bet interacting with WMI from straight C is rough.
I believe WMI stuff for display configuration won't work on Windows XP (or won't work reliably). Quoting http://msdn.microsoft.com/en-us/library/aa394137.aspx

Hardware that is not compatible with Windows Display Driver Model (WDDM) returns inaccurate property values for instances of this class.

Edited by Mārtiņš Možeiko on
I guess Windows XP compatibility will be a recurrent fly in the ointment here, but if the only XP compatible option is less than ideal, one could limit the less-than-ideal way to XP and go with DwmGetCompositionTimingInfo for Vista and up.. it returns a DWM_TIMING_INFO structure that contains a truckload of monitor and timing info.

http://msdn.microsoft.com/en-us/l...ws/desktop/aa969514(v=vs.85).aspx