home *** CD-ROM | disk | FTP | other *** search
/ DP Tool Club 26 / CD_ASCQ_26_1295.iso / vrac / mfcwave.zip / WAVE.HXX < prev    next >
Text File  |  1995-07-21  |  7KB  |  245 lines

  1. /////////////////////////////////////////////////////////////////////////////
  2. //
  3. //  $Id: wave.hxx 1.1 1995/07/21 20:10:06 neuer Exp $
  4. //
  5. //
  6. //      Interface to the CWave class.
  7. //
  8. //
  9. //      Description
  10. //      ===========
  11. //
  12. //      The CWave class is to be used to ease the handling of
  13. //      Windows Multimedia Extensions with the Microsoft Foundation
  14. //      Class Library.
  15. //
  16. //
  17. //      Contruction:
  18. //
  19. //        - CWave();
  20. //              Creates an uninitialized (empty) wave object.
  21. //
  22. //        - CWave( LPCSTR lpszWave );
  23. //              Creates a wave object from a string.
  24. //              The string may either specify a wave file (*.wav)
  25. //              or an entry in the sounds section of the win.ini
  26. //              file.
  27. //
  28. //        - CWave( UINT nWave );
  29. //              Creates a wave object from a wave resource.
  30. //              The parameter specifies the resource identification
  31. //              number.
  32. //
  33. //        - CWave( CWave const &Wave );
  34. //              Creates a wave object from another wave object.
  35. //
  36. //
  37. //      Destruction:
  38. //
  39. //        - ~CWave();
  40. //              Destroys a wave object.
  41. //
  42. //
  43. //      Loading Waves:
  44. //
  45. //        - BOOL LoadWave( LPCSTR lpszWave );
  46. //              Loads a wave form into a wave object.
  47. //              The parameter specifies either a wave form file (*.wav)
  48. //              or an entry in the sounds section of the win.ini file.
  49. //              If the wave object is already loaded with a wave form,
  50. //              the new wave is loaded over the old one.
  51. //
  52. //        - BOOL LoadWave( UINT nWave );
  53. //              Loads a wave form into a wave object.
  54. //              The parameter specifies the resource identification
  55. //              number.
  56. //              If the wave object is already loaded with a wave form,
  57. //              the new wave is loaded over the old one.
  58. //
  59. //
  60. //      Assignment:
  61. //
  62. //        - void operator =( CWave const &wave );
  63. //              Assigns a wave object from another wave.
  64. //
  65. //
  66. //      Output Operations:
  67. //
  68. //        - BOOL PlaySound( UINT flags = SND_SYNC );
  69. //              Plays a wave.
  70. //              Flag values can be found in the <mmsystem.h> include file.
  71. //              The default is SND_SYNC which causes the program to wait
  72. //              until the wave is completely send to the wave output device.
  73. //              The wave class automatically takes care of the difference
  74. //              between memory resident (resource) waves and external wave
  75. //              (*.wav) files.
  76. //              The function will abort in the debugging version of this
  77. //              class if the class is not initialized with a valid wave.
  78. //
  79. //        - void StopSound();
  80. //              Stops any wave that is currently played.
  81. //
  82. //
  83. //      Status:
  84. //
  85. //        - BOOL IsLoaded() const;
  86. //              TRUE if the object is initialized with a wave form.
  87. //
  88. //        - BOOL IsResident() const;
  89. //              TRUE if the object is initialized with a resident
  90. //              (resource) wave form.
  91. //
  92. //        - BOOL IsExternal() const;
  93. //              TRUE if the object is initialized with an external
  94. //              (wave file) wave form.
  95. //
  96. //
  97. //      Debugging:
  98. //
  99. //        - virtual void AssertValid() const;
  100. //              In the debugging version of this class, this function
  101. //              overrides CObject::AssertValid().
  102. //              For more information refer to CObject::AssertValid()
  103. //              in the MFC documentation.
  104. //
  105. //        - virtual void Dump( CDumpContext &dc ) const;
  106. //              In the debugging version of this class, this function
  107. //              overrides CObject::Dump().
  108. //              For more information refer to CObject::Dump() in the
  109. //              MFC documentation.
  110. //
  111. //
  112. //  $Revision: 1.1 $
  113. //  $Date: 1995/07/21 20:10:06 $
  114. //  $Author: neuer $
  115. //
  116. //  $Log: wave.hxx $
  117. //    Revision 1.1  1995/07/21  20:10:06  neuer
  118. //    Initial revision
  119. //
  120. /////////////////////////////////////////////////////////////////////////////
  121.  
  122. #if !defined(__WAVE_H__)
  123. #define __WAVE_H__
  124.  
  125. #include "stdafx.h"
  126. #include <mmsystem.h>
  127.  
  128.  
  129. class CWave : public CObject
  130. {
  131. private:
  132.     HANDLE  m_Resource;
  133.     LPSTR   m_Name;
  134.     UINT    m_Flags;
  135. protected:
  136.     DECLARE_DYNAMIC( CWave );
  137. public:
  138.     inline CWave();
  139.     inline CWave( LPCSTR lpszWave );
  140.     inline CWave( UINT nWave );
  141.     inline CWave( CWave const &Wave );
  142.     inline ~CWave();
  143.     BOOL LoadWave( LPCSTR lpszWave );
  144.     BOOL LoadWave( UINT nWave );
  145.     inline void operator =( CWave const &wave );
  146.     inline BOOL PlaySound( UINT flags = SND_SYNC );
  147.     inline void StopSound();
  148.     inline BOOL IsLoaded() const;       // wave loaded?
  149.     inline BOOL IsResident() const;     // resident wave resource?
  150.     inline BOOL IsExternal() const;     // external wave file?
  151. private:
  152.     void DiscardWave();
  153.     inline void InitWave();
  154. public:
  155. #ifdef  _DEBUG
  156.     virtual void AssertValid() const;
  157.     virtual void Dump( CDumpContext &dc ) const;
  158. #endif
  159. };
  160.  
  161.  
  162. inline void CWave::InitWave()
  163. {
  164.     m_Resource = NULL;
  165.     m_Name = NULL;
  166.     m_Flags = 0;
  167. } // InitWave()
  168.  
  169.  
  170. inline CWave::CWave()
  171. {
  172.     InitWave();
  173. } // CWave()
  174.  
  175.  
  176. inline CWave::CWave( LPCSTR lpszWave )
  177. {
  178.     InitWave();
  179.     VERIFY( LoadWave( lpszWave ) );
  180. } // CWave()
  181.  
  182.  
  183. inline CWave::CWave( UINT nWave )
  184. {
  185.     InitWave();
  186.     VERIFY( LoadWave( nWave ) );
  187. } // CWave()
  188.  
  189.  
  190. inline CWave::CWave( CWave const &Wave )
  191. {
  192.     m_Resource = Wave.m_Resource;
  193.     m_Name = Wave.m_Name;
  194.     m_Flags = Wave.m_Flags;
  195. } // CWave()
  196.  
  197.  
  198. inline CWave::~CWave()
  199. {
  200.     DiscardWave();
  201. } // ~CWave()
  202.  
  203.  
  204. inline BOOL CWave::PlaySound( UINT flags )
  205. {
  206.     ASSERT( IsLoaded() );
  207.     return sndPlaySound( m_Name, m_Flags | flags );
  208. } // PlaySound()
  209.  
  210.  
  211. inline void CWave::StopSound()
  212. {
  213.     sndPlaySound( NULL, 0 );
  214. } // StopSound()
  215.  
  216.  
  217. inline BOOL CWave::IsLoaded() const
  218. {
  219.     return (m_Name != NULL);
  220. } // IsLoaded()
  221.  
  222.  
  223. inline BOOL CWave::IsResident() const
  224. {
  225.     return  (m_Flags != 0);
  226. } // IsResident()
  227.  
  228.  
  229. inline BOOL CWave::IsExternal() const
  230. {
  231.     return  (m_Flags == 0);
  232. } // IsExternal()
  233.  
  234.  
  235. inline void CWave::operator =( CWave const &wave )
  236. {
  237.     m_Resource = wave.m_Resource;
  238.     m_Name = wave.m_Name;
  239.     m_Flags = wave.m_Flags;
  240. } // operator=()
  241.  
  242.  
  243. /////////////////////////////////////////////////////////////////////////////
  244. #endif
  245.