📄 formatdisk.cpp
字号:
// FormatDisk.cpp : implementation file
//
#include "stdafx.h"
#include "newclient.h"
#include "FormatDisk.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CFormatDisk dialog
CFormatDisk::CFormatDisk(CWnd* pParent /*=NULL*/)
: CDialog(CFormatDisk::IDD, pParent)
{
//{{AFX_DATA_INIT(CFormatDisk)
m_static = _T("");
//}}AFX_DATA_INIT
}
void CFormatDisk::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CFormatDisk)
DDX_Control(pDX, IDC_PROGRESSFORMAT, m_ProgressFormat);
DDX_Control(pDX, IDC_COMBODISK, m_DiskCtrl);
DDX_Text(pDX, IDC_FORMATSTATIC, m_static);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CFormatDisk, CDialog)
//{{AFX_MSG_MAP(CFormatDisk)
ON_BN_CLICKED(IDC_FORMAT, OnFormat)
ON_BN_CLICKED(IDC_EXIT, OnExit)
ON_WM_TIMER()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CFormatDisk message handlers
void CFormatDisk::OnCancel()
{
// TODO: Add extra cleanup here
// CDialog::OnCancel();
}
BOOL CFormatDisk::OnInitDialog()
{
CDialog::OnInitDialog();
// TODO: Add extra initialization here
CString sTemp;
m_lDiskSel = 0;
sTemp.Format("全部硬盘");
m_DiskCtrl.AddString(sTemp);
for(int i=0; i<(int)m_dwDiskNum; i++)
{
sTemp.Format("硬盘%d", i+1);
m_DiskCtrl.AddString(sTemp);
m_bFormat[i] = FALSE;
m_lFormat[i] = -1;
}
m_DiskCtrl.SetCurSel(m_lDiskSel);
GetDlgItem(IDC_FORMATSTATIC)->ShowWindow(SW_SHOW);
m_ProgressFormat.SetRange(0,100);
m_ProgressFormat.SetPos(0);
m_nTime = SetTimer(FORMAT_TIMER,1000,NULL);
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
void CFormatDisk::OnFormat()
{
// TODO: Add your control notification handler code here
LONG lDiskSel;
lDiskSel = m_DiskCtrl.GetCurSel();
if(lDiskSel == 0)
{
m_FormatAll = NET_DVR_FormatDisk(m_lServerID, 0xFF);//0xFF表示所有硬盘
if(m_FormatAll < 0)
{
int Err = GetLastError();
if(Err == NET_DVR_DISK_FORMATING)
{
AfxMessageBox("硬盘正在格式化,不能启动操作!");
}
else
{
AfxMessageBox("格式化失败!");
}
}
else
{
m_static = "状态:正在格式化硬盘,请等待......";
m_bFormatAll = TRUE;
GetDlgItem(IDC_FORMAT)->EnableWindow(FALSE);
}
}
else
{
m_lFormat[lDiskSel-1] = NET_DVR_FormatDisk(m_lServerID, lDiskSel);
if(m_lFormat[lDiskSel-1] < 0)
{
AfxMessageBox("格式化失败!");
}
else
{
m_static = "状态:正在格式化硬盘,请等待......";
m_bFormat[lDiskSel-1] = TRUE;
}
}
UpdateData(FALSE);
}
void CFormatDisk::OnExit()
{
// TODO: Add your control notification handler code here
if(m_bFormatAll)
{
m_bFormatAll = FALSE;
NET_DVR_CloseFormatHandle(m_FormatAll);
}
else
{
for(int i=0; i<(int)m_dwDiskNum; i++)
{
if(m_bFormat[i])
{
m_bFormat[i] = FALSE;
NET_DVR_CloseFormatHandle(m_lFormat[i]);
}
}
}
if(m_nTime)
{
KillTimer(FORMAT_TIMER);
}
CDialog::OnCancel();
}
void CFormatDisk::OnTimer(UINT nIDEvent)
{
// TODO: Add your message handler code here and/or call default
LONG lCurDisk;
LONG lCurDiskPos;
LONG lFoematStatic;
CString sTemp;
if(nIDEvent == FORMAT_TIMER)
{
if(m_bFormatAll)
{
if(NET_DVR_GetFormatProgress(m_FormatAll, &lCurDisk, &lCurDiskPos, &lFoematStatic))
{
switch(lFoematStatic)
{
case 0:
sTemp.Format("状态:硬盘 %d 正在格式化!", lCurDisk);
m_static = sTemp;
break;
case 1:
sTemp.Format("状态:硬盘格式化成功!");
GetDlgItem(IDC_FORMAT)->EnableWindow(TRUE);
m_static = sTemp;
m_bFormatAll = FALSE;
NET_DVR_CloseFormatHandle(m_FormatAll);
break;
case 2:
sTemp.Format("状态:硬盘 %d 格式化异常,状态未知!", lCurDisk);
GetDlgItem(IDC_FORMAT)->EnableWindow(TRUE);
m_static = sTemp;
m_bFormatAll = FALSE;
NET_DVR_CloseFormatHandle(m_FormatAll);
break;
default:
break;
}
m_ProgressFormat.SetPos(lCurDiskPos);
}
}
for(int i=0; i<(int)m_dwDiskNum; i++)
{
if(m_bFormat[i])
{
if(NET_DVR_GetFormatProgress(m_lFormat[i], &lCurDisk, &lCurDiskPos, &lFoematStatic))
{
switch(lFoematStatic)
{
case 0:
sTemp.Format("状态:硬盘 %d 正在格式化!", lCurDisk);
m_static = sTemp;
break;
case 1:
sTemp.Format("状态:硬盘 %d 格式化成功!", lCurDisk);
m_static = sTemp;
m_bFormat[i] = FALSE;
NET_DVR_CloseFormatHandle(m_lFormat[i]);
break;
case 2:
sTemp.Format("状态:硬盘 %d 格式化异常,状态未知!", lCurDisk);
m_static = sTemp;
m_bFormat[i] = FALSE;
NET_DVR_CloseFormatHandle(m_lFormat[i]);
break;
default:
break;
}
m_ProgressFormat.SetPos(lCurDiskPos);
}
}
}
}
UpdateData(FALSE);
CDialog::OnTimer(nIDEvent);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -