www.pudn.com > DiskInfo.tgz > InfoView.cpp


// InfoView.cpp : implementation file 
// 
 
#include "stdafx.h" 
#include "DiskInfo.h" 
#include "InfoView.h" 
#include "Common/DirDialog.h" 
 
#include "MainFrm.h" 
 
#ifdef _DEBUG 
#define new DEBUG_NEW 
#undef THIS_FILE 
static char THIS_FILE[] = __FILE__; 
#endif 
 
///////////////////////////////////////////////////////////////////////////// 
// CInfoView 
#include "Common/memDC.h" 
 
IMPLEMENT_DYNCREATE(CInfoView, CView) 
 
CInfoView::CInfoView() 
{ 
	m_bEnableFolder = true; 
	m_bFirstShow = true; 
} 
 
CInfoView::~CInfoView() 
{ 
} 
 
 
BEGIN_MESSAGE_MAP(CInfoView, CView) 
	//{{AFX_MSG_MAP(CInfoView) 
	ON_WM_ERASEBKGND() 
	ON_WM_CREATE() 
	ON_WM_SIZE() 
	ON_COMMAND(ID_RESCAN_ALL, OnRescanAll) 
	ON_WM_SHOWWINDOW() 
	ON_WM_TIMER() 
	ON_COMMAND(ID_STOP, OnStop) 
	ON_UPDATE_COMMAND_UI(ID_RESCAN_ALL, OnUpdateRescanAll) 
	ON_UPDATE_COMMAND_UI(ID_STOP, OnUpdateStop) 
	ON_COMMAND(ID_ADD_FOLDER, OnAddFolder) 
	ON_COMMAND(ID_ENABLE_FOLDER, OnEnableFolder) 
	ON_UPDATE_COMMAND_UI(ID_ENABLE_FOLDER, OnUpdateEnableFolder) 
	ON_UPDATE_COMMAND_UI(ID_ADD_FOLDER, OnUpdateAddFolder) 
	ON_WM_HELPINFO() 
	//}}AFX_MSG_MAP 
	ON_MESSAGE(WM_DISKLIST_NOTIFY, OnDiskCtrlNotify) 
END_MESSAGE_MAP() 
 
///////////////////////////////////////////////////////////////////////////// 
// CInfoView drawing 
 
void CInfoView::OnDraw(CDC* pDC) 
{ 
	CDocument* pDoc = GetDocument(); 
	// TODO: add draw code here 
	CMemDC memDC(pDC); 
	CRect rcClient; 
	GetClientRect(&rcClient); 
 
	memDC.FillSolidRect(rcClient, GetSysColor(COLOR_3DFACE)); 
 
	// Draw a Line under the toolbar 
	CRect rc(rcClient); 
	rc.right--; 
	memDC.DrawEdge(rc, EDGE_ETCHED, BF_TOP); 
} 
 
///////////////////////////////////////////////////////////////////////////// 
// CInfoView diagnostics 
 
#ifdef _DEBUG 
void CInfoView::AssertValid() const 
{ 
	CView::AssertValid(); 
} 
 
void CInfoView::Dump(CDumpContext& dc) const 
{ 
	CView::Dump(dc); 
} 
#endif //_DEBUG 
 
///////////////////////////////////////////////////////////////////////////// 
// CInfoView message handlers 
 
BOOL CInfoView::OnEraseBkgnd(CDC* pDC)  
{ 
	return TRUE; 
} 
 
int CInfoView::OnCreate(LPCREATESTRUCT lpCreateStruct)  
{ 
	if (CView::OnCreate(lpCreateStruct) == -1) 
		return -1; 
	 
	m_ctrlDiskInfo.Create(NULL, "", WS_CHILD|WS_VISIBLE,  
		CRect(5,5, 400, 100), this, ID_DISKINFO_CTRL); 
 
	//m_ctrlDiskInfo.ModifyStyleEx(NULL, WS_EX_STATICEDGE, SWP_NOSIZE|SWP_NOMOVE|SWP_NOZORDER); 
 
	UpdateDriveFolders(); 
 
	//Update drives only 
	m_ctrlDiskInfo.Update(); 
	//if (IsWindowVisible()) 
	//	OnRescanAll(); 
	 
	//m_ctrlDiskInfo.AddFolder("C:\\Win98"); 
	//m_ctrlDiskInfo.AddFolder("C:\\Win98"); 
		 
	return 0; 
} 
 
#define _nBorder_X_  3 
#define _nBorder_Y_  3 
 
