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

📄 cppdlg.cpp

📁 264的播放器
💻 CPP
字号:
// CPPDlg.cpp : implementation file
//
#include "stdafx.h"
#include "CPP.h"
#include "CPPDlg.h"

//#include "global.h"
#include "ldecod.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

extern char  *saveFile;
extern bool winFlag;
extern bool  picFormat;
/////////////////////////////////////////////////////////////////////////////
// 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()

/////////////////////////////////////////////////////////////////////////////
// CCPPDlg dialog

CCPPDlg::CCPPDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CCPPDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CCPPDlg)
	m_DecFile = _T("");
	m_SaveDec = FALSE;
	m_CIF = 0;
	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void CCPPDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CCPPDlg)
	DDX_Control(pDX, IDC_RATE, m_Rate);
	DDX_Control(pDX, IDC_STATE, m_State);
	DDX_Text(pDX, IDC_DECFILE, m_DecFile);
	DDX_Check(pDX, IDC_SAVE_DEC, m_SaveDec);
	DDX_Radio(pDX, IDC_CIF, m_CIF);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CCPPDlg, CDialog)
	//{{AFX_MSG_MAP(CCPPDlg)
	ON_WM_SYSCOMMAND()
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_BN_CLICKED(IDC_OPEN, OnOpen)
	ON_BN_CLICKED(IDC_DECODE, OnDecode)
	ON_BN_CLICKED(IDC_PARSET, OnParset)
	ON_BN_CLICKED(IDC_SAVE_DEC, OnSaveDec)
	ON_WM_TIMER()
	ON_BN_CLICKED(IDC_CIF, OnCif)
	ON_BN_CLICKED(IDC_QCIF, OnQcif)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CCPPDlg message handlers

BOOL CCPPDlg::OnInitDialog()
{
	CDialog::OnInitDialog();

	Disable(IDC_SAVE_DEC);
	Disable(IDC_DECFILE);
	Disable(IDC_DECODE);
	Disable(IDC_PARSET);
	click = fRate = 0;
	winFlag = picFormat = FALSE;
	saveFile = "";
	

	// 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
	
	// TODO: Add extra initialization here
	
	return TRUE;  // return TRUE  unless you set the focus to a control
}

void CCPPDlg::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 CCPPDlg::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 CCPPDlg::OnQueryDragIcon()
{
	return (HCURSOR) m_hIcon;
}

void CCPPDlg::OnOpen() 
{
	// TODO: Add your control notification handler code here
	CString extName;
	static char szFilter[]="H264文件[*.264]|*.264||";
	CFileDialog fileDlg(TRUE,"压缩码流","压缩码流",OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT,szFilter);
	if(fileDlg.DoModal()==IDOK)
	{
		UpdateData(TRUE);
		m_SaveDec = FALSE;
		m_DecFile="";
		m_hFile=fileDlg.GetPathName();
		m_fName=fileDlg.GetFileTitle();
		extName=fileDlg.GetFileExt();
		while(extName!="264")
		{
			AfxMessageBox("不能解码该文件类型!");
				return;
		}
		filename=m_hFile.GetBuffer(m_hFile.GetLength());
		UpdateData(FALSE);	
	}
	Enable(IDC_SAVE_DEC);
	Enable(IDC_DECODE);
	Disable(IDC_PARSET);
	SetTimer(1,1000,NULL);
}

void CCPPDlg::OnDecode() 
{
	// TODO: Add your control notification handler code here
	char* argv;//[2];
	argv = filename;
//	argv[2] = saveFile;
	success=CreateThread(NULL,0,(LPTHREAD_START_ROUTINE)h264dec,(LPVOID) argv,0,NULL );//h264dec(filename,saveName);
	if(!success)
	{
		MessageBox(_T("错误提示:文件格式被破坏!"),_T("Message"),MB_OK|MB_ICONSTOP);
	}	
	Enable(IDC_PARSET);
}

//此处的代码为临时代码,测试播放文件用的!
void CCPPDlg::OnParset() 
{
	// TODO: Add your control notification handler code here
	//CDialog::OnCancel();
	KillTimer(1);
	TerminateThread(success,0);
	Disable(IDC_SAVE_DEC);
	Disable(IDC_DECFILE);
	Disable(IDC_DECODE);
}

void CCPPDlg::OnSaveDec() 
{
	// TODO: Add your control notification handler code here
	click++;
	if((click%2)!=0)
	{
		UpdateData(TRUE);
		if(m_fName=="")
			m_DecFile=saveFile="";
		else
		{
			m_DecFile=m_fName;
			m_DecFile=m_fName+".yuv";
			saveFile = m_DecFile.GetBuffer(m_DecFile.GetLength());
		}
		UpdateData(FALSE);
	}
	else
	{
		UpdateData(TRUE);
		m_DecFile=saveFile="";
		UpdateData(FALSE);
	}
}

void CCPPDlg::Enable(int nID)
{
	CWnd *pObject1;
	pObject1 = GetDlgItem(nID);
	pObject1->EnableWindow(TRUE);
}

void CCPPDlg::Disable(int nID)
{
	CWnd *pObject1;
	pObject1 = GetDlgItem(nID);
	pObject1->EnableWindow(FALSE);
}

void CCPPDlg::OnTimer(UINT nIDEvent) 
{
	// TODO: Add your message handler code here and/or call default
	char str[50];
	UpdateData(TRUE);
	if(winFlag)
		fRate=getState();
	fRate = (fRate>200)? 0:fRate;
	sprintf(str,"%s",m_hFile);
   	m_State.SetWindowText(str);
	sprintf(str,"每秒 %d 帧",fRate);	
   	m_Rate.SetWindowText(str);
	
	CDialog::OnTimer(nIDEvent);	
	Invalidate();
}

void CCPPDlg::OnQcif() 
{
	// TODO: Add your control notification handler code here
	picFormat=TRUE;//QCIF	
}

void CCPPDlg::OnCif() 
{
	// TODO: Add your control notification handler code here
	picFormat=FALSE;//QCIF
}

⌨️ 快捷键说明

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