]>
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"
40 #include "wx/msw/gnuwin32/extra.h"
45 : m_waveData(NULL
), m_waveLength(0), m_isResource(FALSE
)
49 wxWave::wxWave(const wxString
& sFileName
, bool isResource
)
50 : m_waveData(NULL
), m_waveLength(0), m_isResource(isResource
)
52 Create(sFileName
, isResource
);
55 wxWave::wxWave(int size
, const wxByte
* data
)
56 : m_waveData(NULL
), m_waveLength(0), m_isResource(FALSE
)
66 bool wxWave::Create(const wxString
& fileName
, bool isResource
)
75 #if defined(__WIN32__) && !defined(__TWIN32__)
77 hresInfo
= ::FindResourceW((HMODULE
) wxhInstance
, fileName
, _T("WAVE"));
79 hresInfo
= ::FindResourceA((HMODULE
) wxhInstance
, fileName
, _T("WAVE"));
82 hresInfo
= ::FindResource((HMODULE
) wxhInstance
, fileName
, _T("WAVE"));
87 HGLOBAL waveData
= ::LoadResource((HMODULE
) wxhInstance
, hresInfo
);
91 m_waveData
= (wxByte
*)::LockResource(waveData
);
92 m_waveLength
= (int) ::SizeofResource((HMODULE
) wxhInstance
, hresInfo
);
95 return (m_waveData
? TRUE
: FALSE
);
102 if (!fileWave
.Open(fileName
, wxFile::read
))
105 m_waveLength
= (int) fileWave
.Length();
107 m_waveData
= (wxByte
*)::GlobalLock(::GlobalAlloc(GMEM_MOVEABLE
| GMEM_SHARE
, m_waveLength
));
111 fileWave
.Read(m_waveData
, m_waveLength
);
117 bool wxWave::Create(int size
, const wxByte
* data
)
120 m_isResource
= FALSE
;
122 m_waveData
= (wxByte
*)::GlobalLock(::GlobalAlloc(GMEM_MOVEABLE
| GMEM_SHARE
, m_waveLength
));
126 for (int i
=0; i
<size
; i
++) m_waveData
[i
] = data
[i
];
130 bool wxWave::Play(bool async
, bool looped
) const
136 return ( ::PlaySound((LPCTSTR
)m_waveData
, NULL
, SND_MEMORY
|
137 SND_NODEFAULT
| (async
? SND_ASYNC
: SND_SYNC
) | (looped
? (SND_LOOP
| SND_ASYNC
) : 0)) != 0 );
139 return ( ::sndPlaySound((LPCSTR
)m_waveData
, SND_MEMORY
|
140 SND_NODEFAULT
| (async
? SND_ASYNC
: SND_SYNC
) | (looped
? (SND_LOOP
| SND_ASYNC
) : 0)) != 0 );
149 HGLOBAL waveData
= ::GlobalHandle(m_waveData
);
151 HGLOBAL waveData
= GlobalPtrHandle(m_waveData
);
157 ::FreeResource(waveData
);
160 ::GlobalUnlock(waveData
);
161 ::GlobalFree(waveData
);