]> git.saurik.com Git - wxWidgets.git/commitdiff
added test for playing Windows resources
authorVadim Zeitlin <vadim@wxwidgets.org>
Fri, 29 Jul 2005 12:35:10 +0000 (12:35 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Fri, 29 Jul 2005 12:35:10 +0000 (12:35 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@34984 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

samples/sound/sound.bkl
samples/sound/sound.cpp
samples/sound/sound.rc [new file with mode: 0644]

index 07bb4b2df26336ff51ddf9c36304300648e99df8..4aac27d50c54b9f3ff4e3b8b333770e8922e72f9 100644 (file)
         <wx-lib>adv</wx-lib>
         <wx-lib>core</wx-lib>
         <wx-lib>base</wx-lib>
+        <win32-res>sound.rc</win32-res>
     </exe>
-    
+
     <wx-data id="data">
         <files>
-           9000g.wav  cuckoo.wav  doggrowl.wav  tinkalink2.wav
-       </files>
+           9000g.wav cuckoo.wav doggrowl.wav tinkalink2.wav
+        </files>
     </wx-data>
 
 </makefile>
index 7ddb31f5649a85adb121192d45a67136368ff1a6..54a6475b95fb5800dd7c297fb2217afbe35e53c0 100644 (file)
@@ -29,6 +29,7 @@
 
 #include "wx/sound.h"
 #include "wx/numdlg.h"
+#include "wx/textdlg.h"
 
 // ----------------------------------------------------------------------------
 // resources
@@ -66,6 +67,9 @@ public:
     void OnPlayLoop(wxCommandEvent& event);
 
     void OnSelectFile(wxCommandEvent& event);
+#ifdef __WXMSW__
+    void OnSelectResource(wxCommandEvent& event);
+#endif // __WXMSW__
     void OnQuit(wxCommandEvent& event);
     void OnAbout(wxCommandEvent& event);
 
@@ -73,8 +77,13 @@ public:
     
 
 private:
+    wxSound *CreateSound() const;
+
     wxSound*    m_sound;
     wxString    m_soundFile;
+#ifdef __WXMSW__
+    wxString    m_soundRes;
+#endif // __WXMSW__
     wxTextCtrl* m_tc;
     
     // any class wishing to process wxWidgets events must use this macro
@@ -89,13 +98,18 @@ private:
 enum
 {
     // menu items
+    Sound_SelectFile,
+#ifdef __WXMSW__
+    Sound_SelectResource,
+#endif // __WXMSW__
     Sound_Quit = wxID_EXIT,
-    Sound_About = wxID_ABOUT,
+
     Sound_PlaySync = wxID_HIGHEST + 1,
     Sound_PlayAsync,
     Sound_PlayAsyncOnStack,
     Sound_PlayLoop,
-    Sound_SelectFile
+
+    Sound_About = wxID_ABOUT
 };
 
 // ----------------------------------------------------------------------------
@@ -107,6 +121,9 @@ enum
 // simple menu events like this the static method is much simpler.
 BEGIN_EVENT_TABLE(MyFrame, wxFrame)
     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_About,            MyFrame::OnAbout)
     EVT_MENU(Sound_PlaySync,         MyFrame::OnPlaySync)
@@ -164,7 +181,10 @@ MyFrame::MyFrame(const wxString& title)
     wxMenu *helpMenu = new wxMenu;
     wxMenu *playMenu = new wxMenu;
     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"));
     playMenu->Append(Sound_PlaySync, _T("Play sound &synchronously\tCtrl+S"));
     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)
 {
@@ -207,12 +239,39 @@ void MyFrame::OnSelectFile(wxCommandEvent& WXUNUSED(event))
     if ( dlg.ShowModal() == wxID_OK )
     {
         m_soundFile = dlg.GetPath();
+#ifdef __WXMSW__
+        m_soundRes.clear();
+#endif // __WXMSW__
+
         delete m_sound;
         m_sound = NULL;
         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))
 {
     // true is to force the frame to close
@@ -223,7 +282,7 @@ void MyFrame::OnPlaySync(wxCommandEvent& WXUNUSED(event))
 {
     wxBusyCursor busy;
     if (!m_sound)
-        m_sound = new wxSound(m_soundFile);
+        m_sound = CreateSound();
     if (m_sound->IsOk())
         m_sound->Play(wxSOUND_SYNC);
 }
@@ -232,7 +291,7 @@ void MyFrame::OnPlayAsync(wxCommandEvent& WXUNUSED(event))
 {
     wxBusyCursor busy;
     if (!m_sound)
-        m_sound = new wxSound(m_soundFile);
+        m_sound = CreateSound();
     if (m_sound->IsOk())
         m_sound->Play(wxSOUND_ASYNC);
 }
@@ -249,7 +308,7 @@ void MyFrame::OnPlayLoop(wxCommandEvent& WXUNUSED(event))
 {
     wxBusyCursor busy;
     if (!m_sound)
-        m_sound = new wxSound(m_soundFile);
+        m_sound = CreateSound();
     if (m_sound->IsOk())
         m_sound->Play(wxSOUND_ASYNC | wxSOUND_LOOP);
 }
diff --git a/samples/sound/sound.rc b/samples/sound/sound.rc
new file mode 100644 (file)
index 0000000..21a5d21
--- /dev/null
@@ -0,0 +1,3 @@
+FromResource   WAVE    "cuckoo.wav"
+
+#include "../sample.rc"