windows 如何获取屏幕刷新率?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4110731/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 15:33:44  来源:igfitidea点击:

How to get the screen refresh rate?

c++windowsopengl

提问by Newbie

Is this even possible? Since ive noticed v-sync doesnt work on my laptop at all, so i am building FPS limiter "manually" and now i would like to use the FPS limit the user has set to his screen.

这甚至可能吗?因为我注意到 v-sync 在我的笔记本电脑上根本不起作用,所以我正在“手动”构建 FPS 限制器,现在我想使用用户设置到他的屏幕的 FPS 限制。

Edit:i mean the monitor hz rate.

编辑:我的意思是显示器的赫兹率。

Edit3:heres the code i got working (i think... anything wrong there?):

Edit3:这是我开始工作的代码(我认为......那里有什么问题吗?):

DEVMODE lpDevMode;
memset(&lpDevMode, 0, sizeof(DEVMODE));
lpDevMode.dmSize = sizeof(DEVMODE);
lpDevMode.dmDriverExtra = 0;

if(EnumDisplaySettings(NULL, ENUM_CURRENT_SETTINGS, &lpDevMode) == 0){
    framerate_limit = 60; // default value if cannot retrieve from user settings.
}

On demand, here is my v-sync enabling code jay.lee asked for:

根据需要,这是 jay.lee 要求的我的垂直同步启用代码:

PFNWGLSWAPINTERVALEXTPROC wglSwapIntervalEXT = NULL; // global

...

wglSwapIntervalEXT = (PFNWGLSWAPINTERVALEXTPROC) wglGetProcAddress("wglSwapIntervalEXT");

v_sync_enabled = 0;
if(wglSwapIntervalEXT != NULL){
    if(wglSwapIntervalEXT(1) != FALSE){
        v_sync_enabled = 1;
    }
}

回答by Novikov

The Win32 EnumDisplaySettingsfunctioncould be what you're looking for. The refresh rate is held in lpDevMode->dmDisplayFrequency.

Win32EnumDisplaySettings函数可能正是您要找的。刷新率保持在lpDevMode->dmDisplayFrequency.