www.pudn.com > 人体步态跟踪识别bate版.rar > DriveCombo.cpp
// DriveCombo.cpp : implementation file
//
#include "stdafx.h"
#include "humantrack.h"
#include "DriveCombo.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
// Definitions
#define MAX_BUFFER 1024 // Maximum buffer size
/////////////////////////////////////////////////////////////////////////////
// CDriveCombo
CDriveCombo::CDriveCombo()
{
}
CDriveCombo::~CDriveCombo()
{
}
BEGIN_MESSAGE_MAP(CDriveCombo, CComboBox)
//{{AFX_MSG_MAP(CDriveCombo)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CDriveCombo message handlers
BOOL CDriveCombo::Initialize()
{
BOOL bFound = FALSE; // Whether volume info was found or not
DWORD dwRes = 0; // Receives the drive bitmask
int i = 0; // Misc. counter variable
CString str; // Used for string manipulations
char szVolInfo[MAX_BUFFER];
char szDrives[26] = {'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I',
'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R',
'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'};
dwRes = GetLogicalDrives();
if (0 == dwRes)
{
LPVOID lpMsgBuf;
FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER|FORMAT_MESSAGE_FROM_SYSTEM,
NULL, GetLastError(), MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
(LPTSTR) &lpMsgBuf, 0, NULL);
MessageBox((LPTSTR)lpMsgBuf, "GetLastError - GetLogicalDrives failed", MB_OK|MB_ICONERROR);
LocalFree(lpMsgBuf);
return FALSE;
}
// 分离盘符,并增加到组合框中
while (dwRes)
{
if (dwRes & 1)
{
// There's a drive for this bit position.
str.Format("%c: ", szDrives[i]);
// 获取盘符名
SetErrorMode(SEM_FAILCRITICALERRORS);
bFound = GetVolumeInformation(str, szVolInfo, MAX_BUFFER, NULL, NULL, NULL, NULL, NULL);
if (bFound)
str += szVolInfo;
// 增加到组合框
AddString(str);
}
dwRes >>= 1;
i++;
}
// 获取当前目录
dwRes = GetCurrentDirectory(MAX_BUFFER, szVolInfo);
if (0 == dwRes)
{
LPVOID lpMsgBuf;
FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER|FORMAT_MESSAGE_FROM_SYSTEM,
NULL, GetLastError(), MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
(LPTSTR) &lpMsgBuf, 0, NULL);
MessageBox((LPTSTR)lpMsgBuf, "GetLastError - GetCurrentDirectory failed", MB_OK|MB_ICONERROR);
LocalFree(lpMsgBuf);
return FALSE;
}
str.Format("%c", szVolInfo[0]);
i = FindString(-1, str);
SetCurSel(i);
return TRUE;
}
BOOL CDriveCombo::IsDriveReady(int nIndex)
{
HANDLE hFile; // Handle to found file
WIN32_FIND_DATA stFindData; // Info about the found file
CString szDrive; // Drive letter to test
CString szSearch; // Search string
CString szError; // Error message
GetLBText(nIndex, szDrive);
szSearch = szDrive.Left(1);
szSearch += ":\\*.*";
hFile = FindFirstFile((LPCTSTR)szSearch, &stFindData);
if (INVALID_HANDLE_VALUE == hFile)
{
szError.Format("Drive %s: is not ready.", szDrive.Left(1));
MessageBox(szError, "Error", MB_OK|MB_ICONEXCLAMATION);
return FALSE;
}
FindClose(hFile);
return TRUE;
}
void CDriveCombo::ResetDrive(char cDrive)
{
CString szStr;
int nIndex = 0;
szStr.Format("%c:", cDrive);
nIndex = FindString(-1, szStr);
if (CB_ERR != nIndex)
SetCurSel(nIndex);
return;
}