📄 filecutdlg.cpp
字号:
// FileCutDlg.cpp : implementation file
//
#include "stdafx.h"
#include "FileCut.h"
#include "FileCutDlg.h"
#include "hikplaympeg4.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()
/////////////////////////////////////////////////////////////////////////////
// CFileCutDlg dialog
CFileCutDlg::CFileCutDlg(CWnd* pParent /*=NULL*/)
: CDialog(CFileCutDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CFileCutDlg)
m_bSaveFile = _T("");
m_FileSize = 0;
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CFileCutDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CFileCutDlg)
DDX_Text(pDX, IDC_EDIT2, m_bSaveFile);
DDX_Text(pDX, IDC_EDIT3, m_FileSize);
DDV_MinMaxInt(pDX, m_FileSize, 1, 2000);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CFileCutDlg, CDialog)
//{{AFX_MSG_MAP(CFileCutDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
ON_BN_CLICKED(IDC_BUTTON2, OnButton2)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CFileCutDlg message handlers
BOOL CFileCutDlg::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
m_FileSize=1;
UpdateData(FALSE);
return TRUE; // return TRUE unless you set the focus to a control
}
void CFileCutDlg::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 CFileCutDlg::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 CFileCutDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CFileCutDlg::OnButton1()
{
CFileDialog fg(
TRUE,
"mpg",
NULL,
OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,
"MPEG4文件(*.mp4)|*.mp4|所有文件(*.*)|*.*||", this);
if(fg.DoModal() == IDCANCEL)
{
return ;
}
m_strPlayFileName = fg.GetPathName();
GetDlgItem(IDC_EDIT1)->SetWindowText(m_strPlayFileName);
}
void CFileCutDlg::OnButton2()
{
// UpdateData();
CFileDialog pFile(FALSE,
"mpg",
m_bSaveFile,
OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,
"MPEG4文件(*.mp4)|*.mp4|所有文件(*.*)|*.*||", this);
pFile.m_ofn.lpstrInitialDir="";
pFile.m_ofn.lpstrTitle="保存视频文件";
if(pFile.DoModal()==IDCANCEL) return;
m_bSaveFile=pFile.GetPathName();
UpdateData(FALSE);
}
void CFileCutDlg::OnOK()
{
UpdateData();
SetCursor(::LoadCursor(NULL,IDC_WAIT));
HANDLE m_hPlayFile;
m_hPlayFile=CreateFile(
m_strPlayFileName,
GENERIC_READ,
FILE_SHARE_READ,
NULL,
OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL,
NULL);
if(m_hPlayFile==INVALID_HANDLE_VALUE)
{
MessageBox("打开文件失败");
return ;
}
//Copy file
DWORD nSize=4096*100;//每次处理400k数据;
PBYTE pBuf=new BYTE [nSize];
BYTE pHead[60];
CFileFind ff;
DWORD nFileHeadLen=Hik_PlayM4_GetFileHeadLength();
DWORD nRet;
// DWORD nCount;
ULONG total=0;
DWORD ll=0,lh=0;
__int64 ulong;
//写文件头
char cut[]={'0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f','g'};
int k=0;
int size;
BOOL is=ff.FindFile(m_strPlayFileName);
if(is)
ff.FindNextFile();
//DWORD len=ff.GetLength();
ulong=ff.GetLength64();
// ulong=0x12345678123456ff;
// ll=ulong&0xffffffff;
// lh=(ulong>>32)&0xffffffff;
SetFilePointer(m_hPlayFile,0,0,FILE_BEGIN);
if(!ReadFile(m_hPlayFile,pHead,nFileHeadLen,&nRet,NULL))
{
MessageBox("读文件头失败");
goto end;
}
m_FileSize=m_FileSize*1024*1024;
SetFilePointer(m_hPlayFile,nFileHeadLen,0,FILE_BEGIN);
total=nFileHeadLen;
HANDLE hNewFile;
m_bSaveFile.Insert(m_bSaveFile.GetLength()-4," ");
while(1){
//m_bSaveFile+=cut[k];
m_bSaveFile.SetAt(m_bSaveFile.GetLength()-5,cut[k]);
hNewFile=CreateFile(
m_bSaveFile,
GENERIC_WRITE,
FILE_SHARE_READ|FILE_SHARE_WRITE,
NULL,
CREATE_ALWAYS,
FILE_ATTRIBUTE_NORMAL,
NULL);
if(hNewFile==INVALID_HANDLE_VALUE)
{
CString csErrorName;
csErrorName.Format("创建文件:%s失败",m_bSaveFile);
MessageBox(csErrorName);
return;
}
if(!WriteFile(hNewFile,pHead,nFileHeadLen,&nRet,NULL))
{
MessageBox("写文件头失败");
goto end;
}
size=0;
while(size<=m_FileSize)
{
if(!ReadFile(m_hPlayFile,pBuf,nSize,&nRet,NULL))
{
MessageBox("读文件失败");
goto end;
}
if(!WriteFile(hNewFile,pBuf,nSize,&nRet,NULL))
{
MessageBox("写文件失败");
goto end;
}
//total+=nSize;
size+=nSize;
ulong=ulong-nSize;
if(ulong<=0) goto end;
/*if(lh==0){
if(total>=ll) goto end;
}
else{
if(total>=ll){
total=0;
ll=lh;
lh=0;
}
}
*/
}
k++;
CloseHandle(hNewFile);
}
end:
delete []pBuf;
CloseHandle(hNewFile);
CloseHandle(m_hPlayFile);
SetCursor(AfxGetApp()->LoadCursor(IDC_POINTER));
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -