⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cwicnetexampleview.cpp

📁 关于文件夹共享的一个程序
💻 CPP
字号:
// CWiCnetExampleView.cpp : implementation of the CCWiCnetExampleView class
//

#include "stdafx.h"
#include "CWiCnetExample.h"

#include "CWiCnetExampleDoc.h"
#include "CWiCnetExampleView.h"
#include "Selom Ofori\TreeExampleDlg.h"
#include "ShareAddInfoDlg.h"
#include "CWiCNet.h"
#include "EnumNetResources.h"




#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CCWiCnetExampleView

IMPLEMENT_DYNCREATE(CCWiCnetExampleView, CTreeView)

BEGIN_MESSAGE_MAP(CCWiCnetExampleView, CTreeView)
	//{{AFX_MSG_MAP(CCWiCnetExampleView)
	ON_COMMAND(ID_SHARE_ADD, OnShareAdd)
	ON_COMMAND(ID_SHARE_DEL, OnShareDel)
	ON_COMMAND(ID_ENUM_RES, OnEnumRes)
	ON_COMMAND(ID_LOCAL_INFO, OnLocalInfo)
	ON_UPDATE_COMMAND_UI(ID_SHARE_DEL, OnUpdateShareDel)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CCWiCnetExampleView construction/destruction

CCWiCnetExampleView::CCWiCnetExampleView()
{
	// TODO: add construction code here

}

CCWiCnetExampleView::~CCWiCnetExampleView()
{
}

BOOL CCWiCnetExampleView::PreCreateWindow(CREATESTRUCT& cs)
{
	// TODO: Modify the Window class or styles here by modifying
	//  the CREATESTRUCT cs

	return CTreeView::PreCreateWindow(cs);
}

/////////////////////////////////////////////////////////////////////////////
// CCWiCnetExampleView drawing

void CCWiCnetExampleView::OnDraw(CDC* /*pDC*/)
{
	CCWiCnetExampleDoc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);
	// TODO: add draw code for native data here
}

void CCWiCnetExampleView::OnInitialUpdate()
{
	CTreeView::OnInitialUpdate();

	CTreeCtrl& tc = GetTreeCtrl();
	LONG lStyle = GetWindowLong( tc.m_hWnd, GWL_STYLE );
	lStyle |= TVS_HASLINES | TVS_LINESATROOT | TVS_HASBUTTONS;
	SetWindowLong( tc.m_hWnd, GWL_STYLE, lStyle ); 
}

/////////////////////////////////////////////////////////////////////////////
// CCWiCnetExampleView diagnostics

#ifdef _DEBUG
void CCWiCnetExampleView::AssertValid() const
{
	CTreeView::AssertValid();
}

void CCWiCnetExampleView::Dump(CDumpContext& dc) const
{
	CTreeView::Dump(dc);
}

CCWiCnetExampleDoc* CCWiCnetExampleView::GetDocument() // non-debug version is inline
{
	ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CCWiCnetExampleDoc)));
	return (CCWiCnetExampleDoc*)m_pDocument;
}
#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CCWiCnetExampleView message handlers

void CCWiCnetExampleView::OnShareAdd() 
{
	CTreeExampleDlg* pDlg = new CTreeExampleDlg;

	int nDlgCode = pDlg->DoModal();
	if( nDlgCode != IDOK )
	{
		delete pDlg;
		return;
	}
	
	ShareAddInfoDlg* pSAID = new ShareAddInfoDlg( pDlg->strSelectedPath );
	delete	pDlg;

	int nSAIDRes = pSAID->DoModal();
	if( nSAIDRes != IDOK )
	{
		delete	pSAID;
		return;
	}

	CWiCNet* pNetFunctionCaller = new CWiCNet;

	if( pNetFunctionCaller->NetShareAdd( pSAID->m_FileName, pSAID->m_Name, pSAID->m_Comment, pSAID->m_ReadOnly != 0, pSAID->m_Password ) )
	{
		MessageBox("Ok, shared!");
	}
	else
	{
		MessageBox("Failed!");
	}
}

////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////

void CCWiCnetExampleView::OnShareDel() 
{
	CWiCNet* pNetFunctionCaller = new CWiCNet;

	if( pNetFunctionCaller->NetShareDel( m_Res2Del ) )
	{
		MessageBox("Ok, deleted!");
	}
	else
	{
		MessageBox("Failed!");
	}	
}

void CCWiCnetExampleView::OnUpdateShareDel(CCmdUI* pCmdUI) 
{
	CTreeCtrl& tc = GetTreeCtrl();
	
	HTREEITEM selitem = tc.GetSelectedItem();
	
	CString strItem = tc.GetItemText(selitem);

	int nStartOfResourse = strItem.ReverseFind('\\');
	
	if( nStartOfResourse != -1 )
	{
		m_Res2Del = strItem.Right(strItem.GetLength()-nStartOfResourse-1);
		if( !m_Res2Del.IsEmpty() )
		{
			HTREEITEM parent = tc.GetParentItem(selitem);
			if( parent != NULL )
			{
				CString strParent = tc.GetItemText(parent);
				int nStartOfServer = strParent.ReverseFind('\\');
				if( nStartOfServer != -1 )
				{
					CString strSelServer = strParent.Right(strParent.GetLength()-nStartOfServer-1);
					if( !stricmp( strSelServer, m_strServer ) )
					{
						pCmdUI->Enable(TRUE);
						return;
					}
				}
			}
		}
	}
	
	pCmdUI->Enable(FALSE);	
}

////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////

void ProcessNetRecord(LPNETRESOURCE lpnr, void* pTreeCtrl )
{
	CTreeCtrl* tc = reinterpret_cast<CTreeCtrl*>(pTreeCtrl);
	
	static HTREEITEM hAllNet = 0;
	static HTREEITEM hDomain = 0;
	static HTREEITEM hComp = 0;

	switch( lpnr->dwDisplayType )
	{
		//	0x00000006
		case RESOURCEDISPLAYTYPE_NETWORK:
		if( lpnr->lpRemoteName == NULL )
		{
			hAllNet = tc->InsertItem( lpnr->lpComment, 0, TVI_LAST );
		}
		else
		{
			hAllNet = tc->InsertItem( lpnr->lpRemoteName, 0, TVI_LAST ); 
		}
		break;

		//	0x00000001
		case RESOURCEDISPLAYTYPE_DOMAIN: // The object should be displayed as a domain. 
		hDomain = tc->InsertItem( lpnr->lpRemoteName, hAllNet, TVI_LAST );
		break;
		
		//	0x00000002 
		case RESOURCEDISPLAYTYPE_SERVER:	// The object should be displayed as a server.
		hComp = tc->InsertItem( lpnr->lpRemoteName, hDomain );
		break;

		// 0x00000003
		case RESOURCEDISPLAYTYPE_SHARE:	// The object should be displayed as a sharepoint
		tc->InsertItem( lpnr->lpRemoteName, hComp );
		break;

		default:
		AfxMessageBox( "One more type!" );
		break;
	}
}

void CCWiCnetExampleView::OnEnumRes() 
{
	CDC* pDC = GetDC();
	CTreeCtrl& tc = GetTreeCtrl();

	BeginWaitCursor(); // display the hourglass cursor
	
	EnumerateFunc( m_hWnd, pDC->m_hDC, NULL, &tc, ProcessNetRecord );

	EndWaitCursor(); // remove the hourglass cursor
}

////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////

void CCWiCnetExampleView::OnLocalInfo() 
{
	CCWiCnetExampleDoc* pDoc = GetDocument();

	CString strAddress;
	strAddress.LoadString( IDS_ADDRESS_ROOT );

	CTreeCtrl& tc = GetTreeCtrl();
	HTREEITEM hParenHost = tc.InsertItem( strAddress, 0, 0 );
	m_strServer = pDoc->m_strHostName;
	tc.InsertItem( m_strServer, hParenHost );
	tc.InsertItem( pDoc->m_strHostIP, hParenHost );
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -