]>
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__)
30 #include "wx/msw/wave.h"
31 #include "wx/msw/private.h"
36 #if defined(__GNUWIN32_OLD__) && !defined(__CYGWIN10__)
37 #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 wxByte
* data
)
54 : m_waveData(NULL
), m_waveLength(0), m_isResource(FALSE
)
64 bool wxWave::Create(const wxString
& fileName
, bool isResource
)
73 #if defined(__WIN32__) && !defined(__TWIN32__)
75 hresInfo
= ::FindResourceW((HMODULE
) wxhInstance
, fileName
, wxT("WAVE"));
77 hresInfo
= ::FindResourceA((HMODULE
) wxhInstance
, fileName
, wxT("WAVE"));
80 hresInfo
= ::FindResource((HMODULE
) wxhInstance
, fileName
, wxT("WAVE"));
85 HGLOBAL waveData
= ::LoadResource((HMODULE
) wxhInstance
, hresInfo
);
89 m_waveData
= (wxByte
*)::LockResource(waveData
);
90 m_waveLength
= (int) ::SizeofResource((HMODULE
) wxhInstance
, hresInfo
);
93 return (m_waveData
? TRUE
: FALSE
);
100 if (!fileWave
.Open(fileName
, wxFile::read
))
103 m_waveLength
= (int) fileWave
.Length();
105 m_waveData
= (wxByte
*)::GlobalLock(::GlobalAlloc(GMEM_MOVEABLE
| GMEM_SHARE
, m_waveLength
));
109 fileWave
.Read(m_waveData
, m_waveLength
);
115 bool wxWave::Create(int size
, const wxByte
* data
)
118 m_isResource
= FALSE
;
120 m_waveData
= (wxByte
*)::GlobalLock(::GlobalAlloc(GMEM_MOVEABLE
| GMEM_SHARE
, m_waveLength
));
124 for (int i
=0; i
<size
; i
++) m_waveData
[i
] = data
[i
];
128 bool wxWave::Play(bool async
, bool looped
) const
134 return ( ::PlaySound((LPCTSTR
)m_waveData
, NULL
, SND_MEMORY
|
135 SND_NODEFAULT
| (async
? SND_ASYNC
: SND_SYNC
) | (looped
? (SND_LOOP
| SND_ASYNC
) : 0)) != 0 );
137 return ( ::sndPlaySound((LPCSTR
)m_waveData
, SND_MEMORY
|
138 SND_NODEFAULT
| (async
? SND_ASYNC
: SND_SYNC
) | (looped
? (SND_LOOP
| SND_ASYNC
) : 0)) != 0 );
147 HGLOBAL waveData
= ::GlobalHandle(m_waveData
);
149 HGLOBAL waveData
= GlobalPtrHandle(m_waveData
);
155 ::FreeResource(waveData
);
158 ::GlobalUnlock(waveData
);
159 ::GlobalFree(waveData
);