Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

101 lines
2.9 KiB

  1. /***************************************************************************/
  2. /** Microsoft Windows **/
  3. /** Copyright(c) Microsoft Corp., 1991, 1992 **/
  4. /***************************************************************************/
  5. /****************************************************************************
  6. sound.cpp
  7. Aug 92, JimH
  8. May 93, JimH chico port
  9. SoundInit() just verifies that a wave driver is loaded.
  10. HeartsPlaySound() plays the sound given a resource id.
  11. ****************************************************************************/
  12. #include "hearts.h"
  13. #include <mmsystem.h>
  14. #include "main.h"
  15. #include "resource.h"
  16. #include "debug.h"
  17. /****************************************************************************
  18. SoundInit()
  19. returns TRUE if sound is enabled.
  20. ****************************************************************************/
  21. BOOL CMainWindow::SoundInit()
  22. {
  23. return (::waveOutGetNumDevs() > 0);
  24. }
  25. /****************************************************************************
  26. CMainWindow::HeartsPlaySound(id)
  27. Plays the specified sound from the resource file.
  28. The static variable hRes is used as a flag to know if memory has been
  29. allocated and locked for the sound. If hRes is non-zero, a sound is
  30. still playing, or at least the memory for the sound has not been unlocked
  31. and freed. The application must call HeartsPlaySound(NULL, 0) to free this
  32. memory before exiting. (The game destructor does this. It also
  33. happens at the end of each hand.)
  34. ****************************************************************************/
  35. BOOL CMainWindow::HeartsPlaySound(int id)
  36. {
  37. static HRSRC hRes = 0;
  38. if (!bHasSound) // check for sound capability
  39. return TRUE;
  40. if (id == OFF) // request to turn off sound
  41. {
  42. if (hRes == 0) // hRes != 0 if a sound has been played...
  43. return TRUE; // and not freed.
  44. sndPlaySound(NULL, 0); // make sure sound is stopped
  45. UnlockResource(hRes);
  46. FreeResource(hRes);
  47. hRes = 0;
  48. return TRUE;
  49. }
  50. if (!bSoundOn) // has user toggled sound off?
  51. return TRUE;
  52. // User has requested a sound. Check if previous sound was freed.
  53. if (hRes != 0)
  54. HeartsPlaySound(OFF);
  55. BOOL bReturn;
  56. HINSTANCE hInst = AfxGetInstanceHandle();
  57. HRSRC hResInfo = FindResource(hInst, MAKEINTRESOURCE(id), TEXT("WAVE"));
  58. if (!hResInfo)
  59. return FALSE;
  60. hRes = (HRSRC) ::LoadResource(hInst, hResInfo);
  61. if (!hRes)
  62. return FALSE;
  63. LPTSTR lpRes = (LPTSTR) ::LockResource(hRes);
  64. if (lpRes)
  65. bReturn = ::sndPlaySound(lpRes, SND_MEMORY | SND_ASYNC | SND_NODEFAULT);
  66. else
  67. bReturn = FALSE;
  68. return bReturn;
  69. }