void CInfoView::OnSize(UINT nType, int cx, int cy)  
{ 
	CView::OnSize(nType, cx, cy); 
	 
	CRect rcClient; 
	GetClientRect(&rcClient); 
 
	m_ctrlDiskInfo.SetWindowPos(NULL,  
		_nBorder_X_, _nBorder_Y_, rcClient.Width()-_nBorder_X_*2, 
		rcClient.Height()-_nBorder_Y_*2, SWP_NOZORDER); 
 
} 
 
void CInfoView::GetMaxMinHeight(int &nMin, int &nMax) 
{ 
	int nMinOne = 22; 
	int nMaxOne = 22; 
 
	int nNumber = m_ctrlDiskInfo.GetSize(); 
	int nSize = m_ctrlDiskInfo.GetDriveSize(); 
	nMin = nMinOne * (nNumber + (nSize!=0)) + ((nSize!=0)?20:0) + 0 +_nBorder_Y_*2; 
	nMax = nMaxOne * (nNumber + (nSize!=0)) + ((nSize!=0)?20:0) + 0 +_nBorder_Y_*2; 
} 
 
void CInfoView::OnRescanAll()  
{ 
	m_ctrlDiskInfo.Update(TRUE); 
} 
 
void CInfoView::OnShowWindow(BOOL bShow, UINT nStatus)  
{ 
	if (bShow && nStatus == 0) 
	{ 
		if (m_bFirstShow /*|| Is paused */) 
		{ 
			m_bFirstShow = FALSE; 
			//OnRescanAll(); 
		} 
	} 
 
	CView::OnShowWindow(bShow, nStatus); 
	 
		 
} 
 
void CInfoView::OnOptionChanged() 
{ 
	UpdateDriveFolders(); 
	m_ctrlDiskInfo.InitCtrl(); 
 
	//if (IsWindowVisible()) 
} 
 
