::OnTest()
{
CListBox* pListBox = (CListBox*)GetDlgItem(IDC_LIST);
pListBox->ResetContent();
EnumNet(NULL, 0);
}
::EnumNet(NETRESOURCE* pResource, int nItem)
{
HANDLE hEnum = NULL;
DWORD dwResult = 0;
//打开网上资源的枚举
dwResult = WNetOpenEnum(
RESOURCE_GLOBALNET,
RESOURCETYPE_ANY,
0,
pResource,
&hEnum);
if (dwResult != NO_ERROR)
{
return;
}
DWORD nCount = -1;
DWORD nSize = 16384;
pResource = (NETRESOURCE*)new BYTE[nSize];
do
{
ZeroMemory(pResource, nSize);
//枚举网上资源
dwResult = WNetEnumResource(
hEnum,
&nCount,
pResource,
&nSize);
if (dwResult == NO_ERROR)
{
for (UINT n = 0 ; n < nCount; n++)
{
ShowNet(&pResource[n], nItem);
//如果网络资源是容器资源则递归调用枚举函数
if ((pResource[n].dwUsage & RESOURCEUSAGE_CONTAINER)
== RESOURCEUSAGE_CONTAINER)
{
EnumNet(&pResource[n], nItem + 1);
}
}
}
else if(dwResult != ERROR_NO_MORE_ITEMS)
{
break;
}
} while(dwResult != ERROR_NO_MORE_ITEMS);
delete[] pResource;
//关闭网上资源的枚举
WNetCloseEnum(hEnum);
}
::ShowNet(NETRESOURCE* pResource, int nItem)
{
CString strText = _T("");
strText += _T("");
strText += pResource->lpRemoteName;
strText += _T("");
strText += pResource->lpLocalName;
strText += _T("");
strText += pResource->lpComment;
strText += _T("");
for (int n = 0; n < nItem; n++)
{
strText = _T(" ") + strText;
}
CListBox* pListBox = (CListBox*)GetDlgItem(IDC_LIST);
pListBox->AddString(strText);
}
{
CListBox* pListBox = (CListBox*)GetDlgItem(IDC_LIST);
pListBox->ResetContent();
EnumNet(NULL, 0);
}
::EnumNet(NETRESOURCE* pResource, int nItem)
{
HANDLE hEnum = NULL;
DWORD dwResult = 0;
//打开网上资源的枚举
dwResult = WNetOpenEnum(
RESOURCE_GLOBALNET,
RESOURCETYPE_ANY,
0,
pResource,
&hEnum);
if (dwResult != NO_ERROR)
{
return;
}
DWORD nCount = -1;
DWORD nSize = 16384;
pResource = (NETRESOURCE*)new BYTE[nSize];
do
{
ZeroMemory(pResource, nSize);
//枚举网上资源
dwResult = WNetEnumResource(
hEnum,
&nCount,
pResource,
&nSize);
if (dwResult == NO_ERROR)
{
for (UINT n = 0 ; n < nCount; n++)
{
ShowNet(&pResource[n], nItem);
//如果网络资源是容器资源则递归调用枚举函数
if ((pResource[n].dwUsage & RESOURCEUSAGE_CONTAINER)
== RESOURCEUSAGE_CONTAINER)
{
EnumNet(&pResource[n], nItem + 1);
}
}
}
else if(dwResult != ERROR_NO_MORE_ITEMS)
{
break;
}
} while(dwResult != ERROR_NO_MORE_ITEMS);
delete[] pResource;
//关闭网上资源的枚举
WNetCloseEnum(hEnum);
}
::ShowNet(NETRESOURCE* pResource, int nItem)
{
CString strText = _T("");
strText += _T("");
strText += pResource->lpRemoteName;
strText += _T("");
strText += pResource->lpLocalName;
strText += _T("");
strText += pResource->lpComment;
strText += _T("");
for (int n = 0; n < nItem; n++)
{
strText = _T(" ") + strText;
}
CListBox* pListBox = (CListBox*)GetDlgItem(IDC_LIST);
pListBox->AddString(strText);
}