?? mediaplayerdlg.cpp
字號:
// MediaPlayerDlg.cpp : implementation file
//
#include "stdafx.h"
#include "MediaPlayer.h"
#include "MediaPlayerDlg.h"
#include "../common/common.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
player* myplayer = NULL;
/////////////////////////////////////////////////////////////////////////////
// CMediaPlayerDlg dialog
CMediaPlayerDlg::CMediaPlayerDlg(CWnd* pParent /*=NULL*/)
: CDialog(CMediaPlayerDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CMediaPlayerDlg)
m_bFullScreen = FALSE;
m_h = 120;
m_w = 160;
m_x = 0;
m_y = 0;
m_mode = 1;
m_pDlg = NULL;
m_delay = 5000;
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
m_view = 0;
}
void CMediaPlayerDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CMediaPlayerDlg)
DDX_Control(pDX, IDC_LIST, m_list);
DDX_Check(pDX, IDC_CHECK, m_bFullScreen);
DDX_Text(pDX, IDC_EDIT_H, m_h);
DDX_Text(pDX, IDC_EDIT_W, m_w);
DDX_Text(pDX, IDC_EDIT_X, m_x);
DDX_Text(pDX, IDC_EDIT_Y, m_y);
DDX_Radio(pDX, IDC_RADIO_PIC, m_mode);
DDX_Text(pDX, IDC_EDIT_DELAY, m_delay);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CMediaPlayerDlg, CDialog)
//{{AFX_MSG_MAP(CMediaPlayerDlg)
ON_BN_CLICKED(IDC_BUTTON_MEDIA, OnButtonMedia)
ON_BN_CLICKED(IDC_BUTTON_MEDIAFILE, OnButtonMediafile)
ON_BN_CLICKED(IDC_BUTTON_PICFILE, OnButtonPicfile)
ON_BN_CLICKED(IDC_BUTTON_PIC, OnButtonPic)
ON_BN_CLICKED(IDC_RADIO_MED, OnRadioMed)
ON_BN_CLICKED(IDC_RADIO_PIC, OnRadioPic)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CMediaPlayerDlg message handlers
BOOL CMediaPlayerDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
CenterWindow(GetDesktopWindow()); // center to the hpc screen
// TODO: Add extra initialization here
return TRUE; // return TRUE unless you set the focus to a control
}
void CMediaPlayerDlg::OnButtonMedia()
{
if (m_view)
{
if (::AfxMessageBox(L"Are you want to open a new view?", MB_YESNO | MB_ICONEXCLAMATION) != IDYES)
{
Context_Wnd(NULL); // Close MediaForm.
CloseForm(); // Close DlgForm.
delete Context();
delete m_pDlg;
}
}
UpdateData(true);
if (m_folderName.IsEmpty())
{
::AfxMessageBox( L"Plase select a folder" );
return;
}
InitPlayer(); // Init player module.
MakePlayList(); // Make list.
StartPlayer(80); // Play Media or Image.
CreateForm();
m_view++;
}
void PlayNext(LPVOID lpParam)
{
CMediaPlayerDlg* pDlg = (CMediaPlayerDlg*)lpParam;
while(pDlg->m_bThreadStatus)
{
::Sleep(pDlg->m_delay);
myplayer->Set(myplayer,PLAYER_NEXT,NULL,0); // Play next media.
}
}
void CMediaPlayerDlg::OnButtonPic()
{
// TODO: Add your control notification handler code here
m_bThreadStatus = true; // Used a thread to show Image.
OnButtonMedia();
// Create Thread.
m_hThread = ::CreateThread( NULL,
0,
(LPTHREAD_START_ROUTINE)PlayNext,
(LPVOID)this,
0,
&m_dwExitCode );
}
void CMediaPlayerDlg::OnButtonMediafile()
{
// TODO: Add your control notification handler code here
if (InsertList( L"*.*" )) // Open a floder selection dialog.
GetDlgItem(IDC_BUTTON_MEDIA)->EnableWindow(true); // and insert list.
}
void CMediaPlayerDlg::OnButtonPicfile()
{
// TODO: Add your control notification handler code here
if (InsertList( L"*.*" ))
GetDlgItem(IDC_BUTTON_PIC)->EnableWindow(true);
}
void CMediaPlayerDlg::InitPlayer()
{
Context_Init((tchar_t*)T("TCPMP"),(tchar_t*)T("0.72SRC"),3,NULL,NULL);
// Create context
context* p = Context();
// Init player module
myplayer = NULL;
if(p) myplayer = (player*)(p->Player);
// empty saved playlist
int Int = 0;
myplayer->Set(myplayer, PLAYER_LIST_COUNT, &Int, sizeof(Int));
// turn off repeat
bool_t Bool = 0;
myplayer->Set(myplayer, PLAYER_REPEAT, &Bool, sizeof(Bool));
Context_Wnd((void*)1); //fake window handle
// Set Screen.
if (true)
{
rect Rect;
Rect.x = m_x;
Rect.y = m_y;
Rect.Width = m_w;
Rect.Height = m_h;
myplayer->Set(myplayer, PLAYER_SKIN_VIEWPORT, &Rect, sizeof(Rect));
}
else
{
Bool = 1;
myplayer->Set(myplayer, PLAYER_FULLSCREEN, &Bool, sizeof(Bool));
}
}
bool CMediaPlayerDlg::StartPlayer(int vol)
{
// Set the voice.
myplayer->Set(myplayer, PLAYER_VOLUME, &vol, sizeof(int));
// Play Media.
int n = 1;
if ( myplayer->Set(myplayer,PLAYER_PLAY,&n,sizeof(int)) == -3)
return false;
return true;
}
void CMediaPlayerDlg::CreateForm()
{
m_pDlg = new CMediaForm();
m_pDlg->Create(IDD_DIALOG_FORM, m_pDlg);
m_pDlg->SetWindowPos(NULL, m_x, m_y, m_w, m_h, SWP_SHOWWINDOW);
}
void CMediaPlayerDlg::CloseForm()
{
m_pDlg->DestroyWindow();
}
TCHAR* CMediaPlayerDlg::ShowFolderDlg()
{ // Make a
BROWSEINFO browseInfo;
TCHAR* pszDisplayName = new TCHAR[512];
ZeroMemory(&browseInfo, sizeof(browseInfo));
browseInfo.hwndOwner = GetSafeHwnd();
browseInfo.pszDisplayName = pszDisplayName; // Pointer to a buffer that receives the display name of the folder
browseInfo.lpszTitle = L"Please select a folder:"; // displayed above the tree view control in the dialog box.
browseInfo.ulFlags = BIF_RETURNONLYFSDIRS;
LPITEMIDLIST pidl = SHBrowseForFolder(&browseInfo);
if (!pidl)
return NULL;
SHGetPathFromIDList(pidl, pszDisplayName);
LPMALLOC pMalloc = NULL;
if (SHGetMalloc(&pMalloc) == NOERROR)
pMalloc->Free((void*)pidl);
return pszDisplayName;
}
bool CMediaPlayerDlg::InsertList(CString suffix)
{
// Displays a dialog box that allows a user to select a folder.
// It return NULL when user chose the Cancel button in the dialog box.
m_list.ResetContent();
m_folderName = ShowFolderDlg(); // Get folder path.
if(m_folderName.IsEmpty())
return false;
if (m_folderName.GetLength() > 1)
m_folderName += (L"\\");
WIN32_FIND_DATA findFileData;
HANDLE hFile;
if ( (hFile = ::FindFirstFile(m_folderName + suffix, &findFileData)) == INVALID_HANDLE_VALUE )
{
::AfxMessageBox( L"Can't find files!\n" );
return false;
}
else
{
int index = 0;
do
{ // Insert file's name to the list.
m_list.InsertString(index, findFileData.cFileName);
} while (::FindNextFile(hFile, &findFileData));
}
::FindClose(hFile);
return true;
}
void CMediaPlayerDlg::MakePlayList()
{
CString m_path = m_folderName;
int nIndex = m_list.GetCount();
CString str = L"";
for (int index = 0; index < nIndex; index++)
{
m_list.GetText(index, str);
PlayerAdd(myplayer, index, m_path + str, NULL);
}
}
void CMediaPlayerDlg::OnRadioMed()
{
// TODO: Add your control notification handler code here
m_list.ResetContent();
GetDlgItem(IDC_BUTTON_MEDIAFILE)->EnableWindow(true);
m_bThreadStatus = false;
GetDlgItem(IDC_BUTTON_PIC)->EnableWindow(false);
GetDlgItem(IDC_EDIT_DELAY)->EnableWindow(false);
GetDlgItem(IDC_BUTTON_PICFILE)->EnableWindow(false);
}
void CMediaPlayerDlg::OnRadioPic()
{
// TODO: Add your control notification handler code here
m_list.ResetContent();
GetDlgItem(IDC_EDIT_DELAY)->EnableWindow(true);
GetDlgItem(IDC_BUTTON_PICFILE)->EnableWindow(true);
GetDlgItem(IDC_BUTTON_MEDIA)->EnableWindow(false);
GetDlgItem(IDC_BUTTON_MEDIAFILE)->EnableWindow(false);
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -