]>
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"
34 #if defined(__GNUWIN32_OLD__) && !defined(__CYGWIN10__)
35 #include "wx/msw/gnuwin32/extra.h"
41 : m_waveData(NULL
), m_waveLength(0), m_isResource(FALSE
)
45 wxWave::wxWave(const wxString
& sFileName
, bool isResource
)
46 : m_waveData(NULL
), m_waveLength(0), m_isResource(isResource
)
48 Create(sFileName
, isResource
);
51 wxWave::wxWave(int size
, const wxByte
* data
)
52 : m_waveData(NULL
), m_waveLength(0), m_isResource(FALSE
)
62 bool wxWave::Create(const wxString
& fileName
, bool isResource
)
71 #if defined(__WIN32__) && !defined(__TWIN32__)
73 hresInfo
= ::FindResourceW((HMODULE
) wxhInstance
, fileName
, wxT("WAVE"));
75 hresInfo
= ::FindResourceA((HMODULE
) wxhInstance
, fileName
, wxT("WAVE"));
78 hresInfo
= ::FindResource((HMODULE
) wxhInstance
, fileName
, wxT("WAVE"));
83 HGLOBAL waveData
= ::LoadResource((HMODULE
) wxhInstance
, hresInfo
);
87 m_waveData
= (wxByte
*)::LockResource(waveData
);
88 m_waveLength
= (int) ::SizeofResource((HMODULE
) wxhInstance
, hresInfo
);
91 return (m_waveData
? TRUE
: FALSE
);
98 if (!fileWave
.Open(fileName
, wxFile::read
))
101 m_waveLength
= (int) fileWave
.Length();
103 m_waveData
= (wxByte
*)::GlobalLock(::GlobalAlloc(GMEM_MOVEABLE
| GMEM_SHARE
, m_waveLength
));
107 fileWave
.Read(m_waveData
, m_waveLength
);
113 bool wxWave::Create(int size
, const wxByte
* data
)
116 m_isResource
= FALSE
;
118 m_waveData
= (wxByte
*)::GlobalLock(::GlobalAlloc(GMEM_MOVEABLE
| GMEM_SHARE
, m_waveLength
));
122 for (int i
=0; i
<size
; i
++) m_waveData
[i
] = data
[i
];
126 bool wxWave::Play(bool async
, bool looped
) const
132 return ( ::PlaySound((LPCTSTR
)m_waveData
, NULL
, SND_MEMORY
|
133 SND_NODEFAULT
| (async
? SND_ASYNC
: SND_SYNC
) | (looped
? (SND_LOOP
| SND_ASYNC
) : 0)) != 0 );
135 return ( ::sndPlaySound((LPCSTR
)m_waveData
, SND_MEMORY
|
136 SND_NODEFAULT
| (async
? SND_ASYNC
: SND_SYNC
) | (looped
? (SND_LOOP
| SND_ASYNC
) : 0)) != 0 );
145 HGLOBAL waveData
= ::GlobalHandle(m_waveData
);
147 HGLOBAL waveData
= GlobalPtrHandle(m_waveData
);
153 ::FreeResource(waveData
);
156 ::GlobalUnlock(waveData
);
157 ::GlobalFree(waveData
);