⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ambulantplayerview.cpp

📁 彩信浏览器
💻 CPP
字号:
// AmbulantPlayerView.cpp : implementation of the CAmbulantPlayerView class//#include "stdafx.h"#include "AmbulantPlayer.h"#include "AmbulantPlayerDoc.h"#include "AmbulantPlayerView.h"#include "SelectDlg.h"// DG Player#include "ambulant/gui/dg/dg_player.h"#include "ambulant/gui/dg/dg_wmuser.h"#include "ambulant/common/preferences.h"#include "ambulant/lib/logger.h"#include "ambulant/lib/textptr.h"#include "ambulant/lib/win32/win32_fstream.h"#include "ambulant/smil2/test_attrs.h"#include "ambulant/net/url.h"#pragma comment (lib,"mp3lib.lib")#ifdef _DEBUG#define new DEBUG_NEW#undef THIS_FILEstatic char THIS_FILE[] = __FILE__;#endifusing namespace ambulant;typedef gui::dg::dg_player gui_player;typedef gui::dg::dg_player_callbacks gui_callbacks;// The handle of the single window instancestatic HWND s_hwnd;// A class with callbacks, also instantiated onceclass my_player_callbacks : public gui_callbacks {  public:	HWND new_os_window();	void destroy_os_window(HWND hwnd);	HWND get_main_window();};my_player_callbacks s_player_callbacks;HWND my_player_callbacks::new_os_window() {	// Return the handle of the single instance for now	// This means paint bits of the new window	// to the single instance	return s_hwnd;}void my_player_callbacks::destroy_os_window(HWND hwnd) {	// none for now; keep the single instance}HWND my_player_callbacks::get_main_window() {	return AfxGetMainWnd()->GetSafeHwnd();}static gui_player* create_player_instance(const net::url& u) {	return new gui_player(s_player_callbacks, u);}void lib::win32::show_message(int level, const char *message) {	unsigned int type = MB_OK;	if (level == lib::logger::LEVEL_WARN) type |= MB_ICONWARNING;	if (level == lib::logger::LEVEL_ERROR) type |= MB_ICONERROR;	if (level == lib::logger::LEVEL_FATAL) type |= MB_ICONERROR;	MessageBox(NULL, textptr(message), text_str("AmbulantPlayer"), type);}static  gui_player *player = 0;static needs_done_redraw = false;/////////////////////////////////////////////////////////////////////////////// CAmbulantPlayerViewIMPLEMENT_DYNCREATE(CAmbulantPlayerView, CView)BEGIN_MESSAGE_MAP(CAmbulantPlayerView, CView)	//{{AFX_MSG_MAP(CAmbulantPlayerView)	ON_COMMAND(ID_PLAY, OnPlay)	ON_UPDATE_COMMAND_UI(ID_PLAY, OnUpdatePlay)	ON_COMMAND(ID_PAUSE, OnPause)	ON_UPDATE_COMMAND_UI(ID_PAUSE, OnUpdatePause)	ON_COMMAND(ID_STOP, OnStop)	ON_UPDATE_COMMAND_UI(ID_STOP, OnUpdateStop)	ON_WM_DESTROY()	ON_WM_CHAR()	ON_WM_LBUTTONDOWN()	ON_WM_CREATE()	ON_WM_TIMER()	ON_COMMAND(ID_HELP_WELCOME, OnHelpWelcome)	ON_COMMAND(ID_FILE_SELECT, OnFileSelect)	ON_COMMAND(ID_FILE_LOADSETTINGS, OnFileLoadSettings)	ON_MESSAGE(WM_REPLACE_DOC, OnReplaceDoc)	//}}AFX_MSG_MAPEND_MESSAGE_MAP()/////////////////////////////////////////////////////////////////////////////// CAmbulantPlayerView construction/destructionCAmbulantPlayerView::CAmbulantPlayerView(){	m_timer_id = 0;	m_cursor_id = 0;	m_autoplay = true;}CAmbulantPlayerView::~CAmbulantPlayerView(){}BOOL CAmbulantPlayerView::PreCreateWindow(CREATESTRUCT& cs){	// TODO: Modify the Window class or styles here by modifying	//  the CREATESTRUCT cs	return CView::PreCreateWindow(cs);}int CAmbulantPlayerView::OnCreate(LPCREATESTRUCT lpCreateStruct) {	if (CView::OnCreate(lpCreateStruct) == -1)		return -1;		m_timer_id = SetTimer(1, 1000, 0);		// Set static handle	s_hwnd = GetSafeHwnd();		lib::win32::fstream *fs = new lib::win32::fstream();	if(fs->open_for_writing(TEXT("\\Windows\\Ambulant\\amlog.txt")))		lib::logger::get_logger()->set_ostream(fs);	return 0;}/////////////////////////////////////////////////////////////////////////////// CAmbulantPlayerView drawingvoid CAmbulantPlayerView::OnDraw(CDC* pDC){	//CAmbulantPlayerDoc* pDoc = GetDocument();	//ASSERT_VALID(pDoc);	if(player)		player->redraw(m_hWnd, pDC->m_hDC);}/////////////////////////////////////////////////////////////////////////////// CAmbulantPlayerView diagnostics#ifdef _DEBUGvoid CAmbulantPlayerView::AssertValid() const{	CView::AssertValid();}void CAmbulantPlayerView::Dump(CDumpContext& dc) const{	CView::Dump(dc);}CAmbulantPlayerDoc* CAmbulantPlayerView::GetDocument() // non-debug version is inline{	ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CAmbulantPlayerDoc)));	return (CAmbulantPlayerDoc*)m_pDocument;}#endif //_DEBUG/////////////////////////////////////////////////////////////////////////////// CAmbulantPlayerView message handlersvoid CAmbulantPlayerView::SetMMDocument(LPCTSTR lpszPathName) {	gui_player *dummy = player;	player = 0;	if(dummy) {		dummy->stop();		delete dummy;	}	lib::textptr tp(lpszPathName);	net::url u = net::url::from_filename(tp.c_str());	dummy = create_player_instance(u);	m_curDocFilename = lpszPathName;	player = dummy;	if(m_autoplay)		PostMessage(WM_COMMAND, ID_PLAY);}void CAmbulantPlayerView::OnPlay() {	if(player) {		player->play();		needs_done_redraw = true;	}	}void CAmbulantPlayerView::OnUpdatePlay(CCmdUI* pCmdUI) {	bool enable = player && player->is_play_enabled();	pCmdUI->Enable(enable?TRUE:FALSE);	}void CAmbulantPlayerView::OnPause() {	if(player) player->pause();	}void CAmbulantPlayerView::OnUpdatePause(CCmdUI* pCmdUI) {	bool enable = player && player->is_pause_enabled();	pCmdUI->Enable(enable?TRUE:FALSE);	if(enable) pCmdUI->SetCheck(player->is_pause_active()?1:0);	}void CAmbulantPlayerView::OnStop() {	if(player) {		net::url u = player->get_url();		gui_player *dummy = player;		player = 0;		if(dummy) {			dummy->stop();			delete dummy;		}		dummy = create_player_instance(u);		player = dummy;		PostMessage(WM_INITMENUPOPUP,0, 0); 		InvalidateRect(NULL);		needs_done_redraw = false;	}}void CAmbulantPlayerView::OnUpdateStop(CCmdUI* pCmdUI) {	bool enable = player && (player->is_stop_enabled());	pCmdUI->Enable(enable?TRUE:FALSE);	}void CAmbulantPlayerView::OnDestroy() {	if(player) {		player->stop();		delete player;		player = 0;	}	lib::logger::get_logger()->set_ostream(0);	if(m_timer_id) KillTimer(m_timer_id);	CView::OnDestroy();	}void CAmbulantPlayerView::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags) {	if(player) player->on_char(nChar);	CView::OnChar(nChar, nRepCnt, nFlags);}void CAmbulantPlayerView::OnLButtonDown(UINT nFlags, CPoint point) {	if(player) player->on_click(point.x, point.y, GetSafeHwnd());	CView::OnLButtonDown(nFlags, point);}void CAmbulantPlayerView::OnTimer(UINT nIDEvent) {	if(player && needs_done_redraw && player->is_stop_active()) {		OnStop();	}		CView::OnTimer(nIDEvent);}void CAmbulantPlayerView::OnHelpWelcome() {	CString welcomeFilename("\\Windows\\Ambulant\\Welcome.smil");	SetMMDocument(welcomeFilename);	if(!m_autoplay)		PostMessage(WM_COMMAND, ID_PLAY);}void CAmbulantPlayerView::OnFileSelect() {	CSelectDlg dlg(this);	if(dlg.DoModal() == IDOK) {		CString fileName = dlg.GetPathName();		if(!fileName.IsEmpty()) {			SetMMDocument(fileName);			if(!m_autoplay)				PostMessage(WM_COMMAND, ID_PLAY);		}	}}void CAmbulantPlayerView::OnFileLoadSettings() {	BOOL bOpenFileDialog = TRUE;	CString strDefExt = TEXT("*.xml");	DWORD flags = OFN_HIDEREADONLY | OFN_FILEMUSTEXIST;	CString strFilter = TEXT("Settings Files (*.xml)|*.xml|All Files (*.*)|*.*||");	CFileDialog dlg(TRUE, strDefExt, NULL, flags, strFilter, this);	dlg.m_ofn.lpstrTitle = TEXT("Select settings file");	if(dlg.DoModal() == IDOK) {		m_curFilter = dlg.GetPathName();		const char *fn = lib::textptr(LPCTSTR(m_curFilter)).c_str();		load_test_attrs(fn);		if(player && !m_curDocFilename.IsEmpty()) {			SetMMDocument(m_curDocFilename);		}	}}LPARAM CAmbulantPlayerView::OnReplaceDoc(WPARAM wParam, LPARAM lParam) {	if(lParam == 0) return 0;	std::string *purlstr = (std::string *)lParam;	SetMMDocument(lib::textptr(purlstr->c_str()).c_wstr());	delete purlstr;	return 0;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -