]>
git.saurik.com Git - wxWidgets.git/blob - src/os2/sound.cpp
1 /////////////////////////////////////////////////////////////////////////////
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(int size
, const wxByte
* 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(int size
, const wxByte
* data
)
114 m_isResource
= FALSE
;
116 m_waveData
= NULL
; // (wxByte*)::GlobalLock(::GlobalAlloc(GMEM_MOVEABLE | GMEM_SHARE, m_waveLength));
120 for (int i
=0; i
<size
; i
++) m_waveData
[i
] = data
[i
];
124 bool wxSound::DoPlay(unsigned 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);