]>
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_waveData(NULL
), m_waveLength(0), m_isResource(FALSE
)
47 wxWave::wxWave(const wxString
& sFileName
, bool isResource
)
48 : m_waveData(NULL
), m_waveLength(0), m_isResource(isResource
)
50 Create(sFileName
, isResource
);
53 wxWave::wxWave(int size
, const byte
* data
)
54 : m_waveData(NULL
), m_waveLength(0), m_isResource(FALSE
)
64 bool wxWave::Create(const wxString
& fileName
, bool isResource
)
74 hresInfo
= ::FindResourceA((HMODULE
) wxhInstance
, fileName
, "WAVE");
76 hresInfo
= ::FindResource((HMODULE
) wxhInstance
, fileName
, "WAVE");
81 HGLOBAL waveData
= ::LoadResource((HMODULE
) wxhInstance
, hresInfo
);
85 m_waveData
= (byte
*)::LockResource(waveData
);
86 m_waveLength
= (int) ::SizeofResource((HMODULE
) wxhInstance
, hresInfo
);
89 return (m_waveData
? TRUE
: FALSE
);
96 if (!fileWave
.Open(fileName
, wxFile::read
))
99 m_waveLength
= (int) fileWave
.Length();
101 m_waveData
= (byte
*)::GlobalLock(::GlobalAlloc(GMEM_MOVEABLE
| GMEM_SHARE
, m_waveLength
));
105 fileWave
.Read(m_waveData
, m_waveLength
);
111 bool wxWave::Create(int size
, const byte
* data
)
114 m_isResource
= FALSE
;
116 m_waveData
= (byte
*)::GlobalLock(::GlobalAlloc(GMEM_MOVEABLE
| GMEM_SHARE
, m_waveLength
));
120 for (int i
=0; i
<size
; i
++) m_waveData
[i
] = data
[i
];
124 bool wxWave::Play(bool async
, bool looped
) const
130 return ( ::PlaySound((LPCSTR
)m_waveData
, NULL
, SND_MEMORY
|
131 SND_NODEFAULT
| (async
? SND_ASYNC
: SND_SYNC
) | (looped
? (SND_LOOP
| SND_ASYNC
) : 0)) != 0 );
133 return ( ::sndPlaySound((LPCSTR
)m_waveData
, SND_MEMORY
|
134 SND_NODEFAULT
| (async
? SND_ASYNC
: SND_SYNC
) | (looped
? (SND_LOOP
| SND_ASYNC
) : 0)) != 0 );
143 HGLOBAL waveData
= ::GlobalHandle(m_waveData
);
145 HGLOBAL waveData
= GlobalPtrHandle(m_waveData
);
151 ::FreeResource(waveData
);
154 ::GlobalUnlock(waveData
);
155 ::GlobalFree(waveData
);