]>
git.saurik.com Git - wxWidgets.git/blob - src/os2/sound.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/os2/sound.cpp
3 // Purpose: wxSound class implementation: optional
4 // Author: David Webster
7 // Copyright: (c) David Webster
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
11 // For compilers that support precompilation, includes "wx.h".
12 #include "wx/wxprec.h"
20 #define INCL_32 /* force 32 bit compile */
21 #define INCL_GPIBITMAPS
22 #define INCL_DOSFILEMGR
34 : m_waveData(NULL
), m_waveLength(0), m_isResource(FALSE
)
38 wxSound::wxSound(const wxString
& sFileName
, bool isResource
)
39 : m_waveData(NULL
), m_waveLength(0), m_isResource(isResource
)
41 Create(sFileName
, isResource
);
44 wxSound::wxSound(size_t size
, const void* data
)
45 : m_waveData(NULL
), m_waveLength(0), m_isResource(FALSE
)
55 bool wxSound::Create(const wxString
& fileName
, bool isResource
)
66 hresInfo = ::FindResourceW((HMODULE) wxhInstance, fileName, wxT("WAVE"));
68 hresInfo = ::FindResourceA((HMODULE) wxhInstance, fileName, wxT("WAVE"));
73 HGLOBAL waveData = ::LoadResource((HMODULE) wxhInstance, hresInfo);
77 m_waveData= (wxByte*)::LockResource(waveData);
78 m_waveLength = (int) ::SizeofResource((HMODULE) wxhInstance, hresInfo);
81 return (m_waveData ? TRUE : FALSE);
91 if (!fileWave
.Open(fileName
, wxFile::read
))
94 m_waveLength
= (int) fileWave
.Length();
97 m_waveData = (wxByte*)::GlobalLock(::GlobalAlloc(GMEM_MOVEABLE | GMEM_SHARE, m_waveLength));
101 fileWave.Read(m_waveData, m_waveLength);
110 bool wxSound::Create(size_t size
, const void* data
)
113 m_isResource
= FALSE
;
115 m_waveData
= NULL
; // (wxByte*)::GlobalLock(::GlobalAlloc(GMEM_MOVEABLE | GMEM_SHARE, m_waveLength));
119 memcpy(m_waveData
, data
, size
);
123 bool wxSound::DoPlay(unsigned WXUNUSED(flags
)) const
130 return ( ::PlaySound((LPCTSTR)m_waveData, NULL, SND_MEMORY |
131 SND_NODEFAULT | (async ? SND_ASYNC : SND_SYNC) | (looped ? (SND_LOOP | SND_ASYNC) : 0)) != 0 );
140 // HGLOBAL waveData = ::GlobalHandle(m_waveData);
147 ::FreeResource(waveData);
150 ::GlobalUnlock(waveData);
151 ::GlobalFree(waveData);