void CInfoView::UpdateDriveFolders() 
{ 
	CWinApp* app = AfxGetApp(); 
	BOOL bRemovable= app->GetProfileInt("Settings", "EnableRemovable", 1); 
	BOOL bFixed = app->GetProfileInt("Settings", "EnableFixed", 1); 
	BOOL bCDROM = app->GetProfileInt("Settings", "EnableCDROM", 1); 
	BOOL bRemote = app->GetProfileInt("Settings", "EnableRemote", 0); 
	BOOL bRamDrive = app->GetProfileInt("Settings", "EnableRAMDisk", 0);	 
	int nInterval = app->GetProfileInt("Settings", "Interval", 3); 
	CString strExclude = app->GetProfileString("Settings", "Exclude", "A:\\ B:\\"); 
 
	m_bEnableFolder = app->GetProfileInt("Settings", "EnableFolder",   1) == 1; 
	CString strData;	 
	strData = app->GetProfileString("Settings", "RedAlert", "50.5"); 
	m_ctrlDiskInfo.m_dRedAlert = atof(strData); 
	strData = app->GetProfileString("Settings", "YellowAlert", "30.5"); 
	m_ctrlDiskInfo.m_dYellowAlert = atof(strData); 
 
	// Load Folder data 
	CStringArray strArray; 
	CString str; 
	int n = 0; 
	str.Format("FolderData%d", n); 
	strData = app->GetProfileString("Settings", str, ""); 
 
	while (!strData.IsEmpty()) 
	{ 
		strArray.Add(strData); 
		n++; 
		str.Format("FolderData%d", n); 
		strData = app->GetProfileString("Settings", str, ""); 
	} 
 
	strExclude.MakeLower(); 
	str = strExclude; 
	str.MakeUpper(); 
	strExclude += str; 
 
	int nPos=0; 
	CString strDrive = "?:\\"; 
	UINT nType; 
 
	m_ctrlDiskInfo.DeleteAll(); 
	 
	DWORD dwDriveList = ::GetLogicalDrives(); 
	while (dwDriveList) 
	{ 
		if (dwDriveList & 1) 
		{ 
			strDrive.SetAt(0, 0x41 + nPos); 
			nType = ::GetDriveType((LPCTSTR)strDrive); 
			 
			switch (nType) 
			{ 
			case DRIVE_REMOVABLE: 
				if (bRemovable && strExclude.Find(strDrive.Left(1))==-1) 
						m_ctrlDiskInfo.AddDrive(strDrive); 
		        break; 
	 
			case DRIVE_FIXED: 
				if (bFixed && strExclude.Find(strDrive.Left(1))==-1 )  
						m_ctrlDiskInfo.AddDrive(strDrive); 
				break; 
		 
			case DRIVE_REMOTE: 
				if (bRemote && strExclude.Find(strDrive.Left(1))==-1 )  
						m_ctrlDiskInfo.AddDrive(strDrive); 
				break; 
 
			case DRIVE_CDROM: 
				if (bCDROM && strExclude.Find(strDrive.Left(1))==-1 )  
						m_ctrlDiskInfo.AddDrive(strDrive); 
				break; 
 
			case DRIVE_RAMDISK: 
				if (bRamDrive && strExclude.Find(strDrive.Left(1))==-1 )  
						m_ctrlDiskInfo.AddDrive(strDrive); 
				break; 
			} 
				 
		} 
		dwDriveList >>= 1; 
		nPos ++; 
	} 
 
	if (m_bEnableFolder) 
	{ 
		int nSize = strArray.GetSize(); 
		CString strFolder; 
 
		for (int i=0; im_strDriveName); 
	((CMainFrame*)AfxGetMainWnd())->SetCurrentFolder(str); 
	((CDiskInfoApp*)AfxGetApp())->OnSwitchMainWindow(); 
	//MessageBox(pItem->m_strDriveName); 
	return 0; 
} 
 
void CInfoView::UpdateDrives() 
{ 
	m_ctrlDiskInfo.Update(); 
} 
 
void CInfoView::UpdateFolders() 
{ 
	m_ctrlDiskInfo.OnStopAll(); 
	m_ctrlDiskInfo.UpdateAbortedFolders(); 
} 
 
void CInfoView::OnUpdateRescanAll(CCmdUI* pCmdUI)  
{ 
	pCmdUI->Enable(m_ctrlDiskInfo.m_nNrThread==0); 
} 
 
void CInfoView::OnUpdateStop(CCmdUI* pCmdUI)  
{ 
	pCmdUI->Enable(m_ctrlDiskInfo.m_nNrThread>0); 
} 
 
void CInfoView::OnAddFolder()  
{ 
	CDirDialog dlg; 
	CString strPath; 
	strPath.LoadString(IDS_SELECTFOLDER_TO_MONITOR); 
	 
	dlg.m_strTitle = strPath; 
	dlg.m_hWnd = GetSafeHwnd(); 
	 
	if (dlg.DoBrowse() == IDOK) 
	{ 
		strPath = dlg.m_strPath; 
		if (strPath.Right(1) != "\\") 
			strPath += "\\"; 
	 
		m_ctrlDiskInfo.AddFolder(strPath); 
		((CInfoFrame*)GetOwner())->UpdateWindowSize(); 
		m_ctrlDiskInfo.Update(); 
 
		m_ctrlDiskInfo.UpdateAbortedFolders(); 
 
		//Save the folder list to registry 
		CWinApp* app = AfxGetApp(); 
		 
		CString strData; 
		CString str; 
		int n = 0; 
		str.Format("FolderData%d", n); 
		strData = app->GetProfileString("Settings", str, ""); 
		while (!strData.IsEmpty()) 
		{ 
			n++; 
			str.Format("FolderData%d", n); 
			strData = app->GetProfileString("Settings", str, ""); 
		} 
 
		app->WriteProfileString("Settings", str, strPath);		 
	} 
} 
 
void CInfoView::OnEnableFolder()  
{ 
	m_bEnableFolder = !m_bEnableFolder; 
	CWinApp* app = AfxGetApp(); 
 
	m_ctrlDiskInfo.OnStopAll(); 
 
	if (m_bEnableFolder) 
	{		 
		// Load Folder data 
		CStringArray strArray; 
		CString str; 
		int n = 0; 
		str.Format("FolderData%d", n); 
		CString strData = app->GetProfileString("Settings", str, ""); 
		 
		while (!strData.IsEmpty()) 
		{ 
			strArray.Add(strData); 
			n++; 
			str.Format("FolderData%d", n); 
			strData = app->GetProfileString("Settings", str, ""); 
		} 
		 
		int nSize = strArray.GetSize(); 
		CString strFolder; 
 
		for (int i=0; iUpdateWindowSize(); 
	m_ctrlDiskInfo.Update(); 
 
	app->WriteProfileInt("Settings", "EnableFolder",   m_bEnableFolder); 
} 
 
void CInfoView::OnUpdateEnableFolder(CCmdUI* pCmdUI)  
{ 
	pCmdUI->SetCheck(m_bEnableFolder); 
} 
 
void CInfoView::OnUpdateAddFolder(CCmdUI* pCmdUI)  
{ 
	pCmdUI->Enable(m_bEnableFolder); 
} 
 
BOOL CInfoView::OnHelpInfo(HELPINFO* pHelpInfo)  
{ 
	return TRUE; 
}