]>
git.saurik.com Git - wxWidgets.git/blob - src/os2/sound.cpp
a901a8dc338b7f9ed1e439ae698b5db42c991f0c
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/os2/sound.cpp
3 // Purpose: wxSound class implementation: optional
4 // Author: David Webster
8 // Copyright: (c) David Webster
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // For compilers that support precompilation, includes "wx.h".
13 #include "wx/wxprec.h"
21 #define INCL_32 /* force 32 bit compile */
22 #define INCL_GPIBITMAPS
23 #define INCL_DOSFILEMGR
35 : m_waveData(NULL
), m_waveLength(0), m_isResource(FALSE
)
39 wxSound::wxSound(const wxString
& sFileName
, bool isResource
)
40 : m_waveData(NULL
), m_waveLength(0), m_isResource(isResource
)
42 Create(sFileName
, isResource
);
45 wxSound::wxSound(size_t size
, const void* data
)
46 : m_waveData(NULL
), m_waveLength(0), m_isResource(FALSE
)
56 bool wxSound::Create(const wxString
& fileName
, bool isResource
)
67 hresInfo = ::FindResourceW((HMODULE) wxhInstance, fileName, wxT("WAVE"));
69 hresInfo = ::FindResourceA((HMODULE) wxhInstance, fileName, wxT("WAVE"));
74 HGLOBAL waveData = ::LoadResource((HMODULE) wxhInstance, hresInfo);
78 m_waveData= (wxByte*)::LockResource(waveData);
79 m_waveLength = (int) ::SizeofResource((HMODULE) wxhInstance, hresInfo);
82 return (m_waveData ? TRUE : FALSE);
92 if (!fileWave
.Open(fileName
, wxFile::read
))
95 m_waveLength
= (int) fileWave
.Length();
98 m_waveData = (wxByte*)::GlobalLock(::GlobalAlloc(GMEM_MOVEABLE | GMEM_SHARE, m_waveLength));
102 fileWave.Read(m_waveData, m_waveLength);
111 bool wxSound::Create(size_t size
, const void* data
)
114 m_isResource
= FALSE
;
116 m_waveData
= NULL
; // (wxByte*)::GlobalLock(::GlobalAlloc(GMEM_MOVEABLE | GMEM_SHARE, m_waveLength));
120 memcpy(m_waveData
, data
, size
);
124 bool wxSound::DoPlay(unsigned WXUNUSED(flags
)) const
131 return ( ::PlaySound((LPCTSTR)m_waveData, NULL, SND_MEMORY |
132 SND_NODEFAULT | (async ? SND_ASYNC : SND_SYNC) | (looped ? (SND_LOOP | SND_ASYNC) : 0)) != 0 );
141 // HGLOBAL waveData = ::GlobalHandle(m_waveData);
148 ::FreeResource(waveData);
151 ::GlobalUnlock(waveData);
152 ::GlobalFree(waveData);