mmboard.cpp
来自「Wxpython Implemented on Windows CE, Sou」· C++ 代码 · 共 592 行 · 第 1/2 页
CPP
592 行
/////////////////////////////////////////////////////////////////////////////
// Name: mmboard.cpp
// Purpose: Multimedia Library sample
// Author: Guilhem Lavaux (created from minimal by J. Smart)
// Modified by:
// Created: 13/02/2000
// RCS-ID: $Id: mmboard.cpp,v 1.18 2005/09/23 12:47:27 MR Exp $
// Copyright: (c) Guilhem Lavaux
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
// ============================================================================
// declarations
// ============================================================================
// ----------------------------------------------------------------------------
// headers
// ----------------------------------------------------------------------------
// For compilers that support precompilation, includes "wx/wx.h".
#include "wx/wxprec.h"
#ifdef __BORLANDC__
#pragma hdrstop
#endif
// for all others, include the necessary headers (this file is usually all you
// need because it includes almost all "standard" wxWidgets headers
#ifndef WX_PRECOMP
#include "wx/wx.h"
#endif
// ----------------------------------------------------------------------------
// ressources
// ----------------------------------------------------------------------------
// the application icon
#if defined(__WXGTK__) || defined(__WXX11__) || defined(__WXMOTIF__) || defined(__WXMAC__)
#include "mondrian.xpm"
#endif
// include multimedia classes
#include "wx/mmedia/sndbase.h"
#ifdef __WIN32__
#include "wx/mmedia/sndwin.h"
#endif
#ifdef __UNIX__
#include "wx/mmedia/sndoss.h"
#include "wx/mmedia/sndesd.h"
#endif
#include "wx/statline.h"
#include "wx/stattext.h"
// include personnal classes
#include "mmboard.h"
#include "mmbman.h"
#include "play.xpm"
#include "stop.xpm"
#include "eject.xpm"
#include "pause.xpm"
// ----------------------------------------------------------------------------
// private classes
// ----------------------------------------------------------------------------
// Main Multimedia Board frame
class MMBoardFrame : public wxFrame
{
public:
// ctor(s)
MMBoardFrame(const wxString& title, const wxPoint& pos, const wxSize& size);
// dtor
~MMBoardFrame();
// event handlers
void OnQuit(wxCommandEvent& event);
void OnAbout(wxCommandEvent& event);
void OnOpen(wxCommandEvent& event);
void OnPlay(wxCommandEvent& event);
void OnStop(wxCommandEvent& event);
void OnPause(wxCommandEvent& event);
void OnEject(wxCommandEvent& event);
void OnRefreshInfo(wxEvent& event);
void OnSetPosition(wxCommandEvent& event);
void OpenVideoWindow();
void CloseVideoWindow();
private:
// any class wishing to process wxWidgets events must use this macro
DECLARE_EVENT_TABLE()
private:
void UpdateMMedInfo();
void UpdateInfoText();
MMBoardFile *m_opened_file;
wxSlider *m_positionSlider;
wxBitmapButton *m_playButton, *m_pauseButton, *m_stopButton, *m_ejectButton;
wxStaticText *m_fileType, *m_infoText;
wxWindow *m_video_window;
wxPanel *m_panel;
wxSizer *m_sizer;
wxTimer *m_refreshTimer;
};
// ----------------------------------------------------------------------------
// constants
// ----------------------------------------------------------------------------
// IDs for the controls and the menu commands
enum
{
// menu items
MMBoard_Quit = 1,
MMBoard_Open,
MMBoard_About,
MMBoard_PositionSlider,
MMBoard_PlayButton,
MMBoard_PauseButton,
MMBoard_ResumeButton,
MMBoard_StopButton,
MMBoard_EjectButton,
MMBoard_RefreshInfo
};
// ----------------------------------------------------------------------------
// event tables and other macros for wxWidgets
// ----------------------------------------------------------------------------
BEGIN_EVENT_TABLE(MMBoardFrame, wxFrame)
EVT_MENU(MMBoard_Quit, MMBoardFrame::OnQuit)
EVT_MENU(MMBoard_About, MMBoardFrame::OnAbout)
EVT_MENU(MMBoard_Open, MMBoardFrame::OnOpen)
EVT_BUTTON(MMBoard_PlayButton, MMBoardFrame::OnPlay)
EVT_BUTTON(MMBoard_StopButton, MMBoardFrame::OnStop)
EVT_BUTTON(MMBoard_PauseButton, MMBoardFrame::OnPause)
EVT_BUTTON(MMBoard_EjectButton, MMBoardFrame::OnEject)
EVT_SLIDER(MMBoard_PositionSlider, MMBoardFrame::OnSetPosition)
EVT_CUSTOM(wxEVT_TIMER, MMBoard_RefreshInfo, MMBoardFrame::OnRefreshInfo)
END_EVENT_TABLE()
// ---------------------------------------------------------------------------
// Main board application launcher
// ---------------------------------------------------------------------------
IMPLEMENT_APP(MMBoardApp)
// ============================================================================
// implementation
// ============================================================================
// ----------------------------------------------------------------------------
// the application class
// ----------------------------------------------------------------------------
bool MMBoardApp::OnInit()
{
// create the main application window
MMBoardFrame *frame = new MMBoardFrame(_T("Multimedia Board"),
wxPoint(50, 50), wxSize(450, 340));
// and show it (the frames, unlike simple controls, are not shown when
// created initially)
frame->Show();
m_caps = TestMultimediaCaps();
if (!m_caps) {
wxMessageBox(_T("Your system has no multimedia capabilities. We are exiting now."), _T("Major error !"), wxOK | wxICON_ERROR, NULL);
return false;
}
wxString msg;
msg.Printf(_T("Detected : %s%s%s"), (m_caps & MM_SOUND_OSS) ? _T("OSS ") : _T(""),
(m_caps & MM_SOUND_ESD) ? _T("ESD ") : _T(""),
(m_caps & MM_SOUND_WIN) ? _T("WIN") : _T(""));
wxMessageBox(msg, _T("Good !"), wxOK | wxICON_INFORMATION, NULL);
// success: wxApp::OnRun() will be called which will enter the main message
// loop and the application will run. If we returned false here, the
// application would exit immediately.
return true;
}
wxUint8 MMBoardApp::TestMultimediaCaps()
{
wxSoundStream *dev;
wxUint8 caps;
caps = 0;
#ifdef __WIN32__
// We test the Windows sound support.
dev = new wxSoundStreamWin();
if (dev->GetError() == wxSOUND_NOERROR)
caps |= MM_SOUND_WIN;
delete dev;
#elif defined __UNIX__
// We now test the ESD support
dev = new wxSoundStreamESD();
if (dev->GetError() == wxSOUND_NOERROR)
caps |= MM_SOUND_ESD;
delete dev;
// We test the OSS (Open Sound System) support.
// WARNING: There is a conflict between ESD and ALSA. We may be interrested
// in disabling the auto detection of OSS is ESD has been detected.
#if 1
if (!(caps & MM_SOUND_ESD)) {
#endif
dev = new wxSoundStreamOSS();
if (dev->GetError() == wxSOUND_NOERROR)
caps |= MM_SOUND_OSS;
delete dev;
#if 1
}
#endif
#endif
return caps;
}
// ----------------------------------------------------------------------------
// main frame
// ----------------------------------------------------------------------------
// frame constructor
MMBoardFrame::MMBoardFrame(const wxString& title, const wxPoint& pos, const wxSize& size)
: wxFrame((wxFrame *)NULL, wxID_ANY, title, pos, size)
{
#ifdef __WXMAC__
// we need this in order to allow the about menu relocation, since ABOUT is
// not the default id of the about menu
wxApp::s_macAboutMenuItemId = MMBoard_About;
#endif
// set the frame icon
SetIcon(wxICON(mondrian));
// create a menu bar
wxMenu *menuFile = new wxMenu(wxEmptyString, wxMENU_TEAROFF);
// the "About" item should be in the help menu
wxMenu *helpMenu = new wxMenu;
helpMenu->Append(MMBoard_About, wxT("&About...\tCtrl-A"), wxT("Show about dialog"));
menuFile->Append(MMBoard_Open, wxT("&Open\tAlt-O"), wxT("Open file"));
menuFile->AppendSeparator();
menuFile->Append(MMBoard_Quit, wxT("E&xit\tAlt-X"), wxT("Quit this program"));
// now append the freshly created menu to the menu bar...
wxMenuBar *menuBar = new wxMenuBar();
menuBar->Append(menuFile, wxT("&File"));
menuBar->Append(helpMenu, wxT("&Help"));
// ... and attach this menu bar to the frame
SetMenuBar(menuBar);
#if wxUSE_STATUSBAR
// create a status bar just for fun (by default with 1 pane only)
CreateStatusBar(3);
SetStatusText(wxT("Welcome to wxWidgets!"));
#endif // wxUSE_STATUSBAR
// Misc variables
m_opened_file = NULL;
m_panel = new wxPanel(this, wxID_ANY);
// Initialize main slider
m_positionSlider = new wxSlider( m_panel, MMBoard_PositionSlider, 0, 0, 60,
wxDefaultPosition, wxSize(300, wxDefaultCoord),
wxSL_HORIZONTAL | wxSL_AUTOTICKS);
m_positionSlider->SetPageSize(60); // 60 secs
m_positionSlider->Disable();
// Initialize info panel
wxPanel *infoPanel = new wxPanel( m_panel, wxID_ANY);
infoPanel->SetBackgroundColour(*wxBLACK);
infoPanel->SetForegroundColour(*wxWHITE);
wxBoxSizer *infoSizer = new wxBoxSizer(wxVERTICAL);
m_fileType = new wxStaticText(infoPanel, wxID_ANY, wxEmptyString);
#if wxUSE_STATLINE
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?