added test for playing Windows resources

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@34984 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
2005-07-29 12:35:10 +00:00
parent 2be57a5131
commit 941821d8ac
3 changed files with 72 additions and 9 deletions

View File

@@ -10,12 +10,13 @@
<wx-lib>adv</wx-lib> <wx-lib>adv</wx-lib>
<wx-lib>core</wx-lib> <wx-lib>core</wx-lib>
<wx-lib>base</wx-lib> <wx-lib>base</wx-lib>
<win32-res>sound.rc</win32-res>
</exe> </exe>
<wx-data id="data"> <wx-data id="data">
<files> <files>
9000g.wav cuckoo.wav doggrowl.wav tinkalink2.wav 9000g.wav cuckoo.wav doggrowl.wav tinkalink2.wav
</files> </files>
</wx-data> </wx-data>
</makefile> </makefile>

View File

@@ -29,6 +29,7 @@
#include "wx/sound.h" #include "wx/sound.h"
#include "wx/numdlg.h" #include "wx/numdlg.h"
#include "wx/textdlg.h"
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// resources // resources
@@ -66,6 +67,9 @@ public:
void OnPlayLoop(wxCommandEvent& event); void OnPlayLoop(wxCommandEvent& event);
void OnSelectFile(wxCommandEvent& event); void OnSelectFile(wxCommandEvent& event);
#ifdef __WXMSW__
void OnSelectResource(wxCommandEvent& event);
#endif // __WXMSW__
void OnQuit(wxCommandEvent& event); void OnQuit(wxCommandEvent& event);
void OnAbout(wxCommandEvent& event); void OnAbout(wxCommandEvent& event);
@@ -73,8 +77,13 @@ public:
private: private:
wxSound *CreateSound() const;
wxSound* m_sound; wxSound* m_sound;
wxString m_soundFile; wxString m_soundFile;
#ifdef __WXMSW__
wxString m_soundRes;
#endif // __WXMSW__
wxTextCtrl* m_tc; wxTextCtrl* m_tc;
// any class wishing to process wxWidgets events must use this macro // any class wishing to process wxWidgets events must use this macro
@@ -89,13 +98,18 @@ private:
enum enum
{ {
// menu items // menu items
Sound_SelectFile,
#ifdef __WXMSW__
Sound_SelectResource,
#endif // __WXMSW__
Sound_Quit = wxID_EXIT, Sound_Quit = wxID_EXIT,
Sound_About = wxID_ABOUT,
Sound_PlaySync = wxID_HIGHEST + 1, Sound_PlaySync = wxID_HIGHEST + 1,
Sound_PlayAsync, Sound_PlayAsync,
Sound_PlayAsyncOnStack, Sound_PlayAsyncOnStack,
Sound_PlayLoop, Sound_PlayLoop,
Sound_SelectFile
Sound_About = wxID_ABOUT
}; };
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
@@ -107,6 +121,9 @@ enum
// simple menu events like this the static method is much simpler. // simple menu events like this the static method is much simpler.
BEGIN_EVENT_TABLE(MyFrame, wxFrame) BEGIN_EVENT_TABLE(MyFrame, wxFrame)
EVT_MENU(Sound_SelectFile, MyFrame::OnSelectFile) EVT_MENU(Sound_SelectFile, MyFrame::OnSelectFile)
#ifdef __WXMSW__
EVT_MENU(Sound_SelectResource, MyFrame::OnSelectResource)
#endif // __WXMSW__
EVT_MENU(Sound_Quit, MyFrame::OnQuit) EVT_MENU(Sound_Quit, MyFrame::OnQuit)
EVT_MENU(Sound_About, MyFrame::OnAbout) EVT_MENU(Sound_About, MyFrame::OnAbout)
EVT_MENU(Sound_PlaySync, MyFrame::OnPlaySync) EVT_MENU(Sound_PlaySync, MyFrame::OnPlaySync)
@@ -164,7 +181,10 @@ MyFrame::MyFrame(const wxString& title)
wxMenu *helpMenu = new wxMenu; wxMenu *helpMenu = new wxMenu;
wxMenu *playMenu = new wxMenu; wxMenu *playMenu = new wxMenu;
helpMenu->Append(Sound_About, _T("&About...\tF1"), _T("Show about dialog")); helpMenu->Append(Sound_About, _T("&About...\tF1"), _T("Show about dialog"));
menuFile->Append(Sound_SelectFile, _T("&Select WAV file\tCtrl+O"), _T("Select a new wav file to play")); menuFile->Append(Sound_SelectFile, _T("Select WAV &file\tCtrl+O"), _T("Select a new wav file to play"));
#ifdef __WXMSW__
menuFile->Append(Sound_SelectResource, _T("Select WAV &resource\tCtrl+R"), _T("Select a new resource to play"));
#endif // __WXMSW__
menuFile->Append(Sound_Quit, _T("E&xit\tAlt-X"), _T("Quit this program")); menuFile->Append(Sound_Quit, _T("E&xit\tAlt-X"), _T("Quit this program"));
playMenu->Append(Sound_PlaySync, _T("Play sound &synchronously\tCtrl+S")); playMenu->Append(Sound_PlaySync, _T("Play sound &synchronously\tCtrl+S"));
playMenu->Append(Sound_PlayAsync, _T("Play sound &asynchronously\tCtrl+A")); playMenu->Append(Sound_PlayAsync, _T("Play sound &asynchronously\tCtrl+A"));
@@ -187,6 +207,18 @@ MyFrame::MyFrame(const wxString& title)
} }
wxSound *MyFrame::CreateSound() const
{
#ifdef __WXMSW__
if ( !m_soundRes.empty() )
{
return new wxSound(m_soundRes, true);
}
#endif // __WXMSW__
return new wxSound(m_soundFile);
}
void MyFrame::NotifyUsingFile(const wxString& name) void MyFrame::NotifyUsingFile(const wxString& name)
{ {
@@ -207,12 +239,39 @@ void MyFrame::OnSelectFile(wxCommandEvent& WXUNUSED(event))
if ( dlg.ShowModal() == wxID_OK ) if ( dlg.ShowModal() == wxID_OK )
{ {
m_soundFile = dlg.GetPath(); m_soundFile = dlg.GetPath();
#ifdef __WXMSW__
m_soundRes.clear();
#endif // __WXMSW__
delete m_sound; delete m_sound;
m_sound = NULL; m_sound = NULL;
NotifyUsingFile(m_soundFile); NotifyUsingFile(m_soundFile);
} }
} }
#ifdef __WXMSW__
void MyFrame::OnSelectResource(wxCommandEvent& WXUNUSED(event))
{
m_soundRes = wxGetTextFromUser
(
_T("Enter resource name:"),
_T("wxWidgets Sound Sample"),
_T("FromResource"),
this
);
if ( m_soundRes.empty() )
return;
m_soundFile.clear();
delete m_sound;
m_sound = NULL;
NotifyUsingFile(_T("Windows WAV resource"));
}
#endif // __WXMSW__
void MyFrame::OnQuit(wxCommandEvent& WXUNUSED(event)) void MyFrame::OnQuit(wxCommandEvent& WXUNUSED(event))
{ {
// true is to force the frame to close // true is to force the frame to close
@@ -223,7 +282,7 @@ void MyFrame::OnPlaySync(wxCommandEvent& WXUNUSED(event))
{ {
wxBusyCursor busy; wxBusyCursor busy;
if (!m_sound) if (!m_sound)
m_sound = new wxSound(m_soundFile); m_sound = CreateSound();
if (m_sound->IsOk()) if (m_sound->IsOk())
m_sound->Play(wxSOUND_SYNC); m_sound->Play(wxSOUND_SYNC);
} }
@@ -232,7 +291,7 @@ void MyFrame::OnPlayAsync(wxCommandEvent& WXUNUSED(event))
{ {
wxBusyCursor busy; wxBusyCursor busy;
if (!m_sound) if (!m_sound)
m_sound = new wxSound(m_soundFile); m_sound = CreateSound();
if (m_sound->IsOk()) if (m_sound->IsOk())
m_sound->Play(wxSOUND_ASYNC); m_sound->Play(wxSOUND_ASYNC);
} }
@@ -249,7 +308,7 @@ void MyFrame::OnPlayLoop(wxCommandEvent& WXUNUSED(event))
{ {
wxBusyCursor busy; wxBusyCursor busy;
if (!m_sound) if (!m_sound)
m_sound = new wxSound(m_soundFile); m_sound = CreateSound();
if (m_sound->IsOk()) if (m_sound->IsOk())
m_sound->Play(wxSOUND_ASYNC | wxSOUND_LOOP); m_sound->Play(wxSOUND_ASYNC | wxSOUND_LOOP);
} }

3
samples/sound/sound.rc Normal file
View File

@@ -0,0 +1,3 @@
FromResource WAVE "cuckoo.wav"
#include "../sample.rc"