]>
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"
40 #include "wx/msw/gnuwin32/extra.h"
45 : m_waveData(NULL
), m_waveLength(0), m_isResource(FALSE
)
49 wxWave::wxWave(const wxString
& sFileName
, bool isResource
)
50 : m_waveData(NULL
), m_waveLength(0), m_isResource(isResource
)
52 Create(sFileName
, isResource
);
55 wxWave::wxWave(int size
, const wxByte
* data
)
56 : m_waveData(NULL
), m_waveLength(0), m_isResource(FALSE
)
66 bool wxWave::Create(const wxString
& fileName
, bool isResource
)
75 #if defined(__WIN32__) && !defined(__TWIN32__)
76 hresInfo
= ::FindResourceA((HMODULE
) wxhInstance
, fileName
, "WAVE");
78 hresInfo
= ::FindResource((HMODULE
) wxhInstance
, fileName
, "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((LPCSTR
)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
);