]>
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"
38 : m_waveData(NULL
), m_waveLength(0), m_isResource(false)
42 wxSound::wxSound(const wxString
& sFileName
, bool isResource
)
43 : m_waveData(NULL
), m_waveLength(0), m_isResource(isResource
)
45 Create(sFileName
, isResource
);
48 wxSound::wxSound(int size
, const wxByte
* data
)
49 : m_waveData(NULL
), m_waveLength(0), m_isResource(false)
59 bool wxSound::Create(const wxString
& fileName
, bool isResource
)
68 hresInfo
= ::FindResource((HMODULE
) wxhInstance
, fileName
, wxT("WAVE"));
72 HGLOBAL waveData
= ::LoadResource((HMODULE
) wxhInstance
, hresInfo
);
76 m_waveData
= (wxByte
*)::LockResource(waveData
);
77 m_waveLength
= (int) ::SizeofResource((HMODULE
) wxhInstance
, hresInfo
);
80 return (m_waveData
? true : false);
87 if (!fileWave
.Open(fileName
, wxFile::read
))
90 m_waveLength
= (int) fileWave
.Length();
92 m_waveData
= (wxByte
*)GlobalLock(GlobalAlloc(GMEM_MOVEABLE
| GMEM_SHARE
, m_waveLength
));
96 fileWave
.Read(m_waveData
, m_waveLength
);
102 bool wxSound::Create(int size
, const wxByte
* data
)
107 m_waveData
= (wxByte
*)GlobalLock(GlobalAlloc(GMEM_MOVEABLE
| GMEM_SHARE
, m_waveLength
));
111 for (int i
=0; i
<size
; i
++) m_waveData
[i
] = data
[i
];
115 bool wxSound::DoPlay(unsigned flags
) const
120 return (::PlaySound((LPCTSTR
)m_waveData
, NULL
,
121 SND_MEMORY
| SND_NODEFAULT
|
122 ((flags
& wxSOUND_ASYNC
) ? SND_ASYNC
: SND_SYNC
) |
123 ((flags
& wxSOUND_LOOP
) ? (SND_LOOP
| SND_ASYNC
) : 0))
132 HGLOBAL waveData
= (HGLOBAL
) m_waveData
;
134 HGLOBAL waveData
= GlobalHandle(m_waveData
);
141 ::FreeResource(waveData
);
145 GlobalUnlock(waveData
);
146 GlobalFree(waveData
);
157 /*static*/ void wxSound::Stop()
159 ::PlaySound(NULL
, NULL
, 0);
162 #endif // wxUSE_SOUND