📄 clientdlg.cpp
字号:
// ClientDlg.cpp : implementation file
//
#include "stdafx.h"
#include "Client.h"
#include "ClientDlg.h"
#include "CallDlg.h"
#include "GlobalDefs.h"
#include "CMediaInfo.h"
#include "UFilterUtils.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About
class CAboutDlg : public CDialog
{
public:
CAboutDlg();
// Dialog Data
//{{AFX_DATA(CAboutDlg)
enum { IDD = IDD_ABOUTBOX };
//}}AFX_DATA
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CAboutDlg)
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL
// Implementation
protected:
//{{AFX_MSG(CAboutDlg)
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
//{{AFX_DATA_INIT(CAboutDlg)
//}}AFX_DATA_INIT
}
void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CAboutDlg)
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
//{{AFX_MSG_MAP(CAboutDlg)
// No message handlers
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CClientDlg dialog
CClientDlg::CClientDlg(CWnd* pParent /*=NULL*/)
: CDialog(CClientDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CClientDlg)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
mGraph=NULL;
mMediaControl=NULL;
mVideoReceiver=NULL;
mAudioReceiver=NULL;
mVideoDecom=NULL;
mAudioDecom=NULL;
mVideoRenderer=NULL;
mAudioRenderer=NULL;
mAudioIsOK=FALSE;
mVideoIsOK=FALSE;
mState=STOP;
}
void CClientDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CClientDlg)
DDX_Control(pDX, IDC_PROGRESS, mSliderTimer);
DDX_Control(pDX, IDC_BTNDISCONNECT, mBtnDisconnect);
DDX_Control(pDX, IDC_BTN_CONNECT, mBtnConnect);
DDX_Control(pDX, IDC_VIDEOWINDOW, mVideoWnd);
DDX_Control(pDX, IDC_LIST, mProgramListCtrl);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CClientDlg, CDialog)
//{{AFX_MSG_MAP(CClientDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_BTN_CONNECT, OnBtnConnect)
ON_BN_CLICKED(IDC_BTN_REFRESH, OnBtnRefresh)
ON_BN_CLICKED(IDC_BTN_PLAY, OnBtnPlay)
ON_WM_DESTROY()
ON_BN_CLICKED(IDC_BTN_STOP, OnBtnStop)
ON_BN_CLICKED(IDC_BTNDISCONNECT, OnBtndisconnect)
ON_WM_HSCROLL()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CClientDlg message handlers
BOOL CClientDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// Add "About..." menu item to system menu.
// IDM_ABOUTBOX must be in the system command range.
ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
ASSERT(IDM_ABOUTBOX < 0xF000);
CMenu* pSysMenu = GetSystemMenu(FALSE);
if (pSysMenu != NULL)
{
CString strAboutMenu;
strAboutMenu.LoadString(IDS_ABOUTBOX);
if (!strAboutMenu.IsEmpty())
{
pSysMenu->AppendMenu(MF_SEPARATOR);
pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
}
}
// 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
mProgramListCtrl.SetExtendedStyle(LVS_EX_FULLROWSELECT | LVS_EX_GRIDLINES);
mProgramListCtrl.InsertColumn(0, "File", LVCFMT_CENTER, 120);
mProgramListCtrl.InsertColumn(1, "Type", LVCFMT_CENTER, 80);
mProgramListCtrl.InsertColumn(2, "Size", LVCFMT_CENTER, 80);
mProgramListCtrl.InsertColumn(3, "PID", LVCFMT_CENTER, 60);
// TODO: Add extra initialization here
mControll.AddMsgReceiver(this);
mBtnDisconnect.EnableWindow(FALSE);
mSliderTimer.SetRange(0,1000);
mSliderTimer.SetPos(0);
return TRUE; // return TRUE unless you set the focus to a control
}
void CClientDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
if ((nID & 0xFFF0) == IDM_ABOUTBOX)
{
CAboutDlg dlgAbout;
dlgAbout.DoModal();
}
else
{
CDialog::OnSysCommand(nID, lParam);
}
}
// If you add a minimize button to your dialog, you will need the code below
// to draw the icon. For MFC applications using the document/view model,
// this is automatically done for you by the framework.
void CClientDlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // device context for painting
SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
// Center icon in client rectangle
int cxIcon = GetSystemMetrics(SM_CXICON);
int cyIcon = GetSystemMetrics(SM_CYICON);
CRect rect;
GetClientRect(&rect);
int x = (rect.Width() - cxIcon + 1) / 2;
int y = (rect.Height() - cyIcon + 1) / 2;
// Draw the icon
dc.DrawIcon(x, y, m_hIcon);
}
else
{
CDialog::OnPaint();
}
}
// The system calls this to obtain the cursor to display while the user drags
// the minimized window.
HCURSOR CClientDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CClientDlg::OnBtnConnect()
{
if(!mControll.IsConnected())
{
CCallDlg callDlg;
if (callDlg.DoModal() == IDOK)
{
mServerIP=callDlg.GetServerIP();
if(mControll.ConnectTo(mServerIP,SERVER_CONTROLL_PORT))
{
mControll.StartReceiving();
MessageBox("连接成功,请点击“刷新”按钮!");
mBtnDisconnect.EnableWindow(TRUE);
mBtnConnect.EnableWindow(FALSE);
}
else
{
MessageBox("连接失败,请检查服务端是否运行!");
}
}
}
else
{
MessageBox("已经连接");
}
}
void CClientDlg::OnBtnRefresh()
{
mProgramListCtrl.DeleteAllItems();
SendSimpleCommand(Cmd_RequestProgramList);
}
bool CClientDlg::ReceiveMessage(MessageT inMessage,
void * ioParam,
void * ioParam2)
{
if (inMessage == msg_CommandReceived)
{
ProcessCommand(ioParam);
return true;
}
else if(inMessage == msg_MediaTypeReceived)
{
BOOL * isVideo=(BOOL*) ioParam;
if(*isVideo)
{
CompleteVideoReceivingGraph();
}
else
{
CompleteAudioReceivingGraph();
}
}
return CMsgReceiver::ReceiveMessage(inMessage, ioParam, ioParam2);
}
BOOL CClientDlg::SendSimpleCommand(long inCommand)
{
if(mControll.IsConnected())
{
char buf[MAX_COMMAND_SIZE];
long len = sizeof(Net_Command);
// Specify command id first
long * pCmd = (long *) buf;
*pCmd = inCommand;
*pCmd = htonl(*pCmd);
return mControll.Send(buf, len);
}
return FALSE;
}
void CClientDlg::ProcessCommand(void * inCommand)
{
// First, get the command id
long * pCmd = (long *) inCommand;
switch (ntohl(*pCmd))
{
case Cmd_ProgramList:
{
pCmd++;
Program_List * pData = (Program_List *) pCmd;
pData->my_ntoh();
CMediaInfo info;
info.CopyFrom(pData);
AddProgramItem(info);
}
break;
case Cmd_SetProgress:
{
pCmd++;
Media_Progress * pData = (Media_Progress *) pCmd;
pData->my_ntoh();
mSliderTimer.SetPos(pData->program_Progress);
}
break;
case Cmd_Error:
{
Deactivate();
}
default:
break;
}
}
void CClientDlg::AddProgramItem(CMediaInfo & inMedia)
{
int count = mProgramListCtrl.GetItemCount();
// We needn't display the full path of the file
char * p = strrchr(inMedia.mFilePath, '\\');
mProgramListCtrl.InsertItem(count, p+1);
// Determine file type
CString str;
switch (inMedia.mFileType)
{
case FT_MPEG1:
str = "MPEG1";
break;
case FT_MPEG2:
str = "MPEG2";
break;
case FT_AVI:
str = "AVI";
break;
case FT_MP3:
str = "MP3";
case FT_OGG:
str = "OGG";
break;
case FT_REAL:
str = "REAL";
break;
default:
str = "Unknown";
break;
}
mProgramListCtrl.SetItemText(count, 1, str);
str.Format("%.3fM", inMedia.mFileSize / 1024. / 1024.);
mProgramListCtrl.SetItemText(count, 2, str);
str.Format("%d", inMedia.mProgramId);
mProgramListCtrl.SetItemText(count, 3, str);
// Save to the list too
mPrgrmList.AddTail(inMedia);
}
void CClientDlg::OnBtnPlay()
{
if(mControll.IsConnected())
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -