]> git.saurik.com Git - wxWidgets.git/blob - src/msw/wave.cpp
Crude hack to enable PageUp/DownKeys when controlbar is enabled.
[wxWidgets.git] / src / msw / wave.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wave.cpp
3 // Purpose: wxWave
4 // Author: Julian Smart
5 // Modified by:
6 // Created: 04/01/98
7 // RCS-ID: $Id$
8 // Copyright: (c) Julian Smart and Markus Holzem
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
11
12 #ifdef __GNUG__
13 #pragma implementation "wave.h"
14 #endif
15
16 // For compilers that support precompilation, includes "wx.h".
17 #include "wx/wxprec.h"
18
19 #if defined(__BORLANDC__)
20 #pragma hdrstop
21 #endif
22
23 #ifndef WX_PRECOMP
24 #include "wx/wx.h"
25 #endif
26
27 #include "wx/file.h"
28 #include "wx/msw/wave.h"
29 #include "wx/msw/private.h"
30
31 #include <windows.h>
32 #include <windowsx.h>
33
34 #ifndef __GNUWIN32__
35 #include <mmsystem.h>
36 #endif
37
38 #ifndef __TWIN32__
39 #ifdef __GNUWIN32__
40 #include "wx/msw/gnuwin32/extra.h"
41 #endif
42 #endif
43
44 wxWave::wxWave()
45 : m_waveData(NULL), m_waveLength(0), m_isResource(FALSE)
46 {
47 }
48
49 wxWave::wxWave(const wxString& sFileName, bool isResource)
50 : m_waveData(NULL), m_waveLength(0), m_isResource(isResource)
51 {
52 Create(sFileName, isResource);
53 }
54
55 wxWave::wxWave(int size, const wxByte* data)
56 : m_waveData(NULL), m_waveLength(0), m_isResource(FALSE)
57 {
58 Create(size, data);
59 }
60
61 wxWave::~wxWave()
62 {
63 Free();
64 }
65
66 bool wxWave::Create(const wxString& fileName, bool isResource)
67 {
68 Free();
69
70 if (isResource)
71 {
72 m_isResource = TRUE;
73
74 HRSRC hresInfo;
75 #if defined(__WIN32__) && !defined(__TWIN32__)
76 #ifdef _UNICODE
77 hresInfo = ::FindResourceW((HMODULE) wxhInstance, fileName, _T("WAVE"));
78 #else
79 hresInfo = ::FindResourceA((HMODULE) wxhInstance, fileName, _T("WAVE"));
80 #endif
81 #else
82 hresInfo = ::FindResource((HMODULE) wxhInstance, fileName, _T("WAVE"));
83 #endif
84 if (!hresInfo)
85 return FALSE;
86
87 HGLOBAL waveData = ::LoadResource((HMODULE) wxhInstance, hresInfo);
88
89 if (waveData)
90 {
91 m_waveData= (wxByte*)::LockResource(waveData);
92 m_waveLength = (int) ::SizeofResource((HMODULE) wxhInstance, hresInfo);
93 }
94
95 return (m_waveData ? TRUE : FALSE);
96 }
97 else
98 {
99 m_isResource = FALSE;
100
101 wxFile fileWave;
102 if (!fileWave.Open(fileName, wxFile::read))
103 return FALSE;
104
105 m_waveLength = (int) fileWave.Length();
106
107 m_waveData = (wxByte*)::GlobalLock(::GlobalAlloc(GMEM_MOVEABLE | GMEM_SHARE, m_waveLength));
108 if (!m_waveData)
109 return FALSE;
110
111 fileWave.Read(m_waveData, m_waveLength);
112
113 return TRUE;
114 }
115 }
116
117 bool wxWave::Create(int size, const wxByte* data)
118 {
119 Free();
120 m_isResource = FALSE;
121 m_waveLength=size;
122 m_waveData = (wxByte*)::GlobalLock(::GlobalAlloc(GMEM_MOVEABLE | GMEM_SHARE, m_waveLength));
123 if (!m_waveData)
124 return FALSE;
125
126 for (int i=0; i<size; i++) m_waveData[i] = data[i];
127 return TRUE;
128 }
129
130 bool wxWave::Play(bool async, bool looped) const
131 {
132 if (!IsOk())
133 return FALSE;
134
135 #ifdef __WIN32__
136 return ( ::PlaySound((LPCTSTR)m_waveData, NULL, SND_MEMORY |
137 SND_NODEFAULT | (async ? SND_ASYNC : SND_SYNC) | (looped ? (SND_LOOP | SND_ASYNC) : 0)) != 0 );
138 #else
139 return ( ::sndPlaySound((LPCSTR)m_waveData, SND_MEMORY |
140 SND_NODEFAULT | (async ? SND_ASYNC : SND_SYNC) | (looped ? (SND_LOOP | SND_ASYNC) : 0)) != 0 );
141 #endif
142 }
143
144 bool wxWave::Free()
145 {
146 if (m_waveData)
147 {
148 #ifdef __WIN32__
149 HGLOBAL waveData = ::GlobalHandle(m_waveData);
150 #else
151 HGLOBAL waveData = GlobalPtrHandle(m_waveData);
152 #endif
153
154 if (waveData)
155 {
156 if (m_isResource)
157 ::FreeResource(waveData);
158 else
159 {
160 ::GlobalUnlock(waveData);
161 ::GlobalFree(waveData);
162 }
163
164 m_waveData = NULL;
165 m_waveLength = 0;
166 return TRUE;
167 }
168 }
169 return FALSE;
170 }
171
172