VolumeDlg.h
上传用户:hy_wanghao
上传日期:2007-01-08
资源大小:279k
文件大小:4k
- // VolumeDlg.h : Declaration of the CVolumeDlg
- #ifndef __VOLUMEDLG_H_
- #define __VOLUMEDLG_H_
- #include "resource.h" // main symbols
- #include "PieChart.h"
- EXTERN_C const CLSID CLSID_VolumeDlg;
- /////////////////////////////////////////////////////////////////////////////
- // CVolumeDlg
- // The Amiga Property page for ADF files (volumes).
- //
- // It is implemented as a Property Sheet Shell extension,
- // so it needs to be a COM object supporting IShellPropSheetExt
- // and IShellExtInit.
- class ATL_NO_VTABLE CVolumeDlg :
- public CComObjectRootEx<CComSingleThreadModel>,
- public CComCoClass<CVolumeDlg, &CLSID_VolumeDlg>,
- public CShellPropertyPage<CVolumeDlg>
- {
- public:
- enum { IDD = IDD_PROP_VOLUME };
- enum { IDS_TABCAPTION = IDS_VOLUME_CAPTION };
- enum { ID_TAB_INDEX = 1 };
- DECLARE_PROTECT_FINAL_CONSTRUCT()
- BEGIN_COM_MAP(CVolumeDlg)
- COM_INTERFACE_ENTRY_IID(IID_IShellPropSheetExt, IShellPropSheetExt)
- COM_INTERFACE_ENTRY_IID(IID_IShellExtInit, IShellExtInit)
- END_COM_MAP()
- BEGIN_MSG_MAP(CVolumeDlg)
- MESSAGE_HANDLER(WM_INITDIALOG, OnInitDialog)
- END_MSG_MAP()
- // CVolumeDlg
- public:
- static HRESULT WINAPI UpdateRegistry(BOOL bRegister)
- {
- CComBSTR bstrCLSID(CLSID_VolumeDlg);
- CComBSTR bstrDescription;
- CComBSTR bstrProject;
- bstrDescription.LoadString(IDS_DESCRIPTION);
- bstrProject.LoadString(IDS_PROJNAME);
- _ATL_REGMAP_ENTRY rm[] = {
- { OLESTR("CLSID"), bstrCLSID },
- { OLESTR("PROJECTNAME"), bstrProject },
- { OLESTR("DESCRIPTION"), bstrDescription },
- { NULL,NULL } };
- return _Module.UpdateRegistryFromResource(IDR_VOLUMEDLG, bRegister, rm);
- }
- // Attributes:
- public:
- CPieChart m_pie;
- // Message handlers
- public:
- LRESULT OnInitDialog(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/)
- {
- ATLASSERT(m_szFileName[0]);
- CAdfDevice dev;
- CAdfVolume vol;
- if( OpenAmigaDevice(m_szFileName, TRUE, NULL, dev, vol)!=S_OK ) return 0;
- CResString<64> sType;
- TCHAR szTemp[200];
- UINT idStr;
- // Name
- vol.GetName(szTemp, lengthof(szTemp));
- SetDlgItemText(IDC_NAME, szTemp);
- // Type
- switch( dev.GetType() ) {
- case DEVTYPE_FLOPDD: idStr = IDS_FLOPDD; break;
- case DEVTYPE_FLOPHD: idStr = IDS_FLOPHD; break;
- case DEVTYPE_HARDDISK: idStr = IDS_HARDDISK; break;
- case DEVTYPE_HARDFILE: idStr = IDS_HARDFILE; break;
- default:
- idStr = IDS_UNKNOWN;
- }
- sType.LoadString(idStr);
- SetDlgItemText(IDC_TYPE, sType);
- // File System
- idStr = isFFS(vol.GetDOSType()) ? IDS_FFS : IDS_OFS;
- sType.LoadString(idStr);
- SetDlgItemText(IDC_FILESYSTEM, sType);
- // Flags
- sType.LoadString( isFFS(vol.GetDOSType()) ? IDS_FLAG_FFS : IDS_FLAG_OFS );
- _tcscpy(szTemp, sType);
- if( isINTL(vol.GetDOSType()) ) {
- _tcscat(szTemp, _T(" "));
- sType.LoadString(IDS_FLAG_INTL);
- _tcscat(szTemp, sType);
- }
- if( isDIRCACHE(vol.GetDOSType()) ) {
- _tcscat(szTemp, _T(" "));
- sType.LoadString(IDS_FLAG_DIRCACHE);
- _tcscat(szTemp, sType);
- }
- SetDlgItemText(IDC_FLAGS, szTemp);
- // Capacity
- Int2Str( szTemp, (vol.GetLastBlock() + 1 - vol.GetFirstBlock()) * LOGICAL_BLOCK_SIZE );
- SetDlgItemText(IDC_CAPACITY, szTemp);
- // Used space
- Int2Str( szTemp, ((vol.GetLastBlock() + 1 - vol.GetFirstBlock()) - vol.GetFreeBlockCount()) * LOGICAL_BLOCK_SIZE );
- SetDlgItemText(IDC_USEDSPACE, szTemp);
- // Free space
- Int2Str( szTemp, (vol.GetFreeBlockCount()) * LOGICAL_BLOCK_SIZE );
- SetDlgItemText(IDC_FREESPACE, szTemp);
-
- // Percent control
- DWORD dwPercent = (((vol.GetLastBlock() + 1 - vol.GetFirstBlock()) - vol.GetFreeBlockCount()) * 100) /
- (vol.GetLastBlock() + 1 - vol.GetFirstBlock());
- m_pie.SubclassWindow(GetDlgItem(IDC_PIE));
- m_pie.SetPercent(dwPercent);
- return 1;
- }
- void Int2Str(LPTSTR pszText, DWORD i)
- {
- USES_CONVERSION;
- WCHAR szwTemp[64];
- LONGLONG longlong = i;
- ::StrFormatByteSizeW(longlong, szwTemp, lengthof(szwTemp));
- ATLASSERT(!::IsBadWritePtr(pszText, lengthof(szwTemp)));
- _tcsncpy(pszText, W2CT(szwTemp), lengthof(szwTemp));
- }
- };
- #endif //__VOLUMEDLG_H_