//----------------------------------------------------------------------------- // Name: ResolutionChanged // Desc: Respond to a change of selected resolution by rebuilding the // refresh rate list. //----------------------------------------------------------------------------- void CD3DSettingsDialog::ResolutionChanged( void ) { if (m_d3dSettings.IsWindowed) return; D3DAdapterInfo* pAdapterInfo = (D3DAdapterInfo*)ComboBoxSelected( IDC_ADAPTER_COMBO ); if( pAdapterInfo == NULL ) return; // Update settingsNew with new resolution DWORD dwResolutionData = PtrToUlong( ComboBoxSelected( IDC_RESOLUTION_COMBO ) ); UINT width = LOWORD( dwResolutionData ); UINT height = HIWORD( dwResolutionData ); m_d3dSettings.Fullscreen_DisplayMode.Width = width; m_d3dSettings.Fullscreen_DisplayMode.Height = height; // Update refresh rate list based on new resolution D3DFORMAT adapterFormat = (D3DFORMAT)PtrToUlong( ComboBoxSelected( IDC_ADAPTERFORMAT_COMBO ) ); ComboBoxClear( IDC_REFRESHRATE_COMBO ); for( UINT idm = 0; idm < pAdapterInfo->pDisplayModeList->Count(); idm++ ) { D3DDISPLAYMODE displayMode = *(D3DDISPLAYMODE*)pAdapterInfo->pDisplayModeList->GetPtr(idm); if (displayMode.Format == adapterFormat && displayMode.Width == width && displayMode.Height == height) { TCHAR strRefreshRate[50]; if( displayMode.RefreshRate == 0 ) lstrcpy( strRefreshRate, TEXT("Default Rate") ); else _sntprintf_s( strRefreshRate, 50, 50, TEXT("%d Hz"), displayMode.RefreshRate ); strRefreshRate[49] = 0; if( !ComboBoxContainsText( IDC_REFRESHRATE_COMBO, strRefreshRate ) ) { ComboBoxAdd( IDC_REFRESHRATE_COMBO, UlongToPtr( displayMode.RefreshRate ), strRefreshRate ); if (m_d3dSettings.Fullscreen_DisplayMode.RefreshRate == displayMode.RefreshRate) ComboBoxSelect( IDC_REFRESHRATE_COMBO, UlongToPtr( displayMode.RefreshRate ) ); } } } if (!ComboBoxSomethingSelected( IDC_REFRESHRATE_COMBO ) && ComboBoxCount( IDC_REFRESHRATE_COMBO ) > 0) { ComboBoxSelectIndex( IDC_REFRESHRATE_COMBO, 0 ); } }
// Handles window messages for the graphics settings dialog. INT_PTR DeviceEnumeration::SettingsDialogProc( HWND dialog, UINT msg, WPARAM wparam, LPARAM lparam ) { switch( msg ) { case WM_INITDIALOG: { // Display the adapter details and its driver version. char version[16]; sprintf( version, "%d", LOWORD( m_adapter.DriverVersion.LowPart ) ); Edit_SetText( GetDlgItem( dialog, IDC_DISPLAY_ADAPTER ), m_adapter.Description ); Edit_SetText( GetDlgItem( dialog, IDC_DRIVER_VERSION ), version ); // Check if the settings script has anything in it. if( m_settingsScript->GetBoolData( "windowed" ) == NULL ) { // The settings script is empty, so default to windowed mode. CheckDlgButton( dialog, IDC_WINDOWED, m_windowed = true ); } else { // Load the window mode state. CheckDlgButton( dialog, IDC_WINDOWED, m_windowed = *m_settingsScript->GetBoolData( "windowed" ) ); CheckDlgButton( dialog, IDC_FULLSCREEN, !m_windowed ); // Check if running in fullscreen mode. if( m_windowed == false ) { // Enable all the fullscreen controls. EnableWindow( GetDlgItem( dialog, IDC_VSYNC ), true ); EnableWindow( GetDlgItem( dialog, IDC_DISPLAY_FORMAT ), true ); EnableWindow( GetDlgItem( dialog, IDC_RESOLUTION ), true ); EnableWindow( GetDlgItem( dialog, IDC_REFRESH_RATE ), true ); // Load the vsync state. CheckDlgButton( dialog, IDC_VSYNC, m_vsync = *m_settingsScript->GetBoolData( "vsync" ) ); // Fill in the display formats combo box. ComboBox_ResetContent( GetDlgItem( dialog, IDC_DISPLAY_FORMAT ) ); m_displayModes->Iterate( true ); while( m_displayModes->Iterate() ) if( !ComboBoxContainsText( dialog, IDC_DISPLAY_FORMAT, m_displayModes->GetCurrent()->bpp ) ) ComboBoxAdd( dialog, IDC_DISPLAY_FORMAT, (void*)m_displayModes->GetCurrent()->mode.Format, m_displayModes->GetCurrent()->bpp ); ComboBoxSelect( dialog, IDC_DISPLAY_FORMAT, *m_settingsScript->GetNumberData( "bpp" ) ); char text[16]; // Fill in the resolutions combo box. ComboBox_ResetContent( GetDlgItem( dialog, IDC_RESOLUTION ) ); m_displayModes->Iterate( true ); while( m_displayModes->Iterate() ) { if( m_displayModes->GetCurrent()->mode.Format == (D3DFORMAT)PtrToUlong( ComboBoxSelected( dialog, IDC_COLOUR_DEPTH ) ) ) { sprintf( text, "%d x %d", m_displayModes->GetCurrent()->mode.Width, m_displayModes->GetCurrent()->mode.Height ); if (!ComboBoxContainsText( dialog, IDC_RESOLUTION, text ) ) ComboBoxAdd( dialog, IDC_RESOLUTION, (void*)MAKELONG( m_displayModes->GetCurrent()->mode.Width, m_displayModes->GetCurrent()->mode.Height ), text ); } } ComboBoxSelect( dialog, IDC_RESOLUTION, *m_settingsScript->GetNumberData( "resolution" ) ); // Fill in the refresh rates combo box. ComboBox_ResetContent( GetDlgItem( dialog, IDC_REFRESH_RATE ) ); m_displayModes->Iterate( true ); while( m_displayModes->Iterate() ) { if( (DWORD)MAKELONG( m_displayModes->GetCurrent()->mode.Width, m_displayModes->GetCurrent()->mode.Height ) == (DWORD)PtrToUlong( ComboBoxSelected( dialog, IDC_RESOLUTION ) ) ) { sprintf( text, "%d Hz", m_displayModes->GetCurrent()->mode.RefreshRate ); if (!ComboBoxContainsText( dialog, IDC_REFRESH_RATE, text ) ) ComboBoxAdd( dialog, IDC_REFRESH_RATE, (void*)m_displayModes->GetCurrent()->mode.RefreshRate, text ); } } ComboBoxSelect( dialog, IDC_REFRESH_RATE, *m_settingsScript->GetNumberData( "refresh" ) ); } } return true; } case WM_COMMAND: { switch( LOWORD(wparam) ) { case IDOK: { // Store the details of the selected display mode. m_selectedDisplayMode.Width = LOWORD( PtrToUlong( ComboBoxSelected( dialog, IDC_RESOLUTION ) ) ); m_selectedDisplayMode.Height = HIWORD( PtrToUlong( ComboBoxSelected( dialog, IDC_RESOLUTION ) ) ); m_selectedDisplayMode.RefreshRate = PtrToUlong( ComboBoxSelected( dialog, IDC_REFRESH_RATE ) ); m_selectedDisplayMode.Format = (D3DFORMAT)PtrToUlong( ComboBoxSelected( dialog, IDC_DISPLAY_FORMAT ) ); m_windowed = IsDlgButtonChecked( dialog, IDC_WINDOWED ) ? true : false; m_vsync = IsDlgButtonChecked( dialog, IDC_VSYNC ) ? true : false; // Destroy the display modes list. SAFE_DELETE( m_displayModes ); // Get the selected index from each combo box. long bpp = ComboBox_GetCurSel( GetDlgItem( dialog, IDC_DISPLAY_FORMAT ) ); long resolution = ComboBox_GetCurSel( GetDlgItem( dialog, IDC_RESOLUTION ) ); long refresh = ComboBox_GetCurSel( GetDlgItem( dialog, IDC_REFRESH_RATE ) ); // Check if the settings script has anything in it. if( m_settingsScript->GetBoolData( "windowed" ) == NULL ) { // Add all the settings to the script. m_settingsScript->AddVariable( "windowed", VARIABLE_BOOL, &m_windowed ); m_settingsScript->AddVariable( "vsync", VARIABLE_BOOL, &m_vsync ); m_settingsScript->AddVariable( "bpp", VARIABLE_NUMBER, &bpp ); m_settingsScript->AddVariable( "resolution", VARIABLE_NUMBER, &resolution ); m_settingsScript->AddVariable( "refresh", VARIABLE_NUMBER, &refresh ); } else { // Set all the settings. m_settingsScript->SetVariable( "windowed", &m_windowed ); m_settingsScript->SetVariable( "vsync", &m_vsync ); m_settingsScript->SetVariable( "bpp", &bpp ); m_settingsScript->SetVariable( "resolution", &resolution ); m_settingsScript->SetVariable( "refresh", &refresh ); } // Save all the settings out to the settings script. m_settingsScript->SaveScript(); // Destroy the settings script. SAFE_DELETE( m_settingsScript ); // Close the dialog. EndDialog( dialog, IDOK ); return true; } case IDCANCEL: { // Destroy the display modes list. SAFE_DELETE( m_displayModes ); // Destroy the settings script. SAFE_DELETE( m_settingsScript ); EndDialog( dialog, IDCANCEL ); return true; } case IDC_COLOUR_DEPTH: { if( CBN_SELCHANGE == HIWORD(wparam) ) { char res[16]; DWORD selectedRes = (DWORD)PtrToUlong( ComboBoxSelected( dialog, IDC_RESOLUTION ) ); // Update the resolution combo box. ComboBox_ResetContent( GetDlgItem( dialog, IDC_RESOLUTION ) ); m_displayModes->Iterate( true ); while( m_displayModes->Iterate() ) { if( m_displayModes->GetCurrent()->mode.Format == (D3DFORMAT)PtrToUlong( ComboBoxSelected( dialog, IDC_COLOUR_DEPTH ) ) ) { sprintf( res, "%d x %d", m_displayModes->GetCurrent()->mode.Width, m_displayModes->GetCurrent()->mode.Height ); if( !ComboBoxContainsText( dialog, IDC_RESOLUTION, res ) ) { ComboBoxAdd( dialog, IDC_RESOLUTION, (void*)MAKELONG( m_displayModes->GetCurrent()->mode.Width, m_displayModes->GetCurrent()->mode.Height ), res ); if( selectedRes == (DWORD)MAKELONG( m_displayModes->GetCurrent()->mode.Width, m_displayModes->GetCurrent()->mode.Height ) ) ComboBoxSelect( dialog, IDC_RESOLUTION, (void*)selectedRes ); } } } if( ComboBoxSelected( dialog, IDC_RESOLUTION ) == NULL ) ComboBoxSelect( dialog, IDC_RESOLUTION, 0 ); } return true; } case IDC_RESOLUTION: { if( CBN_SELCHANGE == HIWORD(wparam) ) { char refresh[16]; DWORD selectedRefresh = (DWORD)PtrToUlong( ComboBoxSelected( dialog, IDC_REFRESH_RATE ) ); // Update the refresh rate combo box. ComboBox_ResetContent( GetDlgItem( dialog, IDC_REFRESH_RATE ) ); m_displayModes->Iterate( true ); while( m_displayModes->Iterate() ) { if( (DWORD)MAKELONG( m_displayModes->GetCurrent()->mode.Width, m_displayModes->GetCurrent()->mode.Height ) == (DWORD)PtrToUlong( ComboBoxSelected( dialog, IDC_RESOLUTION ) ) ) { sprintf( refresh, "%d Hz", m_displayModes->GetCurrent()->mode.RefreshRate ); if( !ComboBoxContainsText( dialog, IDC_REFRESH_RATE, refresh ) ) { ComboBoxAdd( dialog, IDC_REFRESH_RATE, (void*)m_displayModes->GetCurrent()->mode.RefreshRate, refresh ); if( selectedRefresh == m_displayModes->GetCurrent()->mode.RefreshRate ) ComboBoxSelect( dialog, IDC_REFRESH_RATE, (void*)selectedRefresh ); } } } if( ComboBoxSelected( dialog, IDC_REFRESH_RATE ) == NULL ) ComboBoxSelect( dialog, IDC_REFRESH_RATE, 0 ); } return true; } case IDC_WINDOWED: case IDC_FULLSCREEN: { // Check if the user has change to windowed or fullscreen mode. if( IsDlgButtonChecked( dialog, IDC_WINDOWED ) ) { // Clear and disable all the fullscreen controls. ComboBox_ResetContent( GetDlgItem( dialog, IDC_DISPLAY_FORMAT ) ); ComboBox_ResetContent( GetDlgItem( dialog, IDC_RESOLUTION ) ); ComboBox_ResetContent( GetDlgItem( dialog, IDC_REFRESH_RATE ) ); CheckDlgButton( dialog, IDC_VSYNC, false ); EnableWindow( GetDlgItem( dialog, IDC_VSYNC ), false ); EnableWindow( GetDlgItem( dialog, IDC_DISPLAY_FORMAT ), false ); EnableWindow( GetDlgItem( dialog, IDC_RESOLUTION ), false ); EnableWindow( GetDlgItem( dialog, IDC_REFRESH_RATE ), false ); } else { // Enable all the fullscreen controls. EnableWindow( GetDlgItem( dialog, IDC_VSYNC ), true ); EnableWindow( GetDlgItem( dialog, IDC_DISPLAY_FORMAT ), true ); EnableWindow( GetDlgItem( dialog, IDC_RESOLUTION ), true ); EnableWindow( GetDlgItem( dialog, IDC_REFRESH_RATE ), true ); // Fill in the display formats combo box. ComboBox_ResetContent( GetDlgItem( dialog, IDC_DISPLAY_FORMAT ) ); m_displayModes->Iterate( true ); while( m_displayModes->Iterate() ) { if( !ComboBoxContainsText( dialog, IDC_DISPLAY_FORMAT, m_displayModes->GetCurrent()->bpp ) ) ComboBoxAdd( dialog, IDC_DISPLAY_FORMAT, (void*)m_displayModes->GetCurrent()->mode.Format, m_displayModes->GetCurrent()->bpp ); } ComboBoxSelect( dialog, IDC_DISPLAY_FORMAT, 0 ); } return true; } } } } return false; }
//----------------------------------------------------------------------------- // Name: AdapterFormatChanged // Desc: Respond to a change of selected adapter format by rebuilding the // resolution list and back buffer format list. Updating the selected // resolution and back buffer format will trigger updates of the rest // of the dialog. //----------------------------------------------------------------------------- void CD3DSettingsDialog::AdapterFormatChanged( void ) { if( !IsDlgButtonChecked( m_hDlg, IDC_WINDOW ) ) { D3DAdapterInfo* pAdapterInfo = (D3DAdapterInfo*)ComboBoxSelected( IDC_ADAPTER_COMBO ); D3DFORMAT adapterFormat = (D3DFORMAT)PtrToUlong( ComboBoxSelected( IDC_ADAPTERFORMAT_COMBO ) ); m_d3dSettings.Fullscreen_DisplayMode.Format = adapterFormat; ComboBoxClear( IDC_RESOLUTION_COMBO ); for( UINT idm = 0; idm < pAdapterInfo->pDisplayModeList->Count(); idm++ ) { D3DDISPLAYMODE displayMode = *(D3DDISPLAYMODE*)pAdapterInfo->pDisplayModeList->GetPtr(idm); if (displayMode.Format == adapterFormat) { DWORD dwResolutionData; TCHAR strResolution[50]; dwResolutionData = MAKELONG( displayMode.Width, displayMode.Height ); _sntprintf_s( strResolution, 50, 50, TEXT("%d by %d"), displayMode.Width, displayMode.Height ); strResolution[49] = 0; if (!ComboBoxContainsText( IDC_RESOLUTION_COMBO, strResolution ) ) { ComboBoxAdd( IDC_RESOLUTION_COMBO, ULongToPtr( dwResolutionData ), strResolution ); if (m_d3dSettings.Fullscreen_DisplayMode.Width == displayMode.Width && m_d3dSettings.Fullscreen_DisplayMode.Height == displayMode.Height) { ComboBoxSelect( IDC_RESOLUTION_COMBO, ULongToPtr( dwResolutionData ) ); } } } } if (!ComboBoxSomethingSelected( IDC_RESOLUTION_COMBO ) && ComboBoxCount( IDC_RESOLUTION_COMBO ) > 0) { ComboBoxSelectIndex( IDC_RESOLUTION_COMBO, 0 ); } } // Update backbuffer format combo box D3DDeviceInfo* pDeviceInfo = (D3DDeviceInfo*)ComboBoxSelected( IDC_DEVICE_COMBO ); if( pDeviceInfo == NULL ) return; ComboBoxClear( IDC_BACKBUFFERFORMAT_COMBO ); for( UINT idc = 0; idc < pDeviceInfo->pDeviceComboList->Count(); idc++ ) { D3DDeviceCombo* pDeviceCombo = (D3DDeviceCombo*)pDeviceInfo->pDeviceComboList->GetPtr(idc); if (pDeviceCombo->IsWindowed == m_d3dSettings.IsWindowed && pDeviceCombo->AdapterFormat == m_d3dSettings.DisplayMode().Format) { if (!ComboBoxContainsText( IDC_BACKBUFFERFORMAT_COMBO, D3DUtil_D3DFormatToString( pDeviceCombo->BackBufferFormat ) ) ) { ComboBoxAdd( IDC_BACKBUFFERFORMAT_COMBO, (void*)pDeviceCombo->BackBufferFormat, D3DUtil_D3DFormatToString( pDeviceCombo->BackBufferFormat ) ); if (pDeviceCombo->BackBufferFormat == m_d3dSettings.BackBufferFormat() ) ComboBoxSelect( IDC_BACKBUFFERFORMAT_COMBO, (void*)pDeviceCombo->BackBufferFormat ); } } } if (!ComboBoxSomethingSelected( IDC_BACKBUFFERFORMAT_COMBO ) && ComboBoxCount( IDC_BACKBUFFERFORMAT_COMBO ) > 0) { ComboBoxSelectIndex( IDC_BACKBUFFERFORMAT_COMBO, 0 ); } }
//----------------------------------------------------------------------------- // Name: WindowedFullscreenChanged // Desc: Respond to a change of windowed/fullscreen state by rebuilding the // adapter format list, resolution list, and refresh rate list. // Updating the selected adapter format will trigger updates of the // rest of the dialog. //----------------------------------------------------------------------------- void CD3DSettingsDialog::WindowedFullscreenChanged( void ) { D3DAdapterInfo* pAdapterInfo = (D3DAdapterInfo*)ComboBoxSelected( IDC_ADAPTER_COMBO ); D3DDeviceInfo* pDeviceInfo = (D3DDeviceInfo*)ComboBoxSelected( IDC_DEVICE_COMBO ); if( pAdapterInfo == NULL || pDeviceInfo == NULL ) return; if( IsDlgButtonChecked( m_hDlg, IDC_WINDOW ) ) { m_d3dSettings.IsWindowed = true; m_d3dSettings.pWindowed_AdapterInfo = pAdapterInfo; m_d3dSettings.pWindowed_DeviceInfo = pDeviceInfo; // Update adapter format combo box ComboBoxClear( IDC_ADAPTERFORMAT_COMBO ); ComboBoxAdd( IDC_ADAPTERFORMAT_COMBO, (void*)m_d3dSettings.Windowed_DisplayMode.Format, D3DUtil_D3DFormatToString( m_d3dSettings.Windowed_DisplayMode.Format ) ); ComboBoxSelectIndex( IDC_ADAPTERFORMAT_COMBO, 0 ); EnableWindow( GetDlgItem( m_hDlg, IDC_ADAPTERFORMAT_COMBO ), false ); // Update resolution combo box DWORD dwResolutionData; TCHAR strResolution[50]; dwResolutionData = MAKELONG( m_d3dSettings.Windowed_DisplayMode.Width, m_d3dSettings.Windowed_DisplayMode.Height ); _sntprintf_s( strResolution, 50, 50, TEXT("%d by %d"), m_d3dSettings.Windowed_DisplayMode.Width, m_d3dSettings.Windowed_DisplayMode.Height ); strResolution[49] = 0; ComboBoxClear( IDC_RESOLUTION_COMBO ); ComboBoxAdd( IDC_RESOLUTION_COMBO, ULongToPtr(dwResolutionData), strResolution ); ComboBoxSelectIndex( IDC_RESOLUTION_COMBO, 0 ); EnableWindow( GetDlgItem( m_hDlg, IDC_RESOLUTION_COMBO ), false ); // Update refresh rate combo box TCHAR strRefreshRate[50]; if( m_d3dSettings.Windowed_DisplayMode.RefreshRate == 0 ) lstrcpy( strRefreshRate, TEXT("Default Rate") ); else _sntprintf_s( strRefreshRate, 50, 50, TEXT("%d Hz"), m_d3dSettings.Windowed_DisplayMode.RefreshRate ); strRefreshRate[49] = 0; ComboBoxClear( IDC_REFRESHRATE_COMBO ); ComboBoxAdd( IDC_REFRESHRATE_COMBO, ULongToPtr(m_d3dSettings.Windowed_DisplayMode.RefreshRate), strRefreshRate ); ComboBoxSelectIndex( IDC_REFRESHRATE_COMBO, 0 ); EnableWindow( GetDlgItem( m_hDlg, IDC_REFRESHRATE_COMBO ), false ); } else { m_d3dSettings.IsWindowed = false; m_d3dSettings.pFullscreen_AdapterInfo = pAdapterInfo; m_d3dSettings.pFullscreen_DeviceInfo = pDeviceInfo; // Update adapter format combo box ComboBoxClear( IDC_ADAPTERFORMAT_COMBO ); for( UINT idc = 0; idc < pDeviceInfo->pDeviceComboList->Count(); idc++ ) { D3DDeviceCombo* pDeviceCombo = (D3DDeviceCombo*)pDeviceInfo->pDeviceComboList->GetPtr(idc); if( pDeviceCombo->IsWindowed ) continue; D3DFORMAT adapterFormat = pDeviceCombo->AdapterFormat; if( !ComboBoxContainsText( IDC_ADAPTERFORMAT_COMBO, D3DUtil_D3DFormatToString( adapterFormat ) ) ) { ComboBoxAdd( IDC_ADAPTERFORMAT_COMBO, (void*)adapterFormat, D3DUtil_D3DFormatToString( adapterFormat ) ); if( adapterFormat == m_d3dSettings.Fullscreen_DisplayMode.Format ) { ComboBoxSelect( IDC_ADAPTERFORMAT_COMBO, (void*)adapterFormat ); } } } if( !ComboBoxSomethingSelected( IDC_ADAPTERFORMAT_COMBO ) && ComboBoxCount( IDC_ADAPTERFORMAT_COMBO ) > 0 ) { ComboBoxSelectIndex( IDC_ADAPTERFORMAT_COMBO, 0 ); } EnableWindow( GetDlgItem( m_hDlg, IDC_ADAPTERFORMAT_COMBO), true ); // Update resolution combo box EnableWindow( GetDlgItem( m_hDlg, IDC_RESOLUTION_COMBO), true ); // Update refresh rate combo box EnableWindow( GetDlgItem( m_hDlg, IDC_REFRESHRATE_COMBO), true ); } }