0001: //-----------------------------------------------------------------------------
0002: // File: D3DSettings.cpp
0003: //
0004: // Desc: Settings class and change-settings dialog class for the Direct3D 
0005: //       samples framework library.
0006: //-----------------------------------------------------------------------------
0007: #define STRICT
0008: #include <windows.h>
0009: #include <windowsx.h>
0010: #include <tchar.h>
0011: #include <stdio.h>
0012: #include <D3D9.h>
0013: #include "DXUtil.h"
0014: #include "D3DUtil.h"
0015: #include "D3DEnumeration.h"
0016: #include "D3DSettings.h"
0017: #include "resource.h"
0018: 
0019: CD3DSettingsDialog* s_pSettingsDialog = NULL;
0020: 
0021: 
0022: //-----------------------------------------------------------------------------
0023: // Name: D3DDevTypeToString
0024: // Desc: Returns the string for the given D3DDEVTYPE.
0025: //-----------------------------------------------------------------------------
0026: TCHAR* D3DDevTypeToString(D3DDEVTYPE devType)
0027: {
0028:     switch (devType)
0029:     {
0030:     case D3DDEVTYPE_HAL:        return TEXT("D3DDEVTYPE_HAL");
0031:     case D3DDEVTYPE_SW:         return TEXT("D3DDEVTYPE_SW");
0032:     case D3DDEVTYPE_REF:        return TEXT("D3DDEVTYPE_REF");
0033:     default:                    return TEXT("Unknown devType");
0034:     }
0035: }
0036: 
0037: 
0038: //-----------------------------------------------------------------------------
0039: // Name: MultisampleTypeToString
0040: // Desc: Returns the string for the given D3DMULTISAMPLE_TYPE.
0041: //-----------------------------------------------------------------------------
0042: TCHAR* MultisampleTypeToString(D3DMULTISAMPLE_TYPE MultiSampleType)
0043: {
0044:     switch (MultiSampleType)
0045:     {
0046:     case D3DMULTISAMPLE_NONE:   return TEXT("D3DMULTISAMPLE_NONE");
0047:     case D3DMULTISAMPLE_NONMASKABLE: return TEXT("D3DMULTISAMPLE_NONMASKABLE");
0048:     case D3DMULTISAMPLE_2_SAMPLES: return TEXT("D3DMULTISAMPLE_2_SAMPLES");
0049:     case D3DMULTISAMPLE_3_SAMPLES: return TEXT("D3DMULTISAMPLE_3_SAMPLES");
0050:     case D3DMULTISAMPLE_4_SAMPLES: return TEXT("D3DMULTISAMPLE_4_SAMPLES");
0051:     case D3DMULTISAMPLE_5_SAMPLES: return TEXT("D3DMULTISAMPLE_5_SAMPLES");
0052:     case D3DMULTISAMPLE_6_SAMPLES: return TEXT("D3DMULTISAMPLE_6_SAMPLES");
0053:     case D3DMULTISAMPLE_7_SAMPLES: return TEXT("D3DMULTISAMPLE_7_SAMPLES");
0054:     case D3DMULTISAMPLE_8_SAMPLES: return TEXT("D3DMULTISAMPLE_8_SAMPLES");
0055:     case D3DMULTISAMPLE_9_SAMPLES: return TEXT("D3DMULTISAMPLE_9_SAMPLES");
0056:     case D3DMULTISAMPLE_10_SAMPLES: return TEXT("D3DMULTISAMPLE_10_SAMPLES");
0057:     case D3DMULTISAMPLE_11_SAMPLES: return TEXT("D3DMULTISAMPLE_11_SAMPLES");
0058:     case D3DMULTISAMPLE_12_SAMPLES: return TEXT("D3DMULTISAMPLE_12_SAMPLES");
0059:     case D3DMULTISAMPLE_13_SAMPLES: return TEXT("D3DMULTISAMPLE_13_SAMPLES");
0060:     case D3DMULTISAMPLE_14_SAMPLES: return TEXT("D3DMULTISAMPLE_14_SAMPLES");
0061:     case D3DMULTISAMPLE_15_SAMPLES: return TEXT("D3DMULTISAMPLE_15_SAMPLES");
0062:     case D3DMULTISAMPLE_16_SAMPLES: return TEXT("D3DMULTISAMPLE_16_SAMPLES");
0063:     default:                    return TEXT("Unknown Multisample Type");
0064:     }
0065: }
0066: 
0067: 
0068: //-----------------------------------------------------------------------------
0069: // Name: VertexProcessingTypeToString
0070: // Desc: Returns the string for the given VertexProcessingType.
0071: //-----------------------------------------------------------------------------
0072: TCHAR* VertexProcessingTypeToString(VertexProcessingType vpt)
0073: {
0074:     switch (vpt)
0075:     {
0076:     case SOFTWARE_VP:      return TEXT("SOFTWARE_VP");
0077:     case MIXED_VP:         return TEXT("MIXED_VP");
0078:     case HARDWARE_VP:      return TEXT("HARDWARE_VP");
0079:     case PURE_HARDWARE_VP: return TEXT("PURE_HARDWARE_VP");
0080:     default:               return TEXT("Unknown VertexProcessingType");
0081:     }
0082: }
0083: 
0084: 
0085: //-----------------------------------------------------------------------------
0086: // Name: PresentIntervalToString
0087: // Desc: Returns the string for the given present interval.
0088: //-----------------------------------------------------------------------------
0089: TCHAR* PresentIntervalToString( UINT pi )
0090: {
0091:     switch( pi )
0092:     {
0093:     case D3DPRESENT_INTERVAL_IMMEDIATE: return TEXT("D3DPRESENT_INTERVAL_IMMEDIATE");
0094:     case D3DPRESENT_INTERVAL_DEFAULT:   return TEXT("D3DPRESENT_INTERVAL_DEFAULT");
0095:     case D3DPRESENT_INTERVAL_ONE:       return TEXT("D3DPRESENT_INTERVAL_ONE");
0096:     case D3DPRESENT_INTERVAL_TWO:       return TEXT("D3DPRESENT_INTERVAL_TWO");
0097:     case D3DPRESENT_INTERVAL_THREE:     return TEXT("D3DPRESENT_INTERVAL_THREE");
0098:     case D3DPRESENT_INTERVAL_FOUR:      return TEXT("D3DPRESENT_INTERVAL_FOUR");
0099:     default:                            return TEXT("Unknown PresentInterval");
0100:     }
0101: }
0102: 
0103: 
0104: 
0105: 
0106: //-----------------------------------------------------------------------------
0107: // Name: DialogProcHelper
0108: // Desc: 
0109: //-----------------------------------------------------------------------------
0110: INT_PTR CALLBACK DialogProcHelper( HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam )
0111: {
0112:     return s_pSettingsDialog->DialogProc( hDlg, msg, wParam, lParam );
0113: }
0114: 
0115: 
0116: 
0117: 
0118: //-----------------------------------------------------------------------------
0119: // Name: CD3DSettingsDialog constructor
0120: // Desc: 
0121: //-----------------------------------------------------------------------------
0122: CD3DSettingsDialog::CD3DSettingsDialog( CD3DEnumeration* pEnumeration, 
0123:                                         CD3DSettings* pSettings)
0124: {
0125:     s_pSettingsDialog = this;
0126:     m_pEnumeration = pEnumeration;
0127:     m_d3dSettings = *pSettings;
0128: }
0129: 
0130: 
0131: 
0132: 
0133: //-----------------------------------------------------------------------------
0134: // Name: ComboBoxAdd
0135: // Desc: Adds an entry to the combo box.
0136: //-----------------------------------------------------------------------------
0137: void CD3DSettingsDialog::ComboBoxAdd( int id, void* pData, TCHAR* pstrDesc )
0138: {
0139:     HWND hwndCtrl = GetDlgItem( m_hDlg, id );
0140:     DWORD dwItem = ComboBox_AddString( hwndCtrl, pstrDesc );
0141:     ComboBox_SetItemData( hwndCtrl, dwItem, pData );
0142: }
0143: 
0144: 
0145: 
0146: 
0147: //-----------------------------------------------------------------------------
0148: // Name: ComboBoxSelect
0149: // Desc: Selects an entry in the combo box.
0150: //-----------------------------------------------------------------------------
0151: void CD3DSettingsDialog::ComboBoxSelect( int id, void* pData )
0152: {
0153:     HWND hwndCtrl = GetDlgItem( m_hDlg, id );
0154:     UINT count = ComboBoxCount( id );
0155:     for( UINT iItem = 0; iItem < count; iItem++ )
0156:     {
0157:         if( (void*)ComboBox_GetItemData( hwndCtrl, iItem ) == pData )
0158:         {
0159:             ComboBox_SetCurSel( hwndCtrl, iItem );
0160:             PostMessage( m_hDlg, WM_COMMAND, 
0161:                 MAKEWPARAM( id, CBN_SELCHANGE ), (LPARAM)hwndCtrl );
0162:             return;
0163:         }
0164:     }
0165: }
0166: 
0167: 
0168: 
0169: 
0170: //-----------------------------------------------------------------------------
0171: // Name: ComboBoxSelectIndex
0172: // Desc: Selects an entry in the combo box.
0173: //-----------------------------------------------------------------------------
0174: void CD3DSettingsDialog::ComboBoxSelectIndex( int id, int index )
0175: {
0176:     HWND hwndCtrl = GetDlgItem( m_hDlg, id );
0177:     ComboBox_SetCurSel( hwndCtrl, index );
0178:     PostMessage( m_hDlg, WM_COMMAND, MAKEWPARAM( id, CBN_SELCHANGE ), 
0179:         (LPARAM)hwndCtrl );
0180: }
0181: 
0182: 
0183: 
0184: 
0185: //-----------------------------------------------------------------------------
0186: // Name: ComboBoxSelected
0187: // Desc: Returns the data for the selected entry in the combo box.
0188: //-----------------------------------------------------------------------------
0189: void* CD3DSettingsDialog::ComboBoxSelected( int id )
0190: {
0191:     HWND hwndCtrl = GetDlgItem( m_hDlg, id );
0192:     int index = ComboBox_GetCurSel( hwndCtrl );
0193:     if( index < 0 )
0194:         return NULL;
0195:     return (void*)ComboBox_GetItemData( hwndCtrl, index );
0196: }
0197: 
0198: 
0199: 
0200: 
0201: //-----------------------------------------------------------------------------
0202: // Name: ComboBoxSomethingSelected
0203: // Desc: Returns whether any entry in the combo box is selected.  This is 
0204: //       more useful than ComboBoxSelected() when you need to distinguish 
0205: //       between having no item selected vs. having an item selected whose 
0206: //       itemData is NULL.
0207: //-----------------------------------------------------------------------------
0208: bool CD3DSettingsDialog::ComboBoxSomethingSelected( int id )
0209: {
0210:     HWND hwndCtrl = GetDlgItem( m_hDlg, id );
0211:     int index = ComboBox_GetCurSel( hwndCtrl );
0212:     return ( index >= 0 );
0213: }
0214: 
0215: 
0216: 
0217: 
0218: //-----------------------------------------------------------------------------
0219: // Name: ComboBoxCount
0220: // Desc: Returns the number of entries in the combo box.
0221: //-----------------------------------------------------------------------------
0222: UINT CD3DSettingsDialog::ComboBoxCount( int id )
0223: {
0224:     HWND hwndCtrl = GetDlgItem( m_hDlg, id );
0225:     return ComboBox_GetCount( hwndCtrl );
0226: }
0227: 
0228: 
0229: 
0230: 
0231: //-----------------------------------------------------------------------------
0232: // Name: ComboBoxClear
0233: // Desc: Clears the entries in the combo box.
0234: //-----------------------------------------------------------------------------
0235: void CD3DSettingsDialog::ComboBoxClear( int id )
0236: {
0237:     HWND hwndCtrl = GetDlgItem( m_hDlg, id );
0238:     ComboBox_ResetContent( hwndCtrl );
0239: }
0240: 
0241: 
0242: 
0243: 
0244: //-----------------------------------------------------------------------------
0245: // Name: ComboBoxContainsText
0246: // Desc: Returns whether the combo box contains the given text.
0247: //-----------------------------------------------------------------------------
0248: bool CD3DSettingsDialog::ComboBoxContainsText( int id, TCHAR* pstrText )
0249: {
0250:     TCHAR strItem[200];
0251:     HWND hwndCtrl = GetDlgItem( m_hDlg, id );
0252:     UINT count = ComboBoxCount( id );
0253:     for( UINT iItem = 0; iItem < count; iItem++ )
0254:     {
0255:         if( ComboBox_GetLBTextLen( hwndCtrl, iItem ) >= 200 )
0256:             continue; // shouldn't happen, but don't overwrite buffer if it does
0257:         ComboBox_GetLBText( hwndCtrl, iItem, strItem );
0258:         if( lstrcmp( strItem, pstrText ) == 0 )
0259:             return true;
0260:     }
0261:     return false;
0262: }
0263: 
0264: 
0265: 
0266: 
0267: //-----------------------------------------------------------------------------
0268: // Name: ShowDialog
0269: // Desc: Show the D3D settings dialog.
0270: //-----------------------------------------------------------------------------
0271: INT_PTR CD3DSettingsDialog::ShowDialog( HWND hwndParent )
0272: {
0273:     return DialogBox( NULL, MAKEINTRESOURCE( IDD_SELECTDEVICE ), 
0274:         hwndParent, DialogProcHelper );
0275: }
0276: 
0277: 
0278: 
0279: 
0280: //-----------------------------------------------------------------------------
0281: // Name: DialogProc
0282: // Desc: Handle window messages in the dialog.
0283: //-----------------------------------------------------------------------------
0284: INT_PTR CD3DSettingsDialog::DialogProc( HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam )
0285: {
0286:     UNREFERENCED_PARAMETER( lParam );
0287: 
0288:     switch( msg )
0289:     {
0290:     case WM_INITDIALOG:
0291:         {
0292:             m_hDlg = hDlg;
0293: 
0294:             // Fill adapter combo box.  Updating the selected adapter will trigger
0295:             // updates of the rest of the dialog.
0296:             for( UINT iai = 0; iai < m_pEnumeration->m_pAdapterInfoList->Count(); iai++ )
0297:             {
0298:                 D3DAdapterInfo* pAdapterInfo;
0299:                 pAdapterInfo = (D3DAdapterInfo*)m_pEnumeration->m_pAdapterInfoList->GetPtr(iai);
0300:                 TCHAR strDescription[512];
0301:                 DXUtil_ConvertAnsiStringToGenericCch( strDescription, pAdapterInfo->AdapterIdentifier.Description, 512 );
0302:                 ComboBoxAdd( IDC_ADAPTER_COMBO, pAdapterInfo, strDescription );
0303:                 if( pAdapterInfo->AdapterOrdinal == m_d3dSettings.AdapterOrdinal() )
0304:                     ComboBoxSelect( IDC_ADAPTER_COMBO, pAdapterInfo );
0305:             }
0306:             if( !ComboBoxSomethingSelected( IDC_ADAPTER_COMBO ) &&
0307:                 ComboBoxCount( IDC_ADAPTER_COMBO ) > 0 )
0308:             {
0309:                 ComboBoxSelectIndex( IDC_ADAPTER_COMBO, 0 );
0310:             }
0311:         }
0312:         return TRUE;
0313: 
0314:     case WM_COMMAND:
0315:         switch( LOWORD(wParam) )
0316:         {
0317:         case IDOK:
0318:             EndDialog( hDlg, IDOK );
0319:             break;
0320:         case IDCANCEL:
0321:             EndDialog( hDlg, IDCANCEL );
0322:             break;
0323:         case IDC_ADAPTER_COMBO:
0324:             if( CBN_SELCHANGE == HIWORD(wParam) )
0325:                 AdapterChanged();
0326:             break;
0327:         case IDC_DEVICE_COMBO:
0328:             if( CBN_SELCHANGE == HIWORD(wParam) )
0329:                 DeviceChanged();
0330:             break;
0331:         case IDC_ADAPTERFORMAT_COMBO:
0332:             if( CBN_SELCHANGE == HIWORD(wParam) )
0333:                 AdapterFormatChanged();
0334:             break;
0335:         case IDC_RESOLUTION_COMBO:
0336:             if( CBN_SELCHANGE == HIWORD(wParam) )
0337:                 ResolutionChanged();
0338:             break;
0339:         case IDC_REFRESHRATE_COMBO:
0340:             if( CBN_SELCHANGE == HIWORD(wParam) )
0341:                 RefreshRateChanged();
0342:             break;
0343:         case IDC_BACKBUFFERFORMAT_COMBO:
0344:             if( CBN_SELCHANGE == HIWORD(wParam) )
0345:                 BackBufferFormatChanged();
0346:             break;
0347:         case IDC_DEPTHSTENCILBUFFERFORMAT_COMBO:
0348:             if( CBN_SELCHANGE == HIWORD(wParam) )
0349:                 DepthStencilBufferFormatChanged();
0350:             break;
0351:         case IDC_MULTISAMPLE_COMBO:
0352:             if( CBN_SELCHANGE == HIWORD(wParam) )
0353:                 MultisampleTypeChanged();
0354:             break;
0355:         case IDC_MULTISAMPLE_QUALITY_COMBO:
0356:             if( CBN_SELCHANGE == HIWORD(wParam) )
0357:                 MultisampleQualityChanged();
0358:             break;
0359:         case IDC_VERTEXPROCESSING_COMBO:
0360:             if( CBN_SELCHANGE == HIWORD(wParam) )
0361:                 VertexProcessingChanged();
0362:             break;
0363:         case IDC_PRESENTINTERVAL_COMBO:
0364:             if( CBN_SELCHANGE == HIWORD(wParam) )
0365:                 PresentIntervalChanged();
0366:             break;
0367:         case IDC_WINDOW:
0368:         case IDC_FULLSCREEN:
0369:             WindowedFullscreenChanged();
0370:             break;
0371:         }
0372:         return TRUE;
0373: 
0374:     default:
0375:         return FALSE;
0376:     }
0377: }
0378: 
0379: 
0380: 
0381: //-----------------------------------------------------------------------------
0382: // Name: AdapterChanged
0383: // Desc: Respond to a change of selected adapter.
0384: //-----------------------------------------------------------------------------
0385: void CD3DSettingsDialog::AdapterChanged( void )
0386: {
0387:     D3DAdapterInfo* pAdapterInfo = (D3DAdapterInfo*)ComboBoxSelected( IDC_ADAPTER_COMBO );
0388:     if( pAdapterInfo == NULL )
0389:         return;
0390:     
0391:     if( m_d3dSettings.IsWindowed )
0392:         m_d3dSettings.pWindowed_AdapterInfo = pAdapterInfo;
0393:     else
0394:         m_d3dSettings.pFullscreen_AdapterInfo = pAdapterInfo;
0395: 
0396:     // Update device combo box
0397:     ComboBoxClear( IDC_DEVICE_COMBO );
0398:     for( UINT idi = 0; idi < pAdapterInfo->pDeviceInfoList->Count(); idi++ )
0399:     {
0400:         D3DDeviceInfo* pDeviceInfo = (D3DDeviceInfo*)pAdapterInfo->pDeviceInfoList->GetPtr(idi);
0401:         ComboBoxAdd( IDC_DEVICE_COMBO, pDeviceInfo, 
0402:                      D3DDevTypeToString( pDeviceInfo->DevType ) );
0403:         if( pDeviceInfo->DevType == m_d3dSettings.DevType() )
0404:             ComboBoxSelect( IDC_DEVICE_COMBO, pDeviceInfo );
0405:     }
0406:     if( !ComboBoxSomethingSelected( IDC_DEVICE_COMBO ) &&
0407:         ComboBoxCount( IDC_DEVICE_COMBO ) > 0 )
0408:     {
0409:         ComboBoxSelectIndex( IDC_DEVICE_COMBO, 0 );
0410:     }
0411: }
0412: 
0413: 
0414: 
0415: 
0416: //-----------------------------------------------------------------------------
0417: // Name: DeviceChanged
0418: // Desc: Respond to a change of selected device by resetting the 
0419: //       fullscreen/windowed radio buttons.  Updating these buttons will 
0420: //       trigger updates of the rest of the dialog.
0421: //-----------------------------------------------------------------------------
0422: void CD3DSettingsDialog::DeviceChanged( void )
0423: {
0424:     D3DDeviceInfo* pDeviceInfo = (D3DDeviceInfo*)ComboBoxSelected( IDC_DEVICE_COMBO );
0425:     if( pDeviceInfo == NULL )
0426:         return;
0427: 
0428:     if( m_d3dSettings.IsWindowed )
0429:         m_d3dSettings.pWindowed_DeviceInfo = pDeviceInfo;
0430:     else
0431:         m_d3dSettings.pFullscreen_DeviceInfo = pDeviceInfo;
0432: 
0433:     // Update fullscreen/windowed radio buttons
0434:     bool HasWindowedDeviceCombo = false;
0435:     bool HasFullscreenDeviceCombo = false;
0436:     for( UINT idc = 0; idc < pDeviceInfo->pDeviceComboList->Count(); idc++ )
0437:     {
0438:         D3DDeviceCombo* pDeviceCombo = (D3DDeviceCombo*)pDeviceInfo->pDeviceComboList->GetPtr(idc);
0439:         if( pDeviceCombo->IsWindowed )
0440:             HasWindowedDeviceCombo = true;
0441:         else
0442:             HasFullscreenDeviceCombo = true;
0443:     }
0444:     EnableWindow( GetDlgItem( m_hDlg, IDC_WINDOW ), HasWindowedDeviceCombo );
0445:     EnableWindow( GetDlgItem( m_hDlg, IDC_FULLSCREEN ), HasFullscreenDeviceCombo );
0446:     if (m_d3dSettings.IsWindowed && HasWindowedDeviceCombo)
0447:     {
0448:         CheckRadioButton( m_hDlg, IDC_WINDOW, IDC_FULLSCREEN, IDC_WINDOW );
0449:     }
0450:     else
0451:     {
0452:         CheckRadioButton( m_hDlg, IDC_WINDOW, IDC_FULLSCREEN, IDC_FULLSCREEN );
0453:     }
0454:     WindowedFullscreenChanged();
0455: }
0456: 
0457: 
0458: 
0459: 
0460: //-----------------------------------------------------------------------------
0461: // Name: WindowedFullscreenChanged
0462: // Desc: Respond to a change of windowed/fullscreen state by rebuilding the
0463: //       adapter format list, resolution list, and refresh rate list.
0464: //       Updating the selected adapter format will trigger updates of the 
0465: //       rest of the dialog.
0466: //-----------------------------------------------------------------------------
0467: void CD3DSettingsDialog::WindowedFullscreenChanged( void )
0468: {
0469:     D3DAdapterInfo* pAdapterInfo = (D3DAdapterInfo*)ComboBoxSelected( IDC_ADAPTER_COMBO );
0470:     D3DDeviceInfo* pDeviceInfo = (D3DDeviceInfo*)ComboBoxSelected( IDC_DEVICE_COMBO );
0471:     if( pAdapterInfo == NULL || pDeviceInfo == NULL )
0472:         return;
0473: 
0474:     if( IsDlgButtonChecked( m_hDlg, IDC_WINDOW ) )
0475:     {
0476:         m_d3dSettings.IsWindowed = true;
0477:         m_d3dSettings.pWindowed_AdapterInfo = pAdapterInfo;
0478:         m_d3dSettings.pWindowed_DeviceInfo = pDeviceInfo;
0479: 
0480:         // Update adapter format combo box
0481:         ComboBoxClear( IDC_ADAPTERFORMAT_COMBO );
0482:         ComboBoxAdd( IDC_ADAPTERFORMAT_COMBO, (void*)m_d3dSettings.Windowed_DisplayMode.Format,
0483:             D3DUtil_D3DFormatToString( m_d3dSettings.Windowed_DisplayMode.Format ) );
0484:         ComboBoxSelectIndex( IDC_ADAPTERFORMAT_COMBO, 0 );
0485:         EnableWindow( GetDlgItem( m_hDlg, IDC_ADAPTERFORMAT_COMBO ), false );
0486: 
0487:         // Update resolution combo box
0488:         DWORD dwResolutionData;
0489:         TCHAR strResolution[50];
0490:         dwResolutionData = MAKELONG( m_d3dSettings.Windowed_DisplayMode.Width,
0491:                                      m_d3dSettings.Windowed_DisplayMode.Height );
0492:         _sntprintf( strResolution, 50, TEXT("%d by %d"), m_d3dSettings.Windowed_DisplayMode.Width, 
0493:             m_d3dSettings.Windowed_DisplayMode.Height );
0494:         strResolution[49] = 0;
0495:         ComboBoxClear( IDC_RESOLUTION_COMBO );
0496:         ComboBoxAdd( IDC_RESOLUTION_COMBO, ULongToPtr(dwResolutionData), strResolution );
0497:         ComboBoxSelectIndex( IDC_RESOLUTION_COMBO, 0 );
0498:         EnableWindow( GetDlgItem( m_hDlg, IDC_RESOLUTION_COMBO ), false );
0499: 
0500:         // Update refresh rate combo box
0501:         TCHAR strRefreshRate[50];
0502:         if( m_d3dSettings.Windowed_DisplayMode.RefreshRate == 0 )
0503:             lstrcpy( strRefreshRate, TEXT("Default Rate") );
0504:         else
0505:             _sntprintf( strRefreshRate, 50, TEXT("%d Hz"), m_d3dSettings.Windowed_DisplayMode.RefreshRate );
0506:         strRefreshRate[49] = 0;
0507:         ComboBoxClear( IDC_REFRESHRATE_COMBO );
0508:         ComboBoxAdd( IDC_REFRESHRATE_COMBO, ULongToPtr(m_d3dSettings.Windowed_DisplayMode.RefreshRate),
0509:             strRefreshRate );
0510:         ComboBoxSelectIndex( IDC_REFRESHRATE_COMBO, 0 );
0511:         EnableWindow( GetDlgItem( m_hDlg, IDC_REFRESHRATE_COMBO ), false );
0512:     }
0513:     else
0514:     {
0515:         m_d3dSettings.IsWindowed = false;
0516:         m_d3dSettings.pFullscreen_AdapterInfo = pAdapterInfo;
0517:         m_d3dSettings.pFullscreen_DeviceInfo = pDeviceInfo;
0518: 
0519:         // Update adapter format combo box
0520:         ComboBoxClear( IDC_ADAPTERFORMAT_COMBO );
0521:         for( UINT idc = 0; idc < pDeviceInfo->pDeviceComboList->Count(); idc++ )
0522:         {
0523:             D3DDeviceCombo* pDeviceCombo = (D3DDeviceCombo*)pDeviceInfo->pDeviceComboList->GetPtr(idc);
0524:             D3DFORMAT adapterFormat = pDeviceCombo->AdapterFormat;
0525:             if( !ComboBoxContainsText( IDC_ADAPTERFORMAT_COMBO, D3DUtil_D3DFormatToString( adapterFormat ) ) )
0526:             {
0527:                 ComboBoxAdd( IDC_ADAPTERFORMAT_COMBO, (void*)adapterFormat, 
0528:                     D3DUtil_D3DFormatToString( adapterFormat ) );
0529:                 if( adapterFormat == m_d3dSettings.Fullscreen_DisplayMode.Format )
0530:                 {
0531:                     ComboBoxSelect( IDC_ADAPTERFORMAT_COMBO, (void*)adapterFormat );
0532:                 }
0533:             }
0534:         }
0535:         if( !ComboBoxSomethingSelected( IDC_ADAPTERFORMAT_COMBO ) &&
0536:             ComboBoxCount( IDC_ADAPTERFORMAT_COMBO ) > 0 )
0537:         {
0538:             ComboBoxSelectIndex( IDC_ADAPTERFORMAT_COMBO, 0 );
0539:         }
0540:         EnableWindow( GetDlgItem( m_hDlg, IDC_ADAPTERFORMAT_COMBO), true );
0541:         
0542:         // Update resolution combo box
0543:         EnableWindow( GetDlgItem( m_hDlg, IDC_RESOLUTION_COMBO), true );
0544:         
0545:         // Update refresh rate combo box
0546:         EnableWindow( GetDlgItem( m_hDlg, IDC_REFRESHRATE_COMBO), true );
0547:     }
0548: }
0549: 
0550: 
0551: 
0552: 
0553: //-----------------------------------------------------------------------------
0554: // Name: AdapterFormatChanged
0555: // Desc: Respond to a change of selected adapter format by rebuilding the
0556: //       resolution list and back buffer format list.  Updating the selected 
0557: //       resolution and back buffer format will trigger updates of the rest 
0558: //       of the dialog.
0559: //-----------------------------------------------------------------------------
0560: void CD3DSettingsDialog::AdapterFormatChanged( void )
0561: {
0562:     if( !IsDlgButtonChecked( m_hDlg, IDC_WINDOW ) )
0563:     {
0564:         D3DAdapterInfo* pAdapterInfo = (D3DAdapterInfo*)ComboBoxSelected( IDC_ADAPTER_COMBO );
0565:         D3DFORMAT adapterFormat = (D3DFORMAT)PtrToUlong( ComboBoxSelected( IDC_ADAPTERFORMAT_COMBO ) );
0566:         m_d3dSettings.Fullscreen_DisplayMode.Format = adapterFormat;
0567: 
0568:         ComboBoxClear( IDC_RESOLUTION_COMBO );
0569:         for( UINT idm = 0; idm < pAdapterInfo->pDisplayModeList->Count(); idm++ )
0570:         {
0571:             D3DDISPLAYMODE displayMode = *(D3DDISPLAYMODE*)pAdapterInfo->pDisplayModeList->GetPtr(idm);
0572:             if (displayMode.Format == adapterFormat)
0573:             {
0574:                 DWORD dwResolutionData;
0575:                 TCHAR strResolution[50];
0576:                 dwResolutionData = MAKELONG( displayMode.Width, displayMode.Height );
0577:                 _sntprintf( strResolution, 50, TEXT("%d by %d"), displayMode.Width, displayMode.Height );
0578:                 strResolution[49] = 0;
0579:                 if (!ComboBoxContainsText( IDC_RESOLUTION_COMBO, strResolution ) )
0580:                 {
0581:                     ComboBoxAdd( IDC_RESOLUTION_COMBO, ULongToPtr( dwResolutionData ), strResolution );
0582:                     if (m_d3dSettings.Fullscreen_DisplayMode.Width == displayMode.Width &&
0583:                         m_d3dSettings.Fullscreen_DisplayMode.Height == displayMode.Height)
0584:                     {
0585:                         ComboBoxSelect( IDC_RESOLUTION_COMBO, ULongToPtr( dwResolutionData ) );
0586:                     }
0587:                 }
0588:             }
0589:         }
0590:         if (!ComboBoxSomethingSelected( IDC_RESOLUTION_COMBO ) && 
0591:             ComboBoxCount( IDC_RESOLUTION_COMBO ) > 0)
0592:         {
0593:             ComboBoxSelectIndex( IDC_RESOLUTION_COMBO, 0 );
0594:         }
0595:     }
0596: 
0597:     // Update backbuffer format combo box
0598:     D3DDeviceInfo* pDeviceInfo = (D3DDeviceInfo*)ComboBoxSelected( IDC_DEVICE_COMBO );
0599:     if( pDeviceInfo == NULL )
0600:         return;
0601:     ComboBoxClear( IDC_BACKBUFFERFORMAT_COMBO );
0602:     for( UINT idc = 0; idc < pDeviceInfo->pDeviceComboList->Count(); idc++ )
0603:     {
0604:         D3DDeviceCombo* pDeviceCombo = (D3DDeviceCombo*)pDeviceInfo->pDeviceComboList->GetPtr(idc);
0605:         if (pDeviceCombo->IsWindowed == m_d3dSettings.IsWindowed &&
0606:             pDeviceCombo->AdapterFormat == m_d3dSettings.DisplayMode().Format)
0607:         {
0608:             if (!ComboBoxContainsText( IDC_BACKBUFFERFORMAT_COMBO, 
0609:                 D3DUtil_D3DFormatToString( pDeviceCombo->BackBufferFormat ) ) )
0610:             {
0611:                 ComboBoxAdd( IDC_BACKBUFFERFORMAT_COMBO, (void*)pDeviceCombo->BackBufferFormat,
0612:                     D3DUtil_D3DFormatToString( pDeviceCombo->BackBufferFormat ) );
0613:                 if (pDeviceCombo->BackBufferFormat == m_d3dSettings.BackBufferFormat() )
0614:                     ComboBoxSelect( IDC_BACKBUFFERFORMAT_COMBO, (void*)pDeviceCombo->BackBufferFormat );
0615:             }
0616:         }
0617:     }
0618:     if (!ComboBoxSomethingSelected( IDC_BACKBUFFERFORMAT_COMBO ) && 
0619:         ComboBoxCount( IDC_BACKBUFFERFORMAT_COMBO ) > 0)
0620:     {
0621:         ComboBoxSelectIndex( IDC_BACKBUFFERFORMAT_COMBO, 0 );
0622:     }
0623: }
0624: 
0625: 
0626: 
0627: 
0628: //-----------------------------------------------------------------------------
0629: // Name: ResolutionChanged
0630: // Desc: Respond to a change of selected resolution by rebuilding the
0631: //       refresh rate list.
0632: //-----------------------------------------------------------------------------
0633: void CD3DSettingsDialog::ResolutionChanged( void )
0634: {
0635:     if (m_d3dSettings.IsWindowed)
0636:         return;
0637: 
0638:     D3DAdapterInfo* pAdapterInfo = (D3DAdapterInfo*)ComboBoxSelected( IDC_ADAPTER_COMBO );
0639:     if( pAdapterInfo == NULL )
0640:         return;
0641: 
0642:     // Update settingsNew with new resolution
0643:     DWORD dwResolutionData = PtrToUlong( ComboBoxSelected( IDC_RESOLUTION_COMBO ) );
0644:     UINT width = LOWORD( dwResolutionData );
0645:     UINT height = HIWORD( dwResolutionData );
0646:     m_d3dSettings.Fullscreen_DisplayMode.Width = width;
0647:     m_d3dSettings.Fullscreen_DisplayMode.Height = height;
0648: 
0649:     // Update refresh rate list based on new resolution
0650:     D3DFORMAT adapterFormat = (D3DFORMAT)PtrToUlong( ComboBoxSelected( IDC_ADAPTERFORMAT_COMBO ) );
0651:     ComboBoxClear( IDC_REFRESHRATE_COMBO );
0652:     for( UINT idm = 0; idm < pAdapterInfo->pDisplayModeList->Count(); idm++ )
0653:     {
0654:         D3DDISPLAYMODE displayMode = *(D3DDISPLAYMODE*)pAdapterInfo->pDisplayModeList->GetPtr(idm);
0655:         if (displayMode.Format == adapterFormat &&
0656:             displayMode.Width  == width &&
0657:             displayMode.Height == height)
0658:         {
0659:             TCHAR strRefreshRate[50];
0660:             if( displayMode.RefreshRate == 0 )
0661:                 lstrcpy( strRefreshRate, TEXT("Default Rate") );
0662:             else
0663:                 _sntprintf( strRefreshRate, 50, TEXT("%d Hz"), displayMode.RefreshRate );
0664:             strRefreshRate[49] = 0;
0665:             if( !ComboBoxContainsText( IDC_REFRESHRATE_COMBO, strRefreshRate ) )
0666:             {
0667:                 ComboBoxAdd( IDC_REFRESHRATE_COMBO, UlongToPtr( displayMode.RefreshRate ), strRefreshRate );
0668:                 if (m_d3dSettings.Fullscreen_DisplayMode.RefreshRate == displayMode.RefreshRate)
0669:                     ComboBoxSelect( IDC_REFRESHRATE_COMBO, UlongToPtr( displayMode.RefreshRate ) );
0670:             }
0671:         }
0672:     }
0673:     if (!ComboBoxSomethingSelected( IDC_REFRESHRATE_COMBO ) && 
0674:         ComboBoxCount( IDC_REFRESHRATE_COMBO ) > 0)
0675:     {
0676:         ComboBoxSelectIndex( IDC_REFRESHRATE_COMBO, 0 );
0677:     }
0678: }
0679: 
0680: 
0681: 
0682: 
0683: //-----------------------------------------------------------------------------
0684: // Name: RefreshRateChanged
0685: // Desc: Respond to a change of selected refresh rate.
0686: //-----------------------------------------------------------------------------
0687: void CD3DSettingsDialog::RefreshRateChanged( void )
0688: {
0689:     if( m_d3dSettings.IsWindowed )
0690:         return;
0691: 
0692:     // Update settingsNew with new refresh rate
0693:     UINT refreshRate = PtrToUlong( ComboBoxSelected( IDC_REFRESHRATE_COMBO ) );
0694:     m_d3dSettings.Fullscreen_DisplayMode.RefreshRate = refreshRate;
0695: }
0696: 
0697: 
0698: 
0699: 
0700: //-----------------------------------------------------------------------------
0701: // Name: BackBufferFormatChanged
0702: // Desc: Respond to a change of selected back buffer format by rebuilding
0703: //       the depth/stencil format list, multisample type list, and vertex
0704: //       processing type list.
0705: //-----------------------------------------------------------------------------
0706: void CD3DSettingsDialog::BackBufferFormatChanged( void )
0707: {
0708:     D3DDeviceInfo* pDeviceInfo = (D3DDeviceInfo*)ComboBoxSelected( IDC_DEVICE_COMBO );
0709:     D3DFORMAT adapterFormat = (D3DFORMAT)PtrToUlong( ComboBoxSelected( IDC_ADAPTERFORMAT_COMBO ) );
0710:     D3DFORMAT backBufferFormat = (D3DFORMAT)PtrToUlong( ComboBoxSelected( IDC_BACKBUFFERFORMAT_COMBO ) );
0711:     if( pDeviceInfo == NULL )
0712:         return;
0713: 
0714:     for( UINT idc = 0; idc < pDeviceInfo->pDeviceComboList->Count(); idc++ )
0715:     {
0716:         D3DDeviceCombo* pDeviceCombo = (D3DDeviceCombo*)pDeviceInfo->pDeviceComboList->GetPtr(idc);
0717:         if (pDeviceCombo->IsWindowed == m_d3dSettings.IsWindowed &&
0718:             pDeviceCombo->AdapterFormat == adapterFormat &&
0719:             pDeviceCombo->BackBufferFormat == backBufferFormat)
0720:         {
0721:             if( m_d3dSettings.IsWindowed )
0722:                 m_d3dSettings.pWindowed_DeviceCombo = pDeviceCombo;
0723:             else
0724:                 m_d3dSettings.pFullscreen_DeviceCombo = pDeviceCombo;
0725: 
0726:             ComboBoxClear( IDC_DEPTHSTENCILBUFFERFORMAT_COMBO );
0727:             if( m_pEnumeration->AppUsesDepthBuffer )
0728:             {
0729:                 for( UINT ifmt = 0; ifmt < pDeviceCombo->pDepthStencilFormatList->Count(); ifmt++ )
0730:                 {
0731:                     D3DFORMAT fmt = *(D3DFORMAT*)pDeviceCombo->pDepthStencilFormatList->GetPtr(ifmt);
0732:                     ComboBoxAdd( IDC_DEPTHSTENCILBUFFERFORMAT_COMBO, (void*)fmt, 
0733:                         D3DUtil_D3DFormatToString(fmt) );
0734:                     if( fmt == m_d3dSettings.DepthStencilBufferFormat() )
0735:                         ComboBoxSelect( IDC_DEPTHSTENCILBUFFERFORMAT_COMBO, (void*)fmt );
0736:                 }
0737:                 if (!ComboBoxSomethingSelected( IDC_DEPTHSTENCILBUFFERFORMAT_COMBO ) && 
0738:                     ComboBoxCount( IDC_DEPTHSTENCILBUFFERFORMAT_COMBO ) > 0)
0739:                 {
0740:                     ComboBoxSelectIndex( IDC_DEPTHSTENCILBUFFERFORMAT_COMBO, 0 );
0741:                 }
0742:             }
0743:             else
0744:             {
0745:                 EnableWindow( GetDlgItem( m_hDlg, IDC_DEPTHSTENCILBUFFERFORMAT_COMBO ), false );
0746:                 ComboBoxAdd( IDC_DEPTHSTENCILBUFFERFORMAT_COMBO, NULL, TEXT("(not used)") );
0747:                 ComboBoxSelectIndex( IDC_DEPTHSTENCILBUFFERFORMAT_COMBO, 0 );
0748:             }
0749: 
0750:             ComboBoxClear( IDC_VERTEXPROCESSING_COMBO );
0751:             for( UINT ivpt = 0; ivpt < pDeviceCombo->pVertexProcessingTypeList->Count(); ivpt++ )
0752:             {
0753:                 VertexProcessingType vpt = *(VertexProcessingType*)pDeviceCombo->pVertexProcessingTypeList->GetPtr(ivpt);
0754:                 ComboBoxAdd( IDC_VERTEXPROCESSING_COMBO, (void*)vpt, VertexProcessingTypeToString(vpt) );
0755:                 if( vpt == m_d3dSettings.GetVertexProcessingType() )
0756:                     ComboBoxSelect( IDC_VERTEXPROCESSING_COMBO, (void*)vpt );
0757:             }
0758:             if (!ComboBoxSomethingSelected( IDC_VERTEXPROCESSING_COMBO ) && 
0759:                 ComboBoxCount( IDC_VERTEXPROCESSING_COMBO ) > 0)
0760:             {
0761:                 ComboBoxSelectIndex( IDC_VERTEXPROCESSING_COMBO, 0 );
0762:             }
0763: 
0764:             ComboBoxClear( IDC_PRESENTINTERVAL_COMBO );
0765:             for( UINT ipi = 0; ipi < pDeviceCombo->pPresentIntervalList->Count(); ipi++ )
0766:             {
0767:                 UINT pi = *(UINT*)pDeviceCombo->pPresentIntervalList->GetPtr(ipi);
0768:                 ComboBoxAdd( IDC_PRESENTINTERVAL_COMBO, UlongToPtr( pi ), PresentIntervalToString(pi) );
0769:                 if( pi == m_d3dSettings.PresentInterval() )
0770:                     ComboBoxSelect( IDC_PRESENTINTERVAL_COMBO, UlongToPtr( pi ) );
0771:             }
0772:             if (!ComboBoxSomethingSelected( IDC_PRESENTINTERVAL_COMBO ) && 
0773:                 ComboBoxCount( IDC_PRESENTINTERVAL_COMBO ) > 0)
0774:             {
0775:                 ComboBoxSelectIndex( IDC_PRESENTINTERVAL_COMBO, 0 );
0776:             }
0777: 
0778:             break;
0779:         }
0780:     }
0781: }
0782: 
0783: 
0784: 
0785: 
0786: //-----------------------------------------------------------------------------
0787: // Name: DepthStencilBufferFormatChanged
0788: // Desc: Respond to a change of selected depth/stencil buffer format.
0789: //-----------------------------------------------------------------------------
0790: void CD3DSettingsDialog::DepthStencilBufferFormatChanged( void )
0791: {
0792:     D3DFORMAT fmt = (D3DFORMAT)PtrToUlong( ComboBoxSelected( IDC_DEPTHSTENCILBUFFERFORMAT_COMBO ) );
0793:     if( m_pEnumeration->AppUsesDepthBuffer )
0794:         m_d3dSettings.SetDepthStencilBufferFormat( fmt );
0795: 
0796:     // Build multisample list
0797:     D3DDeviceCombo* pDeviceCombo = m_d3dSettings.PDeviceCombo();
0798:     ComboBoxClear( IDC_MULTISAMPLE_COMBO );
0799:     for( UINT ims = 0; ims < pDeviceCombo->pMultiSampleTypeList->Count(); ims++ )
0800:     {
0801:         D3DMULTISAMPLE_TYPE msType = *(D3DMULTISAMPLE_TYPE*)pDeviceCombo->pMultiSampleTypeList->GetPtr(ims);
0802: 
0803:         // check for DS/MS conflicts
0804:         BOOL bConflictFound = FALSE;
0805:         for( UINT iConf = 0; iConf < pDeviceCombo->pDSMSConflictList->Count(); iConf++ )
0806:         {
0807:             D3DDSMSConflict* pDSMSConf = (D3DDSMSConflict*)pDeviceCombo->pDSMSConflictList->GetPtr(iConf);
0808:             if( pDSMSConf->DSFormat == fmt && pDSMSConf->MSType == msType )
0809:             {
0810:                 bConflictFound = TRUE;
0811:                 break;
0812:             }
0813:         }
0814:         if( !bConflictFound )
0815:         {
0816:             ComboBoxAdd( IDC_MULTISAMPLE_COMBO, (void*)msType, MultisampleTypeToString(msType) );
0817:             if( msType == m_d3dSettings.MultisampleType() )
0818:                 ComboBoxSelect( IDC_MULTISAMPLE_COMBO, (void*)msType );
0819:         }
0820:     }
0821:     if (!ComboBoxSomethingSelected( IDC_MULTISAMPLE_COMBO ) && 
0822:         ComboBoxCount( IDC_MULTISAMPLE_COMBO ) > 0)
0823:     {
0824:         ComboBoxSelectIndex( IDC_MULTISAMPLE_COMBO, 0 );
0825:     }
0826: }
0827: 
0828: 
0829: 
0830: 
0831: 
0832: //-----------------------------------------------------------------------------
0833: // Name: MultisampleTypeChanged
0834: // Desc: Respond to a change of selected multisample type.
0835: //-----------------------------------------------------------------------------
0836: void CD3DSettingsDialog::MultisampleTypeChanged( void )
0837: {
0838:     D3DMULTISAMPLE_TYPE mst = (D3DMULTISAMPLE_TYPE)PtrToUlong( ComboBoxSelected( IDC_MULTISAMPLE_COMBO ) );
0839:     m_d3dSettings.SetMultisampleType( mst );
0840: 
0841:     // Set up max quality for this mst
0842:     D3DDeviceCombo* pDeviceCombo = m_d3dSettings.PDeviceCombo();
0843:     DWORD maxQuality = 0;
0844: 
0845:     for( UINT ims = 0; ims < pDeviceCombo->pMultiSampleTypeList->Count(); ims++ )
0846:     {
0847:         D3DMULTISAMPLE_TYPE msType = *(D3DMULTISAMPLE_TYPE*)pDeviceCombo->pMultiSampleTypeList->GetPtr(ims);
0848:         if( msType == mst )
0849:         {
0850:             maxQuality = *(DWORD*)pDeviceCombo->pMultiSampleQualityList->GetPtr(ims);
0851:             break;
0852:         }
0853:     }
0854: 
0855:     ComboBoxClear( IDC_MULTISAMPLE_QUALITY_COMBO );
0856:     for( UINT msq = 0; msq < maxQuality; msq++ )
0857:     {
0858:         TCHAR str[100];
0859:         wsprintf( str, TEXT("%d"), msq );
0860:         ComboBoxAdd( IDC_MULTISAMPLE_QUALITY_COMBO, UlongToPtr( msq ), str );
0861:         if( msq == m_d3dSettings.MultisampleQuality() )
0862:             ComboBoxSelect( IDC_MULTISAMPLE_QUALITY_COMBO, UlongToPtr( msq ) );
0863:     }
0864:     if (!ComboBoxSomethingSelected( IDC_MULTISAMPLE_QUALITY_COMBO ) && 
0865:         ComboBoxCount( IDC_MULTISAMPLE_QUALITY_COMBO ) > 0)
0866:     {
0867:         ComboBoxSelectIndex( IDC_MULTISAMPLE_QUALITY_COMBO, 0 );
0868:     }
0869: }
0870: 
0871: 
0872: 
0873: 
0874: //-----------------------------------------------------------------------------
0875: // Name: MultisampleQualityChanged
0876: // Desc: Respond to a change of selected multisample quality.
0877: //-----------------------------------------------------------------------------
0878: void CD3DSettingsDialog::MultisampleQualityChanged( void )
0879: {
0880:     DWORD msq = (DWORD)PtrToUlong( ComboBoxSelected( IDC_MULTISAMPLE_QUALITY_COMBO ) );
0881:     m_d3dSettings.SetMultisampleQuality( msq );
0882: }
0883: 
0884: 
0885: 
0886: 
0887: //-----------------------------------------------------------------------------
0888: // Name: VertexProcessingChanged
0889: // Desc: Respond to a change of selected vertex processing type.
0890: //-----------------------------------------------------------------------------
0891: void CD3DSettingsDialog::VertexProcessingChanged( void )
0892: {
0893:     VertexProcessingType vpt = (VertexProcessingType)PtrToUlong( ComboBoxSelected( IDC_VERTEXPROCESSING_COMBO ) );
0894:     m_d3dSettings.SetVertexProcessingType( vpt );
0895: }
0896: 
0897: 
0898: 
0899: 
0900: //-----------------------------------------------------------------------------
0901: // Name: PresentIntervalChanged
0902: // Desc: Respond to a change of selected present interval.
0903: //-----------------------------------------------------------------------------
0904: void CD3DSettingsDialog::PresentIntervalChanged( void )
0905: {
0906:     UINT pi = PtrToUlong( ComboBoxSelected( IDC_PRESENTINTERVAL_COMBO ) );
0907:     m_d3dSettings.SetPresentInterval( pi );
0908: }
0909: