]>
git.saurik.com Git - wxWidgets.git/blob - src/msw/wave.cpp
1 /////////////////////////////////////////////////////////////////////////////
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart and Markus Holzem
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
13 #pragma implementation "wave.h"
16 // For compilers that support precompilation, includes "wx.h".
17 #include "wx/wxprec.h"
19 #if defined(__BORLANDC__)
28 #include "wx/msw/wave.h"
29 #include "wx/msw/private.h"
39 #include "wx/msw/gnuwin32/extra.h"
43 : m_waveLength(0), m_isResource(FALSE
), m_waveData(NULL
)
47 wxWave::wxWave(const wxString
& sFileName
, bool isResource
)
48 : m_waveLength(0), m_isResource(isResource
), m_waveData(NULL
)
50 Create(sFileName
, isResource
);
59 bool wxWave::Create(const wxString
& fileName
, bool isResource
)
69 hresInfo
= ::FindResourceA((HMODULE
) wxhInstance
, fileName
, "WAVE");
71 hresInfo
= ::FindResource((HMODULE
) wxhInstance
, fileName
, "WAVE");
76 HGLOBAL waveData
= ::LoadResource((HMODULE
) wxhInstance
, hresInfo
);
80 m_waveData
= (byte
*)::LockResource(waveData
);
81 m_waveLength
= (int) ::SizeofResource((HMODULE
) wxhInstance
, hresInfo
);
84 return (m_waveData
? TRUE
: FALSE
);
91 if (!fileWave
.Open(fileName
, wxFile::read
))
94 m_waveLength
= (int) fileWave
.Length();
96 m_waveData
= (byte
*)::GlobalLock(::GlobalAlloc(GMEM_MOVEABLE
| GMEM_SHARE
, m_waveLength
));
100 fileWave
.Read(m_waveData
, m_waveLength
);
106 bool wxWave::Play(bool async
, bool looped
) const
112 return ( ::PlaySound((LPCSTR
)m_waveData
, NULL
, SND_MEMORY
|
113 SND_NODEFAULT
| (async
? SND_ASYNC
: SND_SYNC
) | (looped
? (SND_LOOP
| SND_ASYNC
) : 0)) != 0 );
115 return ( ::sndPlaySound((LPCSTR
)m_waveData
, SND_MEMORY
|
116 SND_NODEFAULT
| (async
? SND_ASYNC
: SND_SYNC
) | (looped
? (SND_LOOP
| SND_ASYNC
) : 0)) != 0 );
125 HGLOBAL waveData
= ::GlobalHandle(m_waveData
);
127 HGLOBAL waveData
= GlobalPtrHandle(m_waveData
);
133 ::FreeResource(waveData
);
136 ::GlobalUnlock(waveData
);
137 ::GlobalFree(waveData
);