home *** CD-ROM | disk | FTP | other *** search
/ Windows Game Programming for Dummies (2nd Edition) / WinGamProgFD.iso / pc / DirectX SDK / DXSDK / samples / Multimedia / DirectSound / AdjustSound / adjustsound.cpp next >
Encoding:
C/C++ Source or Header  |  2001-10-31  |  21.4 KB  |  604 lines

  1. //----------------------------------------------------------------------------
  2. // File: AdjustSound.cpp
  3. //
  4. // Desc: AdjustSound sample sample shows how to load and play a wave file using
  5. //       a DirectSound buffer and adjust its focus, frequency, pan, and volume.
  6. //
  7. // Copyright (c) 1999-2001 Microsoft Corp. All rights reserved.
  8. //-----------------------------------------------------------------------------
  9. #define STRICT
  10. #include <windows.h>
  11. #include <basetsd.h>
  12. #include <mmsystem.h>
  13. #include <mmreg.h>
  14. #include <dxerr8.h>
  15. #include <dsound.h>
  16. #include <commctrl.h>
  17. #include <commdlg.h>
  18. #include <dsound.h>
  19. #include "resource.h"
  20. #include "DSUtil.h"
  21. #include "DXUtil.h"
  22.  
  23.  
  24.  
  25.  
  26. //-----------------------------------------------------------------------------
  27. // Function-prototypes
  28. //-----------------------------------------------------------------------------
  29. INT_PTR CALLBACK MainDlgProc( HWND hDlg, UINT msg,  WPARAM wParam, LPARAM lParam );
  30.  
  31. VOID    OnInitDialog( HWND hDlg );
  32. VOID    OnTimer( HWND hDlg );
  33.  
  34. VOID    OnOpenSoundFile( HWND hDlg );
  35. VOID    ValidateWaveFile( HWND hDlg, TCHAR* strFileName );
  36.  
  37. HRESULT OnPlaySound( HWND hDlg );
  38. HRESULT CreateAndFillBuffer( HWND hDlg, DWORD dwCreationFlags );
  39.  
  40. VOID    UpdateBehaviorText( HWND hDlg );
  41. VOID    OnSliderChanged( HWND hDlg );
  42. VOID    SetBufferOptions( LONG lFrequency, LONG lPan, LONG lVolume );
  43. VOID    EnablePlayUI( HWND hDlg, BOOL bEnable );
  44. VOID    SetSlidersPos( HWND hDlg, LONG lFreqSlider, LONG lPanSlider, LONG lVolumeSlider );
  45.  
  46.  
  47.  
  48.  
  49.  
  50. //-----------------------------------------------------------------------------
  51. // Defines, constants, and global variables
  52. //-----------------------------------------------------------------------------
  53. TCHAR          m_strWaveFileName[MAX_PATH];
  54. CSoundManager* g_pSoundManager = NULL;
  55. CSound*        g_pSound = NULL;
  56.  
  57.  
  58.  
  59.  
  60. //-----------------------------------------------------------------------------
  61. // Name: WinMain()
  62. // Desc: Entry point for the application.  Since we use a simple dialog for 
  63. //       user interaction we don't need to pump messages.
  64. //-----------------------------------------------------------------------------
  65. INT APIENTRY WinMain( HINSTANCE hInst, HINSTANCE hPrevInst, LPSTR pCmdLine, INT nCmdShow )
  66. {
  67.     // Init the common control dll 
  68.     InitCommonControls();
  69.  
  70.     // Display the main dialog box.
  71.     DialogBox( hInst, MAKEINTRESOURCE(IDD_MAIN), NULL, MainDlgProc );
  72.  
  73.     return TRUE;
  74. }
  75.  
  76.  
  77.  
  78.  
  79. //-----------------------------------------------------------------------------
  80. // Name: MainDlgProc()
  81. // Desc: Handles dialog messages
  82. //-----------------------------------------------------------------------------
  83. INT_PTR CALLBACK MainDlgProc( HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam )
  84. {
  85.     HRESULT hr;
  86.  
  87.     switch( msg ) 
  88.     {
  89.         case WM_COMMAND:
  90.             switch( LOWORD(wParam) )
  91.             {
  92.                 case IDCANCEL:
  93.                     EndDialog( hDlg, IDCANCEL );
  94.                     break;
  95.  
  96.                 case IDC_SOUNDFILE:
  97.                     OnOpenSoundFile( hDlg );
  98.                     break;
  99.  
  100.                 case IDC_PLAY:
  101.                     if( FAILED( hr = OnPlaySound( hDlg ) ) )
  102.                     {
  103.                         DXTRACE_ERR( TEXT("OnPlaySound"), hr );
  104.                         MessageBox( hDlg, "Error playing DirectSound buffer."
  105.                                     "Sample will now exit.", "DirectSound Sample", 
  106.                                     MB_OK | MB_ICONERROR );
  107.                         EndDialog( hDlg, IDABORT );
  108.                     }
  109.  
  110.                     break;
  111.  
  112.                 case IDC_STOP:
  113.                     if( g_pSound )
  114.                     {
  115.                         g_pSound->Stop();
  116.                         g_pSound->Reset();
  117.                     }
  118.                     break;
  119.  
  120.                 case IDC_MIX_DEFAULT:
  121.                 case IDC_MIX_HARDWARE:
  122.                 case IDC_MIX_SOFTWARE:
  123.                 case IDC_FOCUS_GLOBAL:
  124.                 case IDC_FOCUS_STICKY:
  125.                 case IDC_FOCUS_NORMAL:
  126.                     UpdateBehaviorText( hDlg );
  127.                     break;
  128.  
  129.                 default:
  130.                     return FALSE; // Didn't handle message
  131.             }
  132.             break;
  133.  
  134.         case WM_TIMER:
  135.             OnTimer( hDlg );
  136.             break;
  137.  
  138.         case WM_INITDIALOG:
  139.             OnInitDialog( hDlg );
  140.             break;
  141.  
  142.         case WM_NOTIFY:
  143.             OnSliderChanged( hDlg );
  144.             break;
  145.  
  146.         case WM_DESTROY:
  147.             // Cleanup everything
  148.             KillTimer( hDlg, 1 );    
  149.             SAFE_DELETE( g_pSound );
  150.             SAFE_DELETE( g_pSoundManager );
  151.             break; 
  152.  
  153.         default:
  154.             return FALSE; // Didn't handle message
  155.     }
  156.  
  157.     return TRUE; // Handled message
  158. }
  159.  
  160.  
  161.  
  162.  
  163. //-----------------------------------------------------------------------------
  164. // Name: OnInitDialog()
  165. // Desc: Initializes the dialogs (sets up UI controls, etc.)
  166. //-----------------------------------------------------------------------------
  167. VOID OnInitDialog( HWND hDlg )
  168. {
  169.     HRESULT hr;
  170.  
  171.     // Load the icon
  172. #ifdef _WIN64
  173.     HINSTANCE hInst = (HINSTANCE) GetWindowLongPtr( hDlg, GWLP_HINSTANCE );
  174. #else
  175.     HINSTANCE hInst = (HINSTANCE) GetWindowLong( hDlg, GWL_HINSTANCE );
  176. #endif
  177.     HICON hIcon = LoadIcon( hInst, MAKEINTRESOURCE( IDR_MAINFRAME ) );
  178.  
  179.     // Create a static IDirectSound in the CSound class.  
  180.     // Set coop level to DSSCL_PRIORITY, and set primary buffer 
  181.     // format to stereo, 22kHz and 16-bit output.
  182.     g_pSoundManager = new CSoundManager();
  183.  
  184.     if( FAILED( hr = g_pSoundManager->Initialize( hDlg, DSSCL_PRIORITY, 2, 22050, 16 ) ) )
  185.     {
  186.         DXTRACE_ERR( TEXT("Initialize"), hr );
  187.         MessageBox( hDlg, "Error initializing DirectSound.  Sample will now exit.", 
  188.                             "DirectSound Sample", MB_OK | MB_ICONERROR );
  189.         EndDialog( hDlg, IDABORT );
  190.         return;
  191.     }
  192.  
  193.     // Set the icon for this dialog.
  194.     PostMessage( hDlg, WM_SETICON, ICON_BIG,   (LPARAM) hIcon );  // Set big icon
  195.     PostMessage( hDlg, WM_SETICON, ICON_SMALL, (LPARAM) hIcon );  // Set small icon
  196.  
  197.     // Create a timer, so we can check for when the soundbuffer is stopped
  198.     SetTimer( hDlg, 0, 250, NULL );
  199.  
  200.     // Get handles to dialog items
  201.     HWND hFreqSlider    = GetDlgItem( hDlg, IDC_FREQUENCY_SLIDER );
  202.     HWND hPanSlider     = GetDlgItem( hDlg, IDC_PAN_SLIDER );
  203.     HWND hVolumeSlider  = GetDlgItem( hDlg, IDC_VOLUME_SLIDER );
  204.  
  205.     // Set the focus to normal by default
  206.     CheckRadioButton( hDlg, IDC_FOCUS_NORMAL, IDC_FOCUS_NORMAL, IDC_FOCUS_NORMAL );
  207.  
  208.     // Set the buffer mixing to default 
  209.     CheckRadioButton( hDlg, IDC_MIX_DEFAULT, IDC_MIX_SOFTWARE, IDC_MIX_DEFAULT );
  210.  
  211.     // Set the range and position of the freq slider from 
  212.     // DSBFREQUENCY_MIN and DSBFREQUENCY_MAX are DirectSound constants
  213.     PostMessage( hFreqSlider, TBM_SETRANGEMAX, TRUE, DSBFREQUENCY_MAX );
  214.     PostMessage( hFreqSlider, TBM_SETRANGEMIN, TRUE, DSBFREQUENCY_MIN );
  215.  
  216.     // Set the range and position of the pan slider from 
  217.     PostMessage( hPanSlider, TBM_SETRANGEMAX, TRUE, ( 10000L/500L) );
  218.     PostMessage( hPanSlider, TBM_SETRANGEMIN, TRUE, (-10000L/500L) );
  219.  
  220.     // Set the range and position of the volume slider 
  221.     PostMessage( hVolumeSlider, TBM_SETRANGEMAX, TRUE, 0L );
  222.     PostMessage( hVolumeSlider, TBM_SETRANGEMIN, TRUE, (-5000L/100L) );
  223.  
  224.     // Set the position of the sliders
  225.     SetSlidersPos( hDlg, DSBFREQUENCY_MIN, 0, 0 );
  226.  
  227.     // Set the UI controls
  228.     SetDlgItemText( hDlg, IDC_FILENAME, TEXT("") );
  229.     SetDlgItemText( hDlg, IDC_STATUS, TEXT("No file loaded.") );
  230.     UpdateBehaviorText( hDlg );
  231. }
  232.  
  233.  
  234.  
  235.  
  236. //-----------------------------------------------------------------------------
  237. // Name: OnOpenSoundFile()
  238. // Desc: Called when the user requests to open a sound file
  239. //-----------------------------------------------------------------------------
  240. VOID OnOpenSoundFile( HWND hDlg ) 
  241. {
  242.     static TCHAR strFileName[MAX_PATH] = TEXT("");
  243.     static TCHAR strPath[MAX_PATH] = TEXT("");
  244.  
  245.     // Setup the OPENFILENAME structure
  246.     OPENFILENAME ofn = { sizeof(OPENFILENAME), hDlg, NULL,
  247.                          TEXT("Wave Files\0*.wav\0All Files\0*.*\0\0"), NULL,
  248.                          0, 1, strFileName, MAX_PATH, NULL, 0, strPath,
  249.                          TEXT("Open Sound File"),
  250.                          OFN_FILEMUSTEXIST|OFN_HIDEREADONLY, 0, 0,
  251.                          TEXT(".wav"), 0, NULL, NULL };
  252.  
  253.     // Get the default media path (something like C:\WINDOWS\MEDIA)
  254.     if( '\0' == strPath[0] )
  255.     {
  256.         GetWindowsDirectory( strPath, MAX_PATH );
  257.         if( strcmp( &strPath[strlen(strPath)], TEXT("\\") ) )
  258.             strcat( strPath, TEXT("\\") );
  259.         strcat( strPath, TEXT("MEDIA") );
  260.     }
  261.  
  262.     // Update the UI controls to show the sound as loading a file
  263.     EnableWindow( GetDlgItem( hDlg, IDC_PLAY ), FALSE );
  264.     EnableWindow( GetDlgItem( hDlg, IDC_STOP ), FALSE );
  265.     SetDlgItemText( hDlg, IDC_STATUS, TEXT("Loading file...") );
  266.  
  267.     if( g_pSound )
  268.     {
  269.         g_pSound->Stop();
  270.         g_pSound->Reset();
  271.     }
  272.  
  273.     // Display the OpenFileName dialog. Then, try to load the specified file
  274.     if( TRUE != GetOpenFileName( &ofn ) )
  275.     {
  276.         if( g_pSound )
  277.         {
  278.             EnableWindow( GetDlgItem( hDlg, IDC_PLAY ), TRUE );
  279.             EnableWindow( GetDlgItem( hDlg, IDC_STOP ), TRUE );
  280.         }
  281.  
  282.         SetDlgItemText( hDlg, IDC_STATUS, TEXT("Load aborted.") );
  283.         return;
  284.     }
  285.  
  286.     SetDlgItemText( hDlg, IDC_FILENAME, TEXT("") );
  287.  
  288.     // Make sure wave file is a valid wav file
  289.     ValidateWaveFile( hDlg, strFileName );
  290.  
  291.     // Remember the path for next time
  292.     strcpy( strPath, strFileName );
  293.     char* strLastSlash = strrchr( strPath, '\\' );
  294.     strLastSlash[0] = '\0';
  295. }
  296.  
  297.  
  298.  
  299.  
  300. //-----------------------------------------------------------------------------
  301. // Name: ValidateWaveFile()
  302. // Desc: Open the wave file with the helper 
  303. //       class CWaveFile to make sure it is valid
  304. //-----------------------------------------------------------------------------
  305. VOID ValidateWaveFile( HWND hDlg, TCHAR* strFileName )
  306. {
  307.     HRESULT hr;
  308.  
  309.     CWaveFile waveFile;
  310.  
  311.     // Load the wave file
  312.     if( FAILED( hr = waveFile.Open( strFileName, NULL, WAVEFILE_READ ) ) )
  313.     {
  314.         DXTRACE_ERR( TEXT("Open"), hr );
  315.         waveFile.Close();
  316.         SetDlgItemText( hDlg, IDC_STATUS, TEXT("Bad wave file.") );
  317.     }
  318.     else // The load call succeeded
  319.     {
  320.         // Update the UI controls to show the sound as the file is loaded
  321.         waveFile.Close();
  322.  
  323.         EnablePlayUI( hDlg, TRUE );
  324.         SetDlgItemText( hDlg, IDC_FILENAME, strFileName );
  325.         SetDlgItemText( hDlg, IDC_STATUS, TEXT("File loaded.") );
  326.         strcpy( m_strWaveFileName, strFileName );
  327.  
  328.         // Get the samples per sec from the wave file
  329.         DWORD dwSamplesPerSec = waveFile.m_pwfx->nSamplesPerSec;
  330.  
  331.         // Set the slider positions
  332.         SetSlidersPos( hDlg, dwSamplesPerSec, 0, 0 );
  333.     }
  334. }
  335.  
  336.  
  337.  
  338.  
  339. //-----------------------------------------------------------------------------
  340. // Name: OnPlaySound()
  341. // Desc: User hit the "Play" button
  342. //-----------------------------------------------------------------------------
  343. HRESULT OnPlaySound( HWND hDlg ) 
  344. {
  345.     HRESULT hr;
  346.     DWORD dwCreationFlags;
  347.  
  348.     BOOL bLooped      = ( IsDlgButtonChecked( hDlg, IDC_LOOP_CHECK )      == BST_CHECKED );
  349.     BOOL bFocusSticky = ( IsDlgButtonChecked( hDlg, IDC_FOCUS_STICKY )    == BST_CHECKED );
  350.     BOOL bFocusGlobal = ( IsDlgButtonChecked( hDlg, IDC_FOCUS_GLOBAL )    == BST_CHECKED );
  351.     BOOL bMixHardware = ( IsDlgButtonChecked( hDlg, IDC_MIX_HARDWARE ) == BST_CHECKED );
  352.     BOOL bMixSoftware = ( IsDlgButtonChecked( hDlg, IDC_MIX_SOFTWARE ) == BST_CHECKED );
  353.  
  354.     // Detrimine the creation flags to use based on the radio buttons
  355.     dwCreationFlags = 0;
  356.     if( bFocusGlobal )
  357.         dwCreationFlags |= DSBCAPS_GLOBALFOCUS;
  358.  
  359.     if( bFocusSticky )
  360.         dwCreationFlags |= DSBCAPS_STICKYFOCUS;
  361.  
  362.     if( bMixHardware )
  363.         dwCreationFlags |= DSBCAPS_LOCHARDWARE;
  364.  
  365.     if( bMixSoftware )
  366.         dwCreationFlags |= DSBCAPS_LOCSOFTWARE;
  367.  
  368.     // Add extra flags needed for the UI
  369.     dwCreationFlags |= DSBCAPS_CTRLPAN | DSBCAPS_CTRLVOLUME | DSBCAPS_CTRLFREQUENCY;
  370.  
  371.     // Free any previous sound
  372.     SAFE_DELETE( g_pSound );
  373.  
  374.     // Since the user can change the focus before the sound is played, 
  375.     // we need to create the sound buffer every time the play button is pressed 
  376.  
  377.     // Load the wave file into a DirectSound buffer
  378.     if( FAILED( hr = g_pSoundManager->Create( &g_pSound, m_strWaveFileName, dwCreationFlags, GUID_NULL ) ) )
  379.     {
  380.         // Not a critical failure, so just update the status
  381.         DXTRACE_ERR_NOMSGBOX( TEXT("Create"), hr );
  382.         SetDlgItemText( hDlg, IDC_STATUS, TEXT("Could not create sound buffer.") );
  383.         return S_FALSE; 
  384.     }
  385.  
  386.     // Set the buffer options to what the sliders are set to
  387.     OnSliderChanged( hDlg );
  388.  
  389.     // Only if the sound buffer was created perfectly should we update the UI 
  390.     // and play the sound
  391.     // Play the sound
  392.     DWORD dwLooped = bLooped ? DSBPLAY_LOOPING : 0L;
  393.  
  394.     if( FAILED( hr = g_pSound->Play( 0, dwLooped ) ) )
  395.         return DXTRACE_ERR( TEXT("Play"), hr );
  396.  
  397.     // Update the UI controls to show the sound as playing
  398.     EnablePlayUI( hDlg, FALSE );
  399.     SetDlgItemText( hDlg, IDC_STATUS, TEXT("Sound playing.") );
  400.  
  401.     return S_OK;
  402. }
  403.  
  404.  
  405.  
  406.  
  407. //-----------------------------------------------------------------------------
  408. // Name: OnTimer()
  409. // Desc: When we think the sound is playing this periodically checks to see if 
  410. //       the sound has stopped.  If it has then updates the dialog.
  411. //-----------------------------------------------------------------------------
  412. VOID OnTimer( HWND hDlg ) 
  413. {
  414.     if( IsWindowEnabled( GetDlgItem( hDlg, IDC_STOP ) ) )
  415.     {
  416.         // We think the sound is playing, so see if it has stopped yet.
  417.         if( !g_pSound->IsSoundPlaying() ) 
  418.         {
  419.             // Update the UI controls to show the sound as stopped
  420.             EnablePlayUI( hDlg, TRUE );
  421.             SetDlgItemText( hDlg, IDC_STATUS, TEXT("Sound stopped.") );
  422.         }
  423.     }
  424. }
  425.  
  426.  
  427.  
  428.  
  429. //-----------------------------------------------------------------------------
  430. // Name: OnSliderChanged()  
  431. // Desc: Called when the dialog's slider bars are changed by the user, or need
  432. //       updating
  433. //-----------------------------------------------------------------------------
  434. VOID OnSliderChanged( HWND hDlg )
  435. {
  436.     TCHAR strBuffer[10];
  437.  
  438.     // Get handles to dialog items
  439.     HWND hFreqSlider   = GetDlgItem( hDlg, IDC_FREQUENCY_SLIDER );
  440.     HWND hPanSlider    = GetDlgItem( hDlg, IDC_PAN_SLIDER );
  441.     HWND hVolumeSlider = GetDlgItem( hDlg, IDC_VOLUME_SLIDER );
  442.  
  443.     // Get the position of the sliders
  444.     LONG lFrequency = (LONG)SendMessage( hFreqSlider,   TBM_GETPOS, 0, 0 ) * 1L;
  445.     LONG lPan       = (LONG)SendMessage( hPanSlider,    TBM_GETPOS, 0, 0 ) * 500L;
  446.     LONG lVolume    = (LONG)SendMessage( hVolumeSlider, TBM_GETPOS, 0, 0 ) * 100L;
  447.  
  448.     // Set the static text boxes
  449.     wsprintf( strBuffer, TEXT("%ld"), lFrequency );
  450.     SetWindowText( GetDlgItem( hDlg, IDC_FREQUENCY ), strBuffer );
  451.  
  452.     wsprintf( strBuffer, TEXT("%ld"), lPan );
  453.     SetWindowText( GetDlgItem( hDlg, IDC_PAN       ), strBuffer );
  454.  
  455.     wsprintf( strBuffer, TEXT("%ld"), lVolume );
  456.     SetWindowText( GetDlgItem( hDlg, IDC_VOLUME    ), strBuffer );
  457.  
  458.     // Set the options in the DirectSound buffer
  459.     if( g_pSound )
  460.     {
  461.         LPDIRECTSOUNDBUFFER pDSB = g_pSound->GetBuffer( 0 );
  462.  
  463.         if( pDSB )
  464.         {
  465.             pDSB->SetFrequency( lFrequency );
  466.             pDSB->SetPan( lPan );
  467.             pDSB->SetVolume( lVolume );
  468.         }
  469.     }
  470. }
  471.  
  472.  
  473.  
  474.  
  475. //-----------------------------------------------------------------------------
  476. // Name: UpdateBehaviorText()
  477. // Desc: Figure out what the expected behavoir is based on the dialog,
  478. //       and display it on the dialog
  479. //-----------------------------------------------------------------------------
  480. VOID UpdateBehaviorText( HWND hDlg )
  481. {
  482.     TCHAR strExcepted[1024];
  483.  
  484.     BOOL bLooped      = ( IsDlgButtonChecked( hDlg, IDC_LOOP_CHECK )   == BST_CHECKED );
  485.     BOOL bFocusSticky = ( IsDlgButtonChecked( hDlg, IDC_FOCUS_STICKY ) == BST_CHECKED );
  486.     BOOL bFocusGlobal = ( IsDlgButtonChecked( hDlg, IDC_FOCUS_GLOBAL ) == BST_CHECKED );
  487.     BOOL bMixHardware = ( IsDlgButtonChecked( hDlg, IDC_MIX_HARDWARE ) == BST_CHECKED );
  488.     BOOL bMixSoftware = ( IsDlgButtonChecked( hDlg, IDC_MIX_SOFTWARE ) == BST_CHECKED );
  489.  
  490.     // Figure what the user should expect based on the dialog choice
  491.     if( bFocusSticky )
  492.     {
  493.         strcpy( strExcepted, "Buffers with \"sticky\" focus will continue to play "
  494.                              "if the user switches to another application not using "
  495.                              "DirectSound.  However, if the user switches to another "
  496.                              "DirectSound application, all normal-focus and sticky-focus "
  497.                              "buffers in the previous application are muted." ); 
  498.  
  499.     }
  500.     else if( bFocusGlobal )
  501.     {
  502.         strcpy( strExcepted, "Buffers with global focus will continue to play if the user "
  503.                              "switches focus to another application, even if the new application "
  504.                              "uses DirectSound. The one exception is if you switch focus to a "
  505.                              "DirectSound application that uses the DSSCL_WRITEPRIMARY "
  506.                              "cooperative level. In this case, the global-focus buffers from "
  507.                              "other applications will not be audible." );
  508.     }
  509.     else
  510.     {
  511.         // Normal focus
  512.         strcpy( strExcepted, "Buffers with normal focus will mute if the user switches "
  513.                              "focus to any other application" );
  514.     }
  515.  
  516.  
  517.     if( bMixHardware )
  518.     {
  519.         strcat( strExcepted, "\n\nWith the hardware mixing flag, the new buffer will "
  520.                              "be forced to use hardware mixing. If the device does "
  521.                              "not support hardware mixing or if the required "
  522.                              "hardware resources are not available, the call to the "
  523.                              "IDirectSound::CreateSoundBuffer method will fail." ); 
  524.     }
  525.     else if( bMixSoftware )
  526.     {
  527.         strcat( strExcepted, "\n\nWith the software mixing flag, the new buffer will use "
  528.                              "software mixing, even if hardware resources are available." );
  529.     }
  530.     else 
  531.     {
  532.         // Default mixing
  533.         strcat( strExcepted, "\n\nWith default mixing, the new buffer will use hardware "
  534.                              "mixing if available, otherwise software mixing will be used." ); 
  535.     }
  536.  
  537.     // Tell the user what to expect
  538.     SetDlgItemText( hDlg, IDC_BEHAVIOR, strExcepted );
  539. }
  540.  
  541.  
  542.  
  543.  
  544. //-----------------------------------------------------------------------------
  545. // Name: EnablePlayUI()
  546. // Desc: Enables or disables the Play UI controls 
  547. //-----------------------------------------------------------------------------
  548. VOID EnablePlayUI( HWND hDlg, BOOL bEnable )
  549. {
  550.     if( bEnable )
  551.     {
  552.         EnableWindow( GetDlgItem( hDlg, IDC_LOOP_CHECK      ), TRUE );
  553.         EnableWindow( GetDlgItem( hDlg, IDC_PLAY            ), TRUE );
  554.         EnableWindow( GetDlgItem( hDlg, IDC_STOP            ), FALSE );
  555.  
  556.         EnableWindow( GetDlgItem( hDlg, IDC_FOCUS_NORMAL    ), TRUE );
  557.         EnableWindow( GetDlgItem( hDlg, IDC_FOCUS_STICKY    ), TRUE );
  558.         EnableWindow( GetDlgItem( hDlg, IDC_FOCUS_GLOBAL    ), TRUE );
  559.  
  560.         EnableWindow( GetDlgItem( hDlg, IDC_MIX_DEFAULT  ), TRUE );
  561.         EnableWindow( GetDlgItem( hDlg, IDC_MIX_HARDWARE ), TRUE );
  562.         EnableWindow( GetDlgItem( hDlg, IDC_MIX_SOFTWARE ), TRUE );
  563.  
  564.         SetFocus(     GetDlgItem( hDlg, IDC_PLAY ) );
  565.     }
  566.     else
  567.     {
  568.         EnableWindow( GetDlgItem( hDlg, IDC_LOOP_CHECK      ), FALSE );
  569.         EnableWindow( GetDlgItem( hDlg, IDC_PLAY            ), FALSE );
  570.         EnableWindow( GetDlgItem( hDlg, IDC_STOP            ), TRUE );
  571.  
  572.         EnableWindow( GetDlgItem( hDlg, IDC_FOCUS_NORMAL    ), FALSE );
  573.         EnableWindow( GetDlgItem( hDlg, IDC_FOCUS_STICKY    ), FALSE );
  574.         EnableWindow( GetDlgItem( hDlg, IDC_FOCUS_GLOBAL    ), FALSE );
  575.  
  576.         EnableWindow( GetDlgItem( hDlg, IDC_MIX_DEFAULT  ), FALSE );
  577.         EnableWindow( GetDlgItem( hDlg, IDC_MIX_HARDWARE ), FALSE );
  578.         EnableWindow( GetDlgItem( hDlg, IDC_MIX_SOFTWARE ), FALSE );
  579.  
  580.         SetFocus(     GetDlgItem( hDlg, IDC_STOP ) );
  581.     }
  582. }
  583.  
  584.  
  585.  
  586.  
  587. //-----------------------------------------------------------------------------
  588. // Name: SetSlidersPos()
  589. // Desc: Sets the slider positions
  590. //-----------------------------------------------------------------------------
  591. VOID SetSlidersPos( HWND hDlg, LONG lFreqSlider, LONG lPanSlider, LONG lVolumeSlider )
  592. {
  593.     HWND hFreqSlider    = GetDlgItem( hDlg, IDC_FREQUENCY_SLIDER );
  594.     HWND hPanSlider     = GetDlgItem( hDlg, IDC_PAN_SLIDER );
  595.     HWND hVolumeSlider  = GetDlgItem( hDlg, IDC_VOLUME_SLIDER );
  596.  
  597.     PostMessage( hFreqSlider,   TBM_SETPOS, TRUE, lFreqSlider );
  598.     PostMessage( hPanSlider,    TBM_SETPOS, TRUE, lPanSlider );
  599.     PostMessage( hVolumeSlider, TBM_SETPOS, TRUE, lVolumeSlider );
  600. }
  601.  
  602.  
  603.  
  604.