【发布时间】:2021-04-16 23:54:31
【问题描述】:
我有一个在垂直同步关闭的情况下由IDXGISwapChain1 刷新的窗口。如果可能,我想手动控制窗口的当前速率,使其尽可能接近当前的显示器刷新率。
在将具有不同刷新率的两台显示器连接到 PC 的情况下,我希望在窗口从一台显示器移动到另一台显示器时收到通知,以便我可以相应地更改当前的帧速率。
据我所知,WM_DISPLAYCHANGE 和WM_DPICHANGED 可能无法涵盖这种情况。如果我错了,请纠正我。
更新: 这是我根据 Strive 的回答编写的代码,
LRESULT OnPositionChanged(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{
// Get the monitor handle for the window.
HMONITOR currentMonitor = MonitorFromWindow(m_hWnd, MONITOR_DEFAULTTONEAREST);
// error handling
// no need to bother if the window stays on the same monitor
if (_currentMonitor != currentMonitor)
{
// Get more information about the monitor
MONITORINFOEX monitorInfo;
monitorInfo.cbSize = sizeof(MONITORINFOEX);
BOOL succeed = GetMonitorInfo(currentMonitor, (LPMONITORINFO)&monitorInfo);
// error handling
// Get the current display settings for that monitor, which includes the refresh rate
DEVMODE devMode;
devMode.dmSize = sizeof(DEVMODE);
succeed = EnumDisplaySettings(monitorInfo.szDevice, ENUM_CURRENT_SETTINGS, &devMode);
// error handling
// use devMode.dmDisplayFrequency to update my present frame rate
// ...
_currentMonitor = currentMonitor;
}
return 0L;
}
LRESULT OnDisplayChanged(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{
// WM_DISPLAYCHANGE message is sent to all windows when the display resolution has changed
// When a WM_DISPLAYCHANGE message is sent, any monitor may be removed from the desktop and thus its HMONITOR becomes invalid or has its settings changed.
_currentMonitor = NULL;
return 0L;
}
我想在窗口改变位置后改变帧率,所以我切换到WM_WINDOWPOSCHANGED。
【问题讨论】: