]>
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__ ) || defined(wxUSE_NORLANDER_HEADERS)
40 #ifndef wxUSE_NORLANDER_HEADERS
41 #include "wx/msw/gnuwin32/extra.h"
47 : m_waveData(NULL
), m_waveLength(0), m_isResource(FALSE
)
51 wxWave::wxWave(const wxString
& sFileName
, bool isResource
)
52 : m_waveData(NULL
), m_waveLength(0), m_isResource(isResource
)
54 Create(sFileName
, isResource
);
57 wxWave::wxWave(int size
, const wxByte
* data
)
58 : m_waveData(NULL
), m_waveLength(0), m_isResource(FALSE
)
68 bool wxWave::Create(const wxString
& fileName
, bool isResource
)
77 #if defined(__WIN32__) && !defined(__TWIN32__)
79 hresInfo
= ::FindResourceW((HMODULE
) wxhInstance
, fileName
, _T("WAVE"));
81 hresInfo
= ::FindResourceA((HMODULE
) wxhInstance
, fileName
, _T("WAVE"));
84 hresInfo
= ::FindResource((HMODULE
) wxhInstance
, fileName
, _T("WAVE"));
89 HGLOBAL waveData
= ::LoadResource((HMODULE
) wxhInstance
, hresInfo
);
93 m_waveData
= (wxByte
*)::LockResource(waveData
);
94 m_waveLength
= (int) ::SizeofResource((HMODULE
) wxhInstance
, hresInfo
);
97 return (m_waveData
? TRUE
: FALSE
);
101 m_isResource
= FALSE
;
104 if (!fileWave
.Open(fileName
, wxFile::read
))
107 m_waveLength
= (int) fileWave
.Length();
109 m_waveData
= (wxByte
*)::GlobalLock(::GlobalAlloc(GMEM_MOVEABLE
| GMEM_SHARE
, m_waveLength
));
113 fileWave
.Read(m_waveData
, m_waveLength
);
119 bool wxWave::Create(int size
, const wxByte
* data
)
122 m_isResource
= FALSE
;
124 m_waveData
= (wxByte
*)::GlobalLock(::GlobalAlloc(GMEM_MOVEABLE
| GMEM_SHARE
, m_waveLength
));
128 for (int i
=0; i
<size
; i
++) m_waveData
[i
] = data
[i
];
132 bool wxWave::Play(bool async
, bool looped
) const
138 return ( ::PlaySound((LPCTSTR
)m_waveData
, NULL
, SND_MEMORY
|
139 SND_NODEFAULT
| (async
? SND_ASYNC
: SND_SYNC
) | (looped
? (SND_LOOP
| SND_ASYNC
) : 0)) != 0 );
141 return ( ::sndPlaySound((LPCSTR
)m_waveData
, SND_MEMORY
|
142 SND_NODEFAULT
| (async
? SND_ASYNC
: SND_SYNC
) | (looped
? (SND_LOOP
| SND_ASYNC
) : 0)) != 0 );
151 HGLOBAL waveData
= ::GlobalHandle(m_waveData
);
153 HGLOBAL waveData
= GlobalPtrHandle(m_waveData
);
159 ::FreeResource(waveData
);
162 ::GlobalUnlock(waveData
);
163 ::GlobalFree(waveData
);