程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> C語言 >> VC >> 關於VC++ >> 用VC列表顯示所有網上鄰居

用VC列表顯示所有網上鄰居

編輯:關於VC++

網上鄰居的查找在www.codeguru.com上有例子,只是它

把它做成了類,本是好事,但對大家理解它的原理增加了難度,

所以現在把它實現在一對話框中,以便大家能一目了然。

#include <winnetwk.h>
#pragma comment(lib, “mpr.lib”)
BOOL CNetEnum2Dlg::Enumerate(LPNETRESOURCE lpNetRC_p)
{
HANDLE hEnum = 0;
DWORD dwScope = RESOURCE_GLOBALNET ;
DWORD dwType = RESOURCETYPE_ANY ;
DWORD dwResult = WNetOpenEnum(
dwScope, // scope of enumeration
dwType, // resource types to list
0, // enumerate all resources
lpNetRC_p, // pointer to resource structure (NULL at first time)
&hEnum // handle to resource
) ;
if( dwResult != NO_ERROR )
return FALSE;
DWORD dwBuffer = 16384 ; // 16K is reasonable size
DWORD dwEntries = 0xFFFFFFFF ; // enumerate all possible entries
LPNETRESOURCE lpnrLocal = 0;
BOOL bRet = TRUE;
//try
{
do
{
// first allocate buffer for NETRESOURCE structures ...
lpnrLocal = (LPNETRESOURCE) GlobalAlloc( GPTR, dwBuffer ) ;
dwResult = WNetEnumResource(
hEnum, // resource-handle
&dwEntries,
lpnrLocal,
&dwBuffer
) ;
if( dwResult == NO_ERROR )
{
for( register DWORD i = 0 ; i
{
CString nsname;
nsname = lpnrLocal[i].lpRemoteName;
nsname += " ";
nsname +=lpnrLocal[i].lpLocalName;
nsname += " ";
nsname +=lpnrLocal[i].lpComment;
m_netList.AddString(nsname); // m_netList defined in NetEnumDlg2.h : CListBox m_netList;
if( RESOURCEUSAGE_CONTAINER ==
(lpnrLocal[i].dwUsage & RESOURCEUSAGE_CONTAINER) &&
lpnrLocal[i].dwDisplayType != RESOURCEDISPLAYTYPE_SERVER )
if( !Enumerate( &lpnrLocal[i]) )
{
//TRACE0( "CNetwork::Enumerate(): recursiv call failedn" );
//throw CNetworkBreak(FALSE);
return FALSE;
}
}
} else if( dwResult != ERROR_NO_MORE_ITEMS )
{
//AfxMessageBox("WNetEnumResource");
return FALSE;
}
} while( dwResult != ERROR_NO_MORE_ITEMS );
}
if( lpnrLocal )
GlobalFree((HGLOBAL) lpnrLocal) ;
WNetCloseEnum(hEnum) ;
return bRet;
}
void CNetEnum2Dlg::OnListWNet()
{
Enumerate(0);
}

  1. 上一頁:
  2. 下一頁:
欄目導航
Copyright © 程式師世界 All Rights Reserved