将当前驱动器加入到Tree中.其中 m_tree 为树.
//函数功能:获取驱动器
//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
void CTreeViewDlg::GetLogicalDrives(HTREEITEM hParent)
{
size_t szAllDriveStrings = GetLogicalDriveStrings(0,NULL);
char *pDriveStrings = new char[szAllDriveStrings + sizeof(_T(""))];
GetLogicalDriveStrings(szAllDriveStrings,pDriveStrings);
size_t szDriveString = strlen(pDriveStrings);
while(szDriveString > 0)
{
m_tree.InsertItem(pDriveStrings,hParent);
pDriveStrings += szDriveString + 1;
szDriveString = strlen(pDriveStrings);
}
}
GetLogicalDriveStrings这个函数我明白了,就是不不明白在WHILE循环里面怎么一个一个的取出盘符的.
多谢!
The GetLogicalDriveStrings function fills a buffer with strings that specify valid drives in the system.
DWORD GetLogicalDriveStrings(
DWORD nBufferLength,
LPTSTR lpBuffer
);
Parameters
nBufferLength
[in] Maximum size of the buffer pointed to by lpBuffer, in TCHARs. This size does not include the terminating null character. If this parameter is zero, lpBuffer is not used.
lpBuffer
[out] Pointer to a buffer that receives a series of null-terminated strings, one for each valid drive in the system, that end with a second null character. The following example shows the buffer contents with <null> representing the terminating null character.
c:\<null>d:\<null><null>
返回的结构是这样的,你就很容易看出来是怎么实现的了,通过指针移动