]> git.saurik.com Git - wxWidgets.git/blame - src/msw/wave.cpp
set more event object fields for lbox dbl click events
[wxWidgets.git] / src / msw / wave.cpp
CommitLineData
2bda0e17
KB
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
c42404a5 9// Licence: wxWindows license
2bda0e17
KB
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
ee4f8c2a 24#include "wx/wx.h"
2bda0e17
KB
25#endif
26
ee4f8c2a
JS
27#include "wx/file.h"
28#include "wx/msw/wave.h"
29#include "wx/msw/private.h"
2bda0e17
KB
30
31#include <windows.h>
32#include <windowsx.h>
33
c42404a5
VZ
34#ifdef __GNUWIN32_OLD__
35 #include "wx/msw/gnuwin32/extra.h"
36#else
37 #include <mmsystem.h>
65fd5cb0 38#endif
2bda0e17 39
ee4f8c2a 40wxWave::wxWave()
0f358732 41 : m_waveData(NULL), m_waveLength(0), m_isResource(FALSE)
2bda0e17
KB
42{
43}
44
45wxWave::wxWave(const wxString& sFileName, bool isResource)
0f358732 46 : m_waveData(NULL), m_waveLength(0), m_isResource(isResource)
2bda0e17
KB
47{
48 Create(sFileName, isResource);
49}
50
57c208c5 51wxWave::wxWave(int size, const wxByte* data)
0f358732 52 : m_waveData(NULL), m_waveLength(0), m_isResource(FALSE)
321db4b6
JS
53{
54 Create(size, data);
55}
2bda0e17 56
ee4f8c2a 57wxWave::~wxWave()
2bda0e17
KB
58{
59 Free();
60}
61
62bool wxWave::Create(const wxString& fileName, bool isResource)
63{
64 Free();
65
66 if (isResource)
67 {
68 m_isResource = TRUE;
69
70 HRSRC hresInfo;
57c208c5 71#if defined(__WIN32__) && !defined(__TWIN32__)
837e5743 72#ifdef _UNICODE
223d09f6 73 hresInfo = ::FindResourceW((HMODULE) wxhInstance, fileName, wxT("WAVE"));
2bda0e17 74#else
223d09f6 75 hresInfo = ::FindResourceA((HMODULE) wxhInstance, fileName, wxT("WAVE"));
837e5743
OK
76#endif
77#else
223d09f6 78 hresInfo = ::FindResource((HMODULE) wxhInstance, fileName, wxT("WAVE"));
2bda0e17
KB
79#endif
80 if (!hresInfo)
81 return FALSE;
82
83 HGLOBAL waveData = ::LoadResource((HMODULE) wxhInstance, hresInfo);
84
85 if (waveData)
86 {
57c208c5 87 m_waveData= (wxByte*)::LockResource(waveData);
2bda0e17
KB
88 m_waveLength = (int) ::SizeofResource((HMODULE) wxhInstance, hresInfo);
89 }
90
91 return (m_waveData ? TRUE : FALSE);
92 }
93 else
94 {
95 m_isResource = FALSE;
96
97 wxFile fileWave;
98 if (!fileWave.Open(fileName, wxFile::read))
99 return FALSE;
100
101 m_waveLength = (int) fileWave.Length();
102
57c208c5 103 m_waveData = (wxByte*)::GlobalLock(::GlobalAlloc(GMEM_MOVEABLE | GMEM_SHARE, m_waveLength));
2bda0e17
KB
104 if (!m_waveData)
105 return FALSE;
106
107 fileWave.Read(m_waveData, m_waveLength);
108
109 return TRUE;
110 }
111}
112
57c208c5 113bool wxWave::Create(int size, const wxByte* data)
321db4b6
JS
114{
115 Free();
116 m_isResource = FALSE;
117 m_waveLength=size;
57c208c5 118 m_waveData = (wxByte*)::GlobalLock(::GlobalAlloc(GMEM_MOVEABLE | GMEM_SHARE, m_waveLength));
321db4b6
JS
119 if (!m_waveData)
120 return FALSE;
121
122 for (int i=0; i<size; i++) m_waveData[i] = data[i];
123 return TRUE;
124}
125
2bda0e17
KB
126bool wxWave::Play(bool async, bool looped) const
127{
128 if (!IsOk())
129 return FALSE;
130
131#ifdef __WIN32__
837e5743 132 return ( ::PlaySound((LPCTSTR)m_waveData, NULL, SND_MEMORY |
2bda0e17
KB
133 SND_NODEFAULT | (async ? SND_ASYNC : SND_SYNC) | (looped ? (SND_LOOP | SND_ASYNC) : 0)) != 0 );
134#else
135 return ( ::sndPlaySound((LPCSTR)m_waveData, SND_MEMORY |
136 SND_NODEFAULT | (async ? SND_ASYNC : SND_SYNC) | (looped ? (SND_LOOP | SND_ASYNC) : 0)) != 0 );
137#endif
138}
139
ee4f8c2a 140bool wxWave::Free()
2bda0e17
KB
141{
142 if (m_waveData)
143 {
144#ifdef __WIN32__
145 HGLOBAL waveData = ::GlobalHandle(m_waveData);
146#else
147 HGLOBAL waveData = GlobalPtrHandle(m_waveData);
148#endif
149
150 if (waveData)
151 {
152 if (m_isResource)
153 ::FreeResource(waveData);
154 else
155 {
156 ::GlobalUnlock(waveData);
157 ::GlobalFree(waveData);
158 }
159
160 m_waveData = NULL;
161 m_waveLength = 0;
162 return TRUE;
163 }
164 }
165 return FALSE;
166}
167
168