home *** CD-ROM | disk | FTP | other *** search
/ Beginning Direct3D Game Programming / Direct3D.iso / directx / dxf / samples / multimedia / directsound / voicemanagement / voicemanagement.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2000-11-04  |  24.3 KB  |  680 lines

  1. //----------------------------------------------------------------------------
  2. // File: VoiceManagement.cpp
  3. //
  4. // Desc: Main application file for the VoiceManagement sample. 
  5. //
  6. // Copyright (c) 1999-2000 Microsoft Corp. All rights reserved.
  7. //-----------------------------------------------------------------------------
  8. #define STRICT
  9. #include <windows.h>
  10. #include <basetsd.h>
  11. #include <commdlg.h>
  12. #include <commctrl.h>
  13. #include <mmreg.h>
  14. #include <dxerr8.h>
  15. #include <dsound.h>
  16. #include "resource.h"
  17. #include "DSUtil.h"
  18. #include "DXUtil.h"
  19.  
  20.  
  21.  
  22.  
  23. //-----------------------------------------------------------------------------
  24. // Function-prototypes
  25. //-----------------------------------------------------------------------------
  26. INT_PTR CALLBACK MainDlgProc( HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam );
  27. VOID OnInitDialog( HWND hDlg );
  28. VOID OnOpenSoundFile( HWND hDlg );
  29. HRESULT OnPlaySound( HWND hDlg );
  30. VOID OnTimer( HWND hDlg );
  31. VOID EnablePlayUI( HWND hDlg, BOOL bShowPlayControl );
  32. VOID EnableManagementFlags( HWND hDlg, BOOL bShowFlags );
  33. VOID UpdateBehaviorText( HWND hDlg );
  34. VOID SetFileUI( HWND hDlg, TCHAR* strFileName );
  35.  
  36.  
  37.  
  38.  
  39. //-----------------------------------------------------------------------------
  40. // Defines, constants, and global variables
  41. //-----------------------------------------------------------------------------
  42. CSoundManager* g_pSoundManager = NULL;
  43. CSound*        g_pSound = NULL;
  44.  
  45.  
  46.  
  47.  
  48. //-----------------------------------------------------------------------------
  49. // Name: WinMain()
  50. // Desc: Entry point for the application.  Since we use a simple dialog for 
  51. //       user interaction we don't need to pump messages.
  52. //-----------------------------------------------------------------------------
  53. INT APIENTRY WinMain( HINSTANCE hInst, HINSTANCE hPrevInst, LPSTR pCmdLine, 
  54.                       INT nCmdShow )
  55. {
  56.     InitCommonControls();
  57.  
  58.     // Display the main dialog box.
  59.     DialogBox( hInst, MAKEINTRESOURCE(IDD_MAIN), NULL, MainDlgProc );
  60.  
  61.     return TRUE;
  62. }
  63.  
  64.  
  65.  
  66.  
  67. //-----------------------------------------------------------------------------
  68. // Name: MainDlgProc()
  69. // Desc: Handles dialog messages
  70. //-----------------------------------------------------------------------------
  71. INT_PTR CALLBACK MainDlgProc( HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam )
  72. {
  73.     HRESULT hr;
  74.  
  75.     switch( msg ) 
  76.     {
  77.         case WM_INITDIALOG:
  78.             OnInitDialog( hDlg ); 
  79.             break;
  80.  
  81.         case WM_COMMAND:
  82.             switch( LOWORD(wParam) )
  83.             {
  84.                 case IDC_SOUNDFILE:
  85.                     OnOpenSoundFile( hDlg );
  86.                     break;
  87.  
  88.                 case IDCANCEL:
  89.                     EndDialog( hDlg, IDCANCEL );
  90.                     break;
  91.  
  92.                 case IDC_PLAY:
  93.                     // The 'play' button was pressed
  94.                     if( FAILED( hr = OnPlaySound( hDlg ) ) )
  95.                     {
  96.                         DXTRACE_ERR( TEXT("OnPlaySound"), hr );
  97.                         MessageBox( hDlg, "Error playing DirectSound buffer."
  98.                                     "Sample will now exit.", "DirectSound Sample", 
  99.                                     MB_OK | MB_ICONERROR );
  100.                         EndDialog( hDlg, IDABORT );
  101.                     }
  102.                     break;
  103.  
  104.                 case IDC_STOP:
  105.                     if( g_pSound )
  106.                     {
  107.                         g_pSound->Stop();
  108.                         g_pSound->Reset();
  109.                     }
  110.  
  111.                     EnablePlayUI( hDlg, TRUE );
  112.                     break;
  113.  
  114.                 case IDC_ALLOC_HARDWARE:
  115.                 case IDC_ALLOC_EITHER:
  116.                     EnableManagementFlags( hDlg, TRUE );
  117.                     UpdateBehaviorText( hDlg );
  118.                     break;
  119.  
  120.                 case IDC_ALLOC_SOFTWARE:
  121.                     EnableManagementFlags( hDlg, FALSE );
  122.                     UpdateBehaviorText( hDlg );
  123.                     break;
  124.  
  125.                 case IDC_BYTIME:
  126.                     if( IsDlgButtonChecked( hDlg, IDC_BYTIME ) == BST_CHECKED ) 
  127.                         CheckDlgButton( hDlg, IDC_BYDISTANCE, BST_UNCHECKED );
  128.                     UpdateBehaviorText( hDlg );
  129.                     break;
  130.  
  131.                 case IDC_BYDISTANCE:
  132.                     if( IsDlgButtonChecked( hDlg, IDC_BYDISTANCE ) == BST_CHECKED ) 
  133.                         CheckDlgButton( hDlg, IDC_BYTIME, BST_UNCHECKED );
  134.                     UpdateBehaviorText( hDlg );
  135.                     break;
  136.                     
  137.                 case IDC_BYPRIORTY:
  138.                     UpdateBehaviorText( hDlg );
  139.                     break;
  140.  
  141.                 default:
  142.                     return FALSE; // Didn't handle message
  143.             }
  144.             break;
  145.  
  146.         case WM_TIMER:
  147.             OnTimer( hDlg );
  148.             break;
  149.  
  150.         case WM_DESTROY:
  151.             // Cleanup everything
  152.             KillTimer( hDlg, 1 );    
  153.             SAFE_DELETE( g_pSound );
  154.             SAFE_DELETE( g_pSoundManager );
  155.             break; 
  156.  
  157.         default:
  158.             return FALSE; // Didn't handle message
  159.     }
  160.  
  161.     return TRUE; // Handled message
  162. }
  163.  
  164.  
  165.  
  166.  
  167. //-----------------------------------------------------------------------------
  168. // Name: OnInitDialog()
  169. // Desc: Initializes the dialogs (sets up UI controls, etc.)
  170. //-----------------------------------------------------------------------------
  171. VOID OnInitDialog( HWND hDlg )
  172. {
  173.     HRESULT hr;
  174.  
  175.     // Load the icon
  176. #ifdef _WIN64
  177.     HINSTANCE hInst = (HINSTANCE) GetWindowLongPtr( hDlg, GWLP_HINSTANCE );
  178. #else
  179.     HINSTANCE hInst = (HINSTANCE) GetWindowLong( hDlg, GWL_HINSTANCE );
  180. #endif
  181.     HICON hIcon = LoadIcon( hInst, MAKEINTRESOURCE( IDR_MAINFRAME ) );
  182.  
  183.     // Create a static IDirectSound in the CSound class.  
  184.     // Set coop level to DSSCL_PRIORITY, and set primary buffer 
  185.     // format to stereo, 22kHz and 16-bit output.
  186.     g_pSoundManager = new CSoundManager();
  187.  
  188.     if( FAILED( hr = g_pSoundManager->Initialize( hDlg, DSSCL_PRIORITY, 2, 22050, 16 ) ) )
  189.     {
  190.         DXTRACE_ERR( TEXT("Initialize"), hr );
  191.         MessageBox( hDlg, "Error initializing DirectSound.  Sample will now exit.", 
  192.                             "DirectSound Sample", MB_OK | MB_ICONERROR );
  193.         EndDialog( hDlg, IDABORT );
  194.         return;
  195.     }
  196.  
  197.     // Check the 'hardware' voice allocation button by default. 
  198.     CheckRadioButton( hDlg, IDC_ALLOC_EITHER, IDC_ALLOC_SOFTWARE, IDC_ALLOC_EITHER );
  199.  
  200.     HWND hEditPri = GetDlgItem( hDlg, IDC_EDIT_PRIORITY );
  201.     HWND hSpinPri = GetDlgItem( hDlg, IDC_SPIN_PRIORITY );
  202.     SendMessage( hSpinPri, UDM_SETBUDDY, (WPARAM) hEditPri, 0 );
  203.     SendMessage( hSpinPri, UDM_SETRANGE, 0, MAKELONG (0x7FFF, 0) );
  204.     SendMessage( hSpinPri, UDM_SETPOS, 0, 0 );
  205.     SendMessage( hEditPri, EM_LIMITTEXT, 5, 0 );
  206.  
  207.     // Set the icon for this dialog.
  208.     PostMessage( hDlg, WM_SETICON, ICON_BIG,   (LPARAM) hIcon );  // Set big icon
  209.     PostMessage( hDlg, WM_SETICON, ICON_SMALL, (LPARAM) hIcon );  // Set small icon
  210.  
  211.     // Create a timer, so we can check for when the soundbuffer is stopped
  212.     SetTimer( hDlg, 0, 250, NULL );
  213.  
  214.     // Set the UI controls
  215.     UpdateBehaviorText( hDlg );
  216.     SetDlgItemText( hDlg, IDC_FILENAME, TEXT("No file loaded.") );
  217. }
  218.  
  219.  
  220.  
  221.  
  222. //-----------------------------------------------------------------------------
  223. // Name: OnOpenSoundFile()
  224. // Desc: Called when the user requests to open a sound file
  225. //-----------------------------------------------------------------------------
  226. VOID OnOpenSoundFile( HWND hDlg ) 
  227. {
  228.     HRESULT hr;
  229.  
  230.     static TCHAR strFileName[MAX_PATH] = TEXT("");
  231.     static TCHAR strPath[MAX_PATH] = TEXT("");
  232.  
  233.     // Setup the OPENFILENAME structure
  234.     OPENFILENAME ofn = { sizeof(OPENFILENAME), hDlg, NULL,
  235.                          TEXT("Wave Files\0*.wav\0All Files\0*.*\0\0"), NULL,
  236.                          0, 1, strFileName, MAX_PATH, NULL, 0, strPath,
  237.                          TEXT("Open Sound File"),
  238.                          OFN_FILEMUSTEXIST|OFN_HIDEREADONLY, 0, 0,
  239.                          TEXT(".wav"), 0, NULL, NULL };
  240.  
  241.     // Get the default media path (something like C:\WINDOWS\MEDIA)
  242.     if( '\0' == strPath[0] )
  243.     {
  244.         GetWindowsDirectory( strPath, MAX_PATH );
  245.         if( strcmp( &strPath[strlen(strPath)], TEXT("\\") ) )
  246.             strcat( strPath, TEXT("\\") );
  247.         strcat( strPath, TEXT("MEDIA") );
  248.     }
  249.  
  250.     if( g_pSound )
  251.     {
  252.         g_pSound->Stop();
  253.         g_pSound->Reset();
  254.     }
  255.  
  256.     // Update the UI controls to show the sound as loading a file
  257.     EnableWindow(  GetDlgItem( hDlg, IDC_PLAY ), FALSE);
  258.     EnableWindow(  GetDlgItem( hDlg, IDC_STOP ), FALSE);
  259.     SetDlgItemText( hDlg, IDC_FILENAME, TEXT("Loading file...") );
  260.  
  261.     // Display the OpenFileName dialog. Then, try to load the specified file
  262.     if( TRUE != GetOpenFileName( &ofn ) )
  263.     {
  264.         SetDlgItemText( hDlg, IDC_FILENAME, TEXT("Load aborted.") );
  265.         return;
  266.     }
  267.  
  268.     SetDlgItemText( hDlg, IDC_FILENAME, TEXT("") );
  269.  
  270.     // Free any previous sound, and make a new one
  271.     SAFE_DELETE( g_pSound );
  272.  
  273.     // Load the wave file into a DirectSound buffer
  274.     if( FAILED( hr = g_pSoundManager->Create( &g_pSound, strFileName, 
  275.                                          DSBCAPS_LOCDEFER, GUID_NULL ) ) )
  276.     {
  277.         // Not a critical failure, so just update the status
  278.         DXTRACE_ERR_NOMSGBOX( TEXT("Create"), hr );
  279.         SetDlgItemText( hDlg, IDC_FILENAME, TEXT("Could not create sound buffer.") );
  280.         return; 
  281.     }
  282.  
  283.     // Update the UI controls to show the sound as the file is loaded
  284.     SetDlgItemText( hDlg, IDC_FILENAME, strFileName );
  285.     EnablePlayUI( hDlg, TRUE );
  286.  
  287.     // Remember the path for next time
  288.     strcpy( strPath, strFileName );
  289.     char* strLastSlash = strrchr( strPath, '\\' );
  290.     strLastSlash[0] = '\0';
  291. }
  292.  
  293.  
  294.  
  295.  
  296. //-----------------------------------------------------------------------------
  297. // Name: OnPlaySound()
  298. // Desc: User hit the "Play" button
  299. //-----------------------------------------------------------------------------
  300. HRESULT OnPlaySound( HWND hDlg ) 
  301. {
  302.     HRESULT hr;
  303.     LONG    lPriority;
  304.     DWORD   dwPlayFlags;
  305.     BOOL    bLooped;
  306.     BOOL    bAllocHW;
  307.     BOOL    bAllocSW;
  308.     BOOL    bAllocEither;
  309.     BOOL    bByTime;
  310.     BOOL    bByDistance;
  311.     BOOL    bByPriority;
  312.  
  313.     bLooped = ( IsDlgButtonChecked( hDlg, IDC_LOOP_CHECK ) == BST_CHECKED );
  314.  
  315.     // Detrimine where the buffer would like to be allocated 
  316.     bAllocHW     = ( IsDlgButtonChecked( hDlg, IDC_ALLOC_HARDWARE ) == BST_CHECKED );
  317.     bAllocSW     = ( IsDlgButtonChecked( hDlg, IDC_ALLOC_SOFTWARE ) == BST_CHECKED );
  318.     bAllocEither = ( IsDlgButtonChecked( hDlg, IDC_ALLOC_EITHER   ) == BST_CHECKED );
  319.  
  320.     if( bAllocHW || bAllocEither )
  321.     {
  322.         // Detrimine how the buffer should steal hardware resources (if they are not available)
  323.         bByTime      = ( IsDlgButtonChecked( hDlg, IDC_BYTIME     ) == BST_CHECKED );
  324.         bByDistance  = ( IsDlgButtonChecked( hDlg, IDC_BYDISTANCE ) == BST_CHECKED );
  325.         bByPriority  = ( IsDlgButtonChecked( hDlg, IDC_BYPRIORTY  ) == BST_CHECKED );
  326.     }
  327.     else
  328.     {
  329.         // Buffers running in software are not allowed to have
  330.         // voice management flags since they have no need to 
  331.         // steal hardware resources.
  332.         bByTime      = FALSE;
  333.         bByDistance  = FALSE;
  334.         bByPriority  = FALSE;
  335.     }
  336.  
  337.     // Get the buffer priority
  338.     TCHAR strText[MAX_PATH];
  339.     GetDlgItemText( hDlg, IDC_EDIT_PRIORITY, strText, MAX_PATH );
  340.     lPriority = atol( strText );
  341.  
  342.     if( lPriority < 0 || lPriority > 32767 )
  343.     {
  344.         MessageBox( hDlg, "Please enter a buffer priority between 0 and 32767", 
  345.                     "DirectSound Sample", MB_OK );
  346.         return S_OK;
  347.     }
  348.  
  349.     // Figure out the voice allocation flag from the dialog,
  350.     // and what the user should expect based on the dialog choice
  351.     if( bAllocSW )
  352.         dwPlayFlags = DSBPLAY_LOCSOFTWARE;
  353.  
  354.     if( bAllocHW )
  355.         dwPlayFlags = DSBPLAY_LOCHARDWARE;
  356.  
  357.     if( bAllocEither )
  358.         dwPlayFlags = 0;
  359.  
  360.     // Figure out what voice management flags should be based on the dlg
  361.     if( bByTime )
  362.     {
  363.         if( bByPriority )
  364.         {
  365.             dwPlayFlags |= DSBPLAY_TERMINATEBY_TIME | 
  366.                            DSBPLAY_TERMINATEBY_PRIORITY;
  367.         }
  368.         else
  369.         {
  370.             dwPlayFlags |= DSBPLAY_TERMINATEBY_TIME;
  371.         }
  372.     }
  373.     else if( bByDistance )
  374.     {
  375.         if( bByPriority )
  376.         {
  377.             dwPlayFlags |= DSBPLAY_TERMINATEBY_DISTANCE | 
  378.                            DSBPLAY_TERMINATEBY_PRIORITY;
  379.         }
  380.         else
  381.         {
  382.             dwPlayFlags |= DSBPLAY_TERMINATEBY_DISTANCE;
  383.         }
  384.     }
  385.     else
  386.     {
  387.         if( bByPriority )
  388.         {
  389.             dwPlayFlags |= DSBPLAY_TERMINATEBY_PRIORITY;
  390.         }
  391.         else
  392.         {
  393.             dwPlayFlags |= 0;
  394.         }
  395.     }
  396.  
  397.  
  398.     if( bLooped )
  399.         dwPlayFlags |= DSBPLAY_LOOPING;
  400.  
  401.     // Play the sound 
  402.     if( FAILED( hr = g_pSound->Play( lPriority, dwPlayFlags ) ) )
  403.     {
  404.         if( hr == DSERR_CONTROLUNAVAIL || 
  405.             hr == DSERR_INVALIDCALL ||
  406.             hr == E_FAIL )
  407.         {
  408.             DXTRACE_ERR_NOMSGBOX( TEXT("Play"), hr );
  409.             if( hr == DSERR_INVALIDCALL )
  410.             {
  411.                 MessageBox( hDlg, "Unsupported wave file format.", 
  412.                             "DirectPlay Sample", MB_OK | MB_ICONERROR );
  413.             }
  414.             else
  415.             {
  416.                 MessageBox( hDlg, "The buffer could not be played.", 
  417.                             "DirectPlay Sample", MB_OK | MB_ICONERROR );
  418.             }
  419.  
  420.             return S_OK;
  421.         }
  422.        
  423.         return DXTRACE_ERR( TEXT("Play"), hr );
  424.     }
  425.  
  426.     // Update the UI controls to show the sound as playing
  427.     EnablePlayUI( hDlg, FALSE );
  428.  
  429.     return S_OK;
  430. }
  431.  
  432.  
  433.  
  434.  
  435. //-----------------------------------------------------------------------------
  436. // Name: OnTimer()
  437. // Desc: When we think the sound is playing this periodically checks to see if 
  438. //       the sound has stopped.  If it has then updates the dialog.
  439. //-----------------------------------------------------------------------------
  440. VOID OnTimer( HWND hDlg ) 
  441. {
  442.     if( IsWindowEnabled( GetDlgItem( hDlg, IDC_STOP ) ) )
  443.     {
  444.         // We think the sound is playing, so see if it has stopped yet.
  445.         if( !g_pSound->IsSoundPlaying() ) 
  446.         {
  447.             // Update the UI controls to show the sound as stopped
  448.             EnablePlayUI( hDlg, TRUE );
  449.         }
  450.     }
  451. }
  452.  
  453.  
  454.  
  455.  
  456. //-----------------------------------------------------------------------------
  457. // Name: UpdateBehaviorText()
  458. // Desc: Figure out what the expected behavoir is based on the dialog,
  459. //       and display it on the dialog
  460. //-----------------------------------------------------------------------------
  461. VOID UpdateBehaviorText( HWND hDlg )
  462. {
  463.     TCHAR   strExcepted[1024];
  464.     BOOL    bAllocHW;
  465.     BOOL    bAllocSW;
  466.     BOOL    bAllocEither;
  467.     BOOL    bByTime;
  468.     BOOL    bByDistance;
  469.     BOOL    bByPriority;
  470.  
  471.     // Detrimine where the buffer would like to be allocated 
  472.     bAllocHW     = ( IsDlgButtonChecked( hDlg, IDC_ALLOC_HARDWARE ) == BST_CHECKED );
  473.     bAllocSW     = ( IsDlgButtonChecked( hDlg, IDC_ALLOC_SOFTWARE ) == BST_CHECKED );
  474.     bAllocEither = ( IsDlgButtonChecked( hDlg, IDC_ALLOC_EITHER   ) == BST_CHECKED );
  475.  
  476.     if( bAllocHW || bAllocEither )
  477.     {
  478.         // Detrimine how the buffer should steal hardware resources (if they are not available)
  479.         bByTime      = ( IsDlgButtonChecked( hDlg, IDC_BYTIME     ) == BST_CHECKED );
  480.         bByDistance  = ( IsDlgButtonChecked( hDlg, IDC_BYDISTANCE ) == BST_CHECKED );
  481.         bByPriority  = ( IsDlgButtonChecked( hDlg, IDC_BYPRIORTY  ) == BST_CHECKED );
  482.     }
  483.     else
  484.     {
  485.         // Buffers running in software are not allowed to have
  486.         // voice management flags since they have no need to 
  487.         // steal hardware resources.
  488.         bByTime      = FALSE;
  489.         bByDistance  = FALSE;
  490.         bByPriority  = FALSE;
  491.     }
  492.  
  493.     // Figure what the user should expect based on the dialog choice
  494.     if( bAllocSW )
  495.     {
  496.         strcpy( strExcepted, "The new sound will be played in software" );
  497.     }
  498.  
  499.     if( bAllocHW )
  500.     {
  501.         strcpy( strExcepted, "The new sound will be played in hardware" );
  502.     }
  503.  
  504.     if( bAllocEither )
  505.     {
  506.         strcpy( strExcepted, "The new sound will be played in hardware "
  507.                              "if available" );
  508.     }
  509.  
  510.     if( bByTime )
  511.     {
  512.         if( bByPriority )
  513.         {
  514.             if( bAllocEither )
  515.             {
  516.                 strcpy( strExcepted, "The new sound will be played in hardware, "
  517.                                      "if the the hardware has no available "
  518.                                      "voices, and new sound has a higher priority "
  519.                                      "than sounds currently playing in hardware "
  520.                                      "then sound with the lowest priority will be "
  521.                                      "terminated and the new sound will play in "
  522.                                      "hardware. Otherwise, the new sound will play "
  523.                                      "in software.  In event of a priority tie, "
  524.                                      "then the buffer with the least time left to "
  525.                                      "play will be prematurely terminated." );
  526.             }
  527.             else
  528.             {
  529.                 strcat( strExcepted, ", and if the hardware has no available "
  530.                                      "voices, the voice management buffer with "
  531.                                      "the lowest priority as set by the "
  532.                                      "IDirectSoundBuffer::Play priority argument "
  533.                                      "will be prematurely terminated. In event "
  534.                                      "of a priority tie, then the buffer with "
  535.                                      "the least time left to play will be "
  536.                                      "prematurely terminated." );         
  537.             }
  538.         }
  539.         else
  540.         {
  541.             strcat( strExcepted, ", and if the hardware has no available "
  542.                                  "voices, the voice management buffer with "
  543.                                  "the least time left to play will be "
  544.                                  "prematurely terminated." );                                     
  545.         }
  546.     }
  547.     else if( bByDistance )
  548.     {
  549.         if( bByPriority )
  550.         {
  551.             if( bAllocEither )
  552.             {
  553.                 strcpy( strExcepted, "The new sound will be played in hardware, "
  554.                                      "if the the hardware has no available "
  555.                                      "voices, and new sound has a higher priority "
  556.                                      "than sounds currently playing in hardware "
  557.                                      "then sound with the lowest priority will be "
  558.                                      "terminated and the new sound will play in "
  559.                                      "hardware. Otherwise, the new sound will play "
  560.                                      "in software.  In event of a priority tie, "
  561.                                      "then the buffer which is the furthest "
  562.                                      "distance from the listener at the time "
  563.                                      "of the Play will be prematurely terminated." );
  564.             }
  565.             else
  566.             {
  567.                 strcat( strExcepted, ", and if the hardware has no available "
  568.                                      "voices, the voice management buffer with "
  569.                                      "the lowest priority as set by the "
  570.                                      "IDirectSoundBuffer::Play priority argument "
  571.                                      "will be prematurely terminated. In event "
  572.                                      "of a priority tie, then the buffer which "
  573.                                      "is the furthest distance from the "
  574.                                      "listener at the time of the Play will "
  575.                                      "be prematurely terminated." );
  576.             }
  577.         }
  578.         else
  579.         {
  580.             strcat( strExcepted, ", and if the hardware has no available "
  581.                                  "voices, the voice management buffer which "
  582.                                  "is the furthest distance from the "
  583.                                  "listener at the time of the Play will "
  584.                                  "be prematurely terminated." );
  585.  
  586.         }
  587.     }
  588.     else
  589.     {
  590.         if( bByPriority )
  591.         {
  592.             if( bAllocEither )
  593.             {
  594.                 strcpy( strExcepted, "The new sound will be played in hardware, "
  595.                                      "if the the hardware has no available "
  596.                                      "voices, and new sound has a higher priority "
  597.                                      "than sounds currently playing in hardware "
  598.                                      "then sound with the lowest priority will be "
  599.                                      "terminated and the new sound will play in "
  600.                                      "hardware. Otherwise, the new sound will play "
  601.                                      "in software." );
  602.             }
  603.             else
  604.             {
  605.                 strcat( strExcepted, ", and if the hardware has no available "
  606.                                      "voices, the voice management buffer with "
  607.                                      "the lowest priority as set by the "
  608.                                      "IDirectSoundBuffer::Play priority argument "
  609.                                      "will be prematurely terminated. " );
  610.             }
  611.         }
  612.         else
  613.         {
  614.             strcat( strExcepted, ", and the buffer will not steal any "
  615.                                  "hardware resources." );
  616.         }
  617.     }
  618.  
  619.  
  620.     // Tell the user what to expect
  621.     SetDlgItemText( hDlg, IDC_BEHAVIOR, strExcepted );
  622. }
  623.  
  624.  
  625.  
  626.  
  627.  
  628.  
  629. //-----------------------------------------------------------------------------
  630. // Name: EnablePlayUI()
  631. // Desc: Enables or disables the Play UI controls 
  632. //-----------------------------------------------------------------------------
  633. VOID EnablePlayUI( HWND hDlg, BOOL bShowPlayControl )
  634. {
  635.     EnableWindow( GetDlgItem( hDlg, IDC_LOOP_CHECK ),  bShowPlayControl );
  636.     EnableWindow( GetDlgItem( hDlg, IDC_STOP ),       !bShowPlayControl );
  637.     EnableWindow( GetDlgItem( hDlg, IDC_PLAY ),        bShowPlayControl );
  638.  
  639.     // Don't allow the voice allocation or voicemanagement flags 
  640.     // to be changed when a sound is playing
  641.     EnableWindow( GetDlgItem( hDlg, IDC_BYTIME         ), bShowPlayControl );
  642.     EnableWindow( GetDlgItem( hDlg, IDC_BYDISTANCE     ), bShowPlayControl );
  643.     EnableWindow( GetDlgItem( hDlg, IDC_BYPRIORTY      ), bShowPlayControl );
  644.     EnableWindow( GetDlgItem( hDlg, IDC_EDIT_PRIORITY  ), bShowPlayControl );
  645.     EnableWindow( GetDlgItem( hDlg, IDC_ALLOC_HARDWARE ), bShowPlayControl );
  646.     EnableWindow( GetDlgItem( hDlg, IDC_ALLOC_SOFTWARE ), bShowPlayControl );
  647.     EnableWindow( GetDlgItem( hDlg, IDC_ALLOC_EITHER   ), bShowPlayControl );
  648.  
  649.     if( bShowPlayControl )
  650.     {
  651.         // If the software alloc flag is checked, then don't enable
  652.         // the voice management flags
  653.         if( IsDlgButtonChecked( hDlg, IDC_ALLOC_SOFTWARE ) == BST_CHECKED )
  654.             EnableManagementFlags( hDlg, FALSE );
  655.     }
  656.  
  657.     if( bShowPlayControl )
  658.         SetFocus( GetDlgItem( hDlg, IDC_PLAY ) );
  659.     else
  660.         SetFocus( GetDlgItem( hDlg, IDC_STOP ) );
  661. }
  662.  
  663.  
  664.  
  665.  
  666. //-----------------------------------------------------------------------------
  667. // Name: EnableManagementFlags()
  668. // Desc: Enable or disable the voice management flags
  669. //-----------------------------------------------------------------------------
  670. VOID EnableManagementFlags( HWND hDlg, BOOL bShowFlags )
  671. {
  672.     EnableWindow( GetDlgItem( hDlg, IDC_BYTIME        ), bShowFlags );
  673.     EnableWindow( GetDlgItem( hDlg, IDC_BYDISTANCE    ), bShowFlags );
  674.     EnableWindow( GetDlgItem( hDlg, IDC_BYPRIORTY     ), bShowFlags );
  675.     EnableWindow( GetDlgItem( hDlg, IDC_EDIT_PRIORITY ), bShowFlags );
  676. }
  677.  
  678.  
  679.  
  680.