www.pudn.com > pullOut.rar > PULLOUTDlg.cpp
// PULLOUTDlg.cpp : implementation file
//
#include "stdafx.h"
#include "PULLOUT.h"
#include "PULLOUTDlg.h"
#include "ApiFileNameStr.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()
/////////////////////////////////////////////////////////////////////////////
// CPULLOUTDlg dialog
CPULLOUTDlg::CPULLOUTDlg(CWnd* pParent /*=NULL*/)
: CDialog(CPULLOUTDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CPULLOUTDlg)
m_nPull = 0;
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CPULLOUTDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CPULLOUTDlg)
DDX_Text(pDX, IDC_EDIT_NPULL, m_nPull);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CPULLOUTDlg, CDialog)
//{{AFX_MSG_MAP(CPULLOUTDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_OPEN, OnOpen)
ON_BN_CLICKED(IDC_PULL, OnPull)
ON_BN_CLICKED(IDC_SAVEAS, OnSaveas)
ON_BN_CLICKED(IDC_CIF, OnCif)
ON_BN_CLICKED(IDC_SIF, OnSif)
ON_EN_UPDATE(IDC_EDIT_NPULL, OnUpdateEditNpull)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CPULLOUTDlg message handlers
BOOL CPULLOUTDlg::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
// TODO: Add extra initialization here
return TRUE; // return TRUE unless you set the focus to a control
}
void CPULLOUTDlg::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 CPULLOUTDlg::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 CPULLOUTDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CPULLOUTDlg::OnOpen()
{
// TODO: Add your control notification handler code here
if(m_nChoose!=1&&m_nChoose!=2)
{
MessageBox("请先选择文件类型");
return;
}
else
{
char BASED_CODE szFilter[] =
"YUV文件(*.YUV)|*.YUV|所有文件(*.*)|*.*|";
CFileDialog dlgFileOpen ( TRUE, "YUV", "",
OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT, szFilter, this );
int ret = dlgFileOpen.DoModal();
if ( ret != IDOK ) return;
m_strFilename = dlgFileOpen.GetPathName();//路径名
m_strTitle=dlgFileOpen.GetFileName(); //文件名
CListBox *pListBox=(CListBox *)GetDlgItem(IDC_OPENLIST);
pListBox->AddString(m_strTitle);//添加到列表框
m_FileFolder= GetFileFolderByPath(m_strFilename);//另存为 路径的设置
GetSelectNews(m_strFilename);//文件信息分析
CString Target=m_FileFolder+NameTargetFile(m_strTitle,"yuv");
SetDlgItemText(IDC_EDIT_ADD,Target);//映射到另存为编辑框
}
}
void CPULLOUTDlg::OnPull()
{
// TODO: Add your control notification handler code here
CString saveFileName;
GetDlgItemText(IDC_EDIT_ADD,saveFileName);//另存为的准备工作
if(""==saveFileName){MessageBox("请先选择文件!");return;}
FILE *file= fopen(m_strFilename, "rb" );
if (m_nChoose==1)
{
A=new BYTE[352*288*3/2];
fseek(file,m_nPull*(352*288*3/2),0);
fread(A,352*288*3/2,1,file);
}
if (m_nChoose==2)
{
A=new BYTE[352*240*3/2];
fseek(file,m_nPull*(352*240*3/2),0);
fread(A,352*240*3/2,1,file);
}
fclose(file);
}
void CPULLOUTDlg::OnSaveas()
{
// TODO: Add your control notification handler code here
CFileDialog mSaveDialog(FALSE,NULL,"new.yuv",OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,
"YUV Files(.yuv)|*.yuv|All Files (*.*)|*.*||");
if(mSaveDialog.DoModal()!=IDOK)return;
CString saveFileName=mSaveDialog.GetPathName();
SetDlgItemText(IDC_EDIT_ADD,saveFileName);
FILE *fp=fopen(saveFileName, "wb" );
if (m_nChoose==1)
{
fwrite(A,352*288*3/2,1,fp);
}
if (m_nChoose==2)
{
fwrite(A,352*240*3/2,1,fp);
}
fclose(fp);
delete A;
}
void CPULLOUTDlg::GetSelectNews(CString fileName)
{
char buf[200];
CString info="";
infp=fopen(fileName,"rb");
fseek(infp,0L,2); //图像信息字段的字符数
int m_ntotal=ftell(infp);
int a,b,c;
if (m_nChoose==1)
{
a=352*288;
b=352*288/4;
c=352*288/4;
NUM=m_ntotal/(a+b+c);
sprintf(buf,"本视频包括 %d 帧",NUM);
info+=buf; //图像类型
info+=_T(0xd);info+=_T(0xa);
SetDlgItemText(IDC_EDIT_PLAYLIST,info);
}
if (m_nChoose==2)
{
a=352*240;
b=352*240/4;
c=352*240/4;
NUM=m_ntotal/(a+b+c);
sprintf(buf,"本视频包括 %d 帧",NUM);
info+=buf; //图像类型
info+=_T(0xd);info+=_T(0xa);
SetDlgItemText(IDC_EDIT_PLAYLIST,info);
}
}
void CPULLOUTDlg::OnCif()
{
// TODO: Add your control notification handler code here
m_nChoose=1;
}
void CPULLOUTDlg::OnSif()
{
// TODO: Add your control notification handler code here
m_nChoose=2;
}
void CPULLOUTDlg::OnUpdateEditNpull()
{
// TODO: If this is a RICHEDIT control, the control will not
// send this notification unless you override the CDialog::OnInitDialog()
// function to send the EM_SETEVENTMASK message to the control
// with the ENM_UPDATE flag ORed into the lParam mask.
UpdateData(true);
if (m_nPull>(NUM-1))
{
MessageBox("帧数超出范围!");
}
// TODO: Add your control notification handler code here
}
///曾经把m_nNumber设置为全局变量,结果在关闭时,程序提示出错,更改后问题解决;为什么?