From af409260eb8192924bd85d574a1c09b047f07763 Mon Sep 17 00:00:00 2001 From: Glenn Maynard Date: Tue, 17 Jan 2006 01:42:17 +0000 Subject: [PATCH] fix GraphicsWindow::GetParams doesn't return the actual refresh rate --- .../src/archutils/Win32/GraphicsWindow.cpp | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/stepmania/src/archutils/Win32/GraphicsWindow.cpp b/stepmania/src/archutils/Win32/GraphicsWindow.cpp index d50c9deb55..17ee0cd20e 100644 --- a/stepmania/src/archutils/Win32/GraphicsWindow.cpp +++ b/stepmania/src/archutils/Win32/GraphicsWindow.cpp @@ -174,6 +174,42 @@ static LRESULT CALLBACK GraphicsWindow_WndProc( HWND hWnd, UINT msg, WPARAM wPar return DefWindowProcA( hWnd, msg, wParam, lParam ); } +static void AdjustVideoModeParams( VideoModeParams &p ) +{ + DEVMODE dm; + ZERO( dm ); + dm.dmSize = sizeof(dm); + if( !EnumDisplaySettings(NULL, ENUM_CURRENT_SETTINGS, &dm) ) + { + p.rate = 60; + LOG->Warn( "%s", werr_ssprintf(GetLastError(), "EnumDisplaySettings failed").c_str() ); + return; + } + + /* + * On a nForce 2 IGP on Windows 98, dm.dmDisplayFrequency sometimes + * (but not always) is 0. + * + * MSDN: When you call the EnumDisplaySettings function, the + * dmDisplayFrequency member may return with the value 0 or 1. + * These values represent the display hardware's default refresh rate. + * This default rate is typically set by switches on a display card or + * computer motherboard, or by a configuration program that does not + * use Win32 display functions such as ChangeDisplaySettings. + */ + if( !(dm.dmFields & DM_DISPLAYFREQUENCY) || + dm.dmDisplayFrequency == 0 || + dm.dmDisplayFrequency == 1 ) + { + p.rate = 60; + LOG->Warn( "EnumDisplaySettings doesn't know what the refresh rate is. %d %d %d", dm.dmPelsWidth, dm.dmPelsHeight, dm.dmBitsPerPel ); + } + else + { + p.rate = dm.dmDisplayFrequency; + } +} + /* Set the display mode to the given size, bit depth and refresh. The refresh * setting may be ignored. */ CString GraphicsWindow::SetScreenMode( const VideoModeParams &p ) @@ -230,6 +266,9 @@ void GraphicsWindow::CreateGraphicsWindow( const VideoModeParams &p, bool bForce { g_CurrentParams = p; + // Adjust g_CurrentParams to reflect the actual display settings. + AdjustVideoModeParams( g_CurrentParams ); + if( g_hWndMain == NULL || bForceRecreateWindow ) { int iWindowStyle = GetWindowStyle( p.windowed );