]>
git.saurik.com Git - wxWidgets.git/blob - src/msw/sound.cpp
1 /////////////////////////////////////////////////////////////////////////////
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
13 #pragma implementation "sound.h"
16 // For compilers that support precompilation, includes "wx.h".
17 #include "wx/wxprec.h"
19 #if defined(__BORLANDC__)
31 #include "wx/msw/private.h"
35 #if defined(__GNUWIN32_OLD__) && !defined(__CYGWIN10__)
36 #include "wx/msw/gnuwin32/extra.h"
42 : m_waveData(NULL
), m_waveLength(0), m_isResource(false)
46 wxSound::wxSound(const wxString
& sFileName
, bool isResource
)
47 : m_waveData(NULL
), m_waveLength(0), m_isResource(isResource
)
49 Create(sFileName
, isResource
);
52 wxSound::wxSound(int size
, const wxByte
* data
)
53 : m_waveData(NULL
), m_waveLength(0), m_isResource(false)
63 bool wxSound::Create(const wxString
& fileName
, bool isResource
)
72 hresInfo
= ::FindResource((HMODULE
) wxhInstance
, fileName
, wxT("WAVE"));
76 HGLOBAL waveData
= ::LoadResource((HMODULE
) wxhInstance
, hresInfo
);
80 m_waveData
= (wxByte
*)::LockResource(waveData
);
81 m_waveLength
= (int) ::SizeofResource((HMODULE
) wxhInstance
, hresInfo
);
84 return (m_waveData
? true : false);
91 if (!fileWave
.Open(fileName
, wxFile::read
))
94 m_waveLength
= (int) fileWave
.Length();
96 m_waveData
= (wxByte
*)GlobalLock(GlobalAlloc(GMEM_MOVEABLE
| GMEM_SHARE
, m_waveLength
));
100 fileWave
.Read(m_waveData
, m_waveLength
);
106 bool wxSound::Create(int size
, const wxByte
* data
)
111 m_waveData
= (wxByte
*)GlobalLock(GlobalAlloc(GMEM_MOVEABLE
| GMEM_SHARE
, m_waveLength
));
115 for (int i
=0; i
<size
; i
++) m_waveData
[i
] = data
[i
];
119 bool wxSound::DoPlay(unsigned flags
) const
124 return (::PlaySound((LPCTSTR
)m_waveData
, NULL
,
125 SND_MEMORY
| SND_NODEFAULT
|
126 ((flags
& wxSOUND_ASYNC
) ? SND_ASYNC
: SND_SYNC
) |
127 ((flags
& wxSOUND_LOOP
) ? (SND_LOOP
| SND_ASYNC
) : 0))
136 HGLOBAL waveData
= (HGLOBAL
) m_waveData
;
138 HGLOBAL waveData
= GlobalHandle(m_waveData
);
145 ::FreeResource(waveData
);
149 GlobalUnlock(waveData
);
150 GlobalFree(waveData
);
161 /*static*/ void wxSound::Stop()
163 ::PlaySound(NULL
, NULL
, 0);
166 #endif // wxUSE_SOUND