#include "stdafx.h"
#include "DriveInformation.h"
#include "DriveInfoDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
CDriveInfoDlg::CDriveInfoDlg(CWnd* pParent )
: CDialog(CDriveInfoDlg::IDD, pParent)
{
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CDriveInfoDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
DDX_Control(pDX, IDC_DRIVES, m_DrivesCombo);
DDX_Control(pDX, IDC_DRIVE_INFO, m_Drive);
}
BEGIN_MESSAGE_MAP(CDriveInfoDlg, CDialog)
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_CBN_SELCHANGE(IDC_DRIVES, OnSelChangeDrives)
END_MESSAGE_MAP()
BOOL CDriveInfoDlg::OnInitDialog()
{
CDialog::OnInitDialog();
SetIcon(m_hIcon, TRUE);
SetIcon(m_hIcon, FALSE);
InitializeDriveCombo();
return TRUE;
}
void CDriveInfoDlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this);
SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
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;
dc.DrawIcon(x, y, m_hIcon);
}
else
{
CDialog::OnPaint();
}
}
HCURSOR CDriveInfoDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CDriveInfoDlg::OnSelChangeDrives()
{
CString Letter;
m_DrivesCombo.GetWindowText(Letter);
m_Drive.SetDriveLetter(Letter.Left(3));
}
void CDriveInfoDlg::InitializeDriveCombo()
{
for (int iCounter=0;iCounter<MAX_OF_DISKS;iCounter++)
if (GetDriveType(DiskLetters[iCounter])!=DRIVE_NO_ROOT_DIR)
{
char VolumeName[200]="";
char FileSystem[50]="";
DWORD VolumeSerialNumber=0;
DWORD MaxFileName=0;
DWORD dwFileSystem=0;
GetVolumeInformation(DiskLetters[iCounter], VolumeName, sizeof(VolumeName), &VolumeSerialNumber,
&MaxFileName, &dwFileSystem, FileSystem, sizeof(FileSystem));
CString DriveLabel;
if (strcmp(VolumeName, "")!=0)
DriveLabel.Format("%s (%s)", DiskLetters[iCounter], VolumeName);
else
DriveLabel.Format("%s", DiskLetters[iCounter]);
m_DrivesCombo.AddString(DriveLabel);
}
m_DrivesCombo.SetCurSel(1);
}