// FormatDisk.cpp : implementation file // #include "stdafx.h" #include "StoneU_HC_OCX.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(""); m_ProgressNum = _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); DDX_Text(pDX, IDC_PROGRESSNUM, m_ProgressNum); //}}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_HIDE); 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) { MessageBox("硬盘正在格式化,不能启动操作!", "温馨提示", MB_ICONINFORMATION); } else { MessageBox("格式化失败!", "温馨提示", MB_ICONINFORMATION); } } else { m_static = "状态:正在格式化硬盘,请等待......"; m_bFormatAll = TRUE; GetDlgItem(IDC_FORMAT)->EnableWindow(FALSE); } } else { //zxy 2005-01-12 lDiskSel => lDiskSel-1 m_lFormat[lDiskSel-1] = NET_DVR_FormatDisk(m_lServerID, lDiskSel-1); if(m_lFormat[lDiskSel-1] < 0) { MessageBox("格式化失败!", "温馨提示", MB_ICONINFORMATION); } 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+1); 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+1); GetDlgItem(IDC_FORMAT)->EnableWindow(TRUE); m_static = sTemp; m_bFormatAll = FALSE; NET_DVR_CloseFormatHandle(m_FormatAll); break; case 3: sTemp.Format("状态:硬盘 %d 格式化出现网络异常,该硬盘已不可见!", lCurDisk+1); GetDlgItem(IDC_FORMAT)->EnableWindow(TRUE); m_static = sTemp; m_bFormatAll = FALSE; NET_DVR_CloseFormatHandle(m_FormatAll); break; default: break; } m_ProgressFormat.SetPos(lCurDiskPos); m_ProgressNum.Format("%d %%", 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+1); m_static = sTemp; break; case 1: sTemp.Format("状态:硬盘 %d 格式化成功!", lCurDisk+1); m_static = sTemp; m_bFormat[i] = FALSE; NET_DVR_CloseFormatHandle(m_lFormat[i]); break; case 2: sTemp.Format("状态:硬盘 %d 格式化时出错,不能继续格式化此硬盘!", lCurDisk+1); m_static = sTemp; m_bFormat[i] = FALSE; NET_DVR_CloseFormatHandle(m_lFormat[i]); break; case 3: sTemp.Format("状态:硬盘 %d 格式化出现网络异常,该硬盘已不可见!", lCurDisk+1); m_static = sTemp; m_bFormat[i] = FALSE; NET_DVR_CloseFormatHandle(m_lFormat[i]); break; default: break; } m_ProgressFormat.SetPos(lCurDiskPos); m_ProgressNum.Format("%d %%", lCurDiskPos); } } } } UpdateData(FALSE); CDialog::OnTimer(nIDEvent); }