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

📄 peerregeditlistview.cpp

📁 一个不错的远程控制软件源码
💻 CPP
📖 第 1 页 / 共 2 页
字号:
// PeerRegeditListView.cpp : implementation file
//

#include "stdafx.h"
#include "PeerYouC.h"
#include "PeerRegeditListView.h"
#include "PeerRegeditTreeView.h"
#include "mainfrm.h"
#include "peersocket.h"
#include "regeditvaluetextdlg.h"
#include "regeditvalueworddlg.h"
#include "regeditvaluebinbdlg.h"


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

/////////////////////////////////////////////////////////////////////////////
// CPeerRegeditListView

IMPLEMENT_DYNCREATE(CPeerRegeditListView, CListView)

CPeerRegeditListView::CPeerRegeditListView()
{
}

CPeerRegeditListView::~CPeerRegeditListView()
{
}


BEGIN_MESSAGE_MAP(CPeerRegeditListView, CListView)
	//{{AFX_MSG_MAP(CPeerRegeditListView)
	ON_WM_CREATE()
	ON_NOTIFY_REFLECT(NM_RCLICK, OnRclick)
	ON_COMMAND(ID_REGEDIT_VALUE_ADD_BINB, OnRegeditValueAddBinb)
	ON_COMMAND(ID_REGEDIT_VALUE_ADD_TEXT, OnRegeditValueAddText)
	ON_COMMAND(ID_REGEDIT_VALUE_ADD_WORD, OnRegeditValueAddWord)
	ON_COMMAND(ID_REGEDIT_VALUE_DEL, OnRegeditValueDel)
	ON_COMMAND(ID_REGEDIT_VALUE_EDIT, OnRegeditValueEdit)
	ON_NOTIFY_REFLECT(NM_DBLCLK, OnDblclk)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CPeerRegeditListView drawing

void CPeerRegeditListView::OnDraw(CDC* pDC)
{
	CDocument* pDoc = GetDocument();
	// TODO: add draw code here
}

/////////////////////////////////////////////////////////////////////////////
// CPeerRegeditListView diagnostics

#ifdef _DEBUG
void CPeerRegeditListView::AssertValid() const
{
	CListView::AssertValid();
}

void CPeerRegeditListView::Dump(CDumpContext& dc) const
{
	CListView::Dump(dc);
}
#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CPeerRegeditListView message handlers

int CPeerRegeditListView::OnCreate(LPCREATESTRUCT lpCreateStruct) 
{
	if (CListView::OnCreate(lpCreateStruct) == -1)
		return -1;

	// TODO: Add your specialized creation code here
	CListCtrl &listCtrl=this->GetListCtrl();
	listCtrl.ModifyStyle(0,LVS_REPORT|LVS_SINGLESEL);
	if(!m_imagelist.Create( 16,16,ILC_MASK,3,1))
		return -1;
	m_imagelist.Add(AfxGetApp()->LoadIcon(IDI_REGTEXT));
	m_imagelist.Add(AfxGetApp()->LoadIcon(IDI_REGBIN));	
	m_imagelist.Add(AfxGetApp()->LoadIcon(IDI_REGERROR));
	listCtrl.SetImageList(&m_imagelist,LVSIL_SMALL);
	//////////////////////////////////////////////////
	LVCOLUMN colinfo;
	memset(&colinfo,0,sizeof(colinfo));
	colinfo.mask=LVCF_TEXT|LVCF_WIDTH;
	colinfo.cx=100;
	colinfo.cchTextMax=255;
	colinfo.pszText="名称";
	colinfo.iSubItem=0;
	colinfo.iOrder=0;
	listCtrl.InsertColumn(0,&colinfo);
	colinfo.pszText="类型";
	colinfo.iSubItem=1;
	colinfo.iOrder=1;
	listCtrl.InsertColumn(1,&colinfo);
	colinfo.pszText="数据";
	colinfo.iSubItem=2;
	colinfo.iOrder=2;
	listCtrl.InsertColumn(2,&colinfo);
	return 0;
}

void CPeerRegeditListView::OnRclick(NMHDR* pNMHDR, LRESULT* pResult) 
{
	// TODO: Add your control notification handler code here
	*pResult = 0;
	///////////////////////

	CListCtrl& list=GetListCtrl();
	CPoint point;
	::GetCursorPos(&point);
	ScreenToClient(&point);
	UINT flag=LVHT_ONITEM ;
	CMenu menu;
	if(list.HitTest(point,&flag)==-1)
	{
		list.SetSelectionMark(-1);
		VERIFY(menu.LoadMenu(IDR_REGEDIT_LIST_ADD));
	}
	else
	{
		VERIFY(menu.LoadMenu(IDR_REGEDIT_LIST_EDITDEL));
	}
	ClientToScreen(&point);
	CMenu* pPopup = menu.GetSubMenu(0);
	ASSERT(pPopup != NULL);
	CWnd* pWndPopupOwner = this;
	while (pWndPopupOwner->GetStyle() & WS_CHILD)
		pWndPopupOwner = pWndPopupOwner->GetParent();
	pPopup->TrackPopupMenu(TPM_LEFTALIGN | TPM_RIGHTBUTTON, point.x, point.y,
							pWndPopupOwner);
	
}


void CPeerRegeditListView::OnDblclk(NMHDR* pNMHDR, LRESULT* pResult) 
{
	// TODO: Add your control notification handler code here
	CListCtrl& list=GetListCtrl();
	CPoint point;
	::GetCursorPos(&point);
	ScreenToClient(&point);
	UINT flag=LVHT_ONITEM ;
	if(list.HitTest(point,&flag)==-1)
		return;
	CPeerRegeditListView::OnRegeditValueEdit();
	*pResult = 0;
}

void CPeerRegeditListView::OnRegeditValueAddText() 
{
	// TODO: Add your command handler code here
//	CSplitterWnd* regsplitterwnd=(CSplitterWnd*)GetParent();
//	CPeerRegeditTreeView* treeview=(CPeerRegeditTreeView*)regsplitterwnd->GetPane(0,0);
//	CPeerRegeditListView* listview=(CPeerRegeditListView*)regsplitterwnd->GetPane(0,1);
//	CMainFrame* pMainFrm=(CMainFrame*)AfxGetApp()->GetMainWnd();
//	pMainFrm->m_pRegList=listview;
//	pMainFrm->m_pRegTree=treeview;
//	CTreeCtrl& tree=treeview->GetTreeCtrl();
//	CListCtrl& list=GetListCtrl();
//
//	CRegeditValueTextDlg dlg;
//	if(dlg.DoModal()==IDOK)
//	{
//		HTREEITEM treeselectitem;
//		if(!(treeselectitem=tree.GetSelectedItem())||treeselectitem==tree.GetRootItem())
//			return;
//		LVFINDINFO lfinfo;
//		lfinfo.flags=LVFI_STRING;
//		lfinfo.psz=dlg.m_name;
//		if(list.FindItem(&lfinfo)>-1)
//		{
//			MessageBox("已有此数值项名,请另选","窥视-客户端",MB_ICONSTOP|MB_OK);
//			return;
//		}
//		REGEDIT reg;
//		MakeRegInfo(tree,treeselectitem,reg);
//		strcpy(reg.value,dlg.m_name);
//		strcpy((char*)reg.data,dlg.m_data);
//		reg.datalen=dlg.m_data.GetLength()+1;
//		reg.type=REG_SZ;
//
//		SOCKET s;
//		DWORD ret;
//		
//		char mess[512];
//		strcpy(mess,"添加数值: \"");
//		strcat(mess,reg.key);
//		if(strlen(reg.sunkey)!=0)
//		{
//			strcat(mess,"\\");
//			strcat(mess,reg.sunkey);
//		}
//		strcat(mess,"\\");
//		strcat(mess,reg.value);
//		strcat(mess,"\"");
//		if(!PeerCreateSocket(&s,PEER_STREAM))
//		{
//			return;
//		}
//		WSAEVENT hevent=WSACreateEvent();
//		if(PeerConnectSocket(s,ADDRESS,7788))
//		{
//			COMMAND cmd;
//			memset(&cmd,0,sizeof(cmd));
//			cmd.CommandID=PEER_REGEDIT_SETVALUE;
//			if(!PeerSendDataS(s,(char*)&cmd,sizeof(cmd),&ret,hevent))
//			{
//				Message(mess,"失败");
//				goto MYERROR ;
//			}
//			if(!PeerSendDataS(s,(char*)&reg,sizeof(reg),&ret,hevent))
//			{
//				Message(mess,"失败");
//				goto MYERROR ;
//			}
//			else
//			{
//				COMMAND cmd;
//				if(!PeerRecvDataS(s,(char*)&cmd,sizeof(cmd),&ret,hevent)||ret!=sizeof(cmd))
//				{
//					Message(mess,"失败");
//					goto MYERROR ;
//				}
//				int itemcount=list.GetItemCount();
//				list.InsertItem(itemcount,dlg.m_name);
//				list.SetItem(itemcount,1,LVIF_TEXT,"REG_SZ",0,0,0,NULL);
//				list.SetItem(itemcount,2,LVIF_TEXT,dlg.m_data,0,0,0,NULL);
//			}
//		}
//
//		Message(mess,"成功");
//	MYERROR:
//		PeerCloseSocket(s);
//		WSACloseEvent(hevent);
//	}
	Common(0);
}

void CPeerRegeditListView::OnRegeditValueAddBinb() 
{
	// TODO: Add your command handler code here
	
}

void CPeerRegeditListView::OnRegeditValueAddWord() 
{
	// TODO: Add your command handler code here
	Common(1);
}

void CPeerRegeditListView::OnRegeditValueEdit() 
{
	// TODO: Add your command handler code here
	CSplitterWnd* regsplitterwnd=(CSplitterWnd*)GetParent();
	CPeerRegeditTreeView* treeview=(CPeerRegeditTreeView*)regsplitterwnd->GetPane(0,0);
	CPeerRegeditListView* listview=(CPeerRegeditListView*)regsplitterwnd->GetPane(0,1);
	CMainFrame* pMainFrm=(CMainFrame*)AfxGetApp()->GetMainWnd();
	pMainFrm->m_pRegList=listview;
	pMainFrm->m_pRegTree=treeview;
	CTreeCtrl& tree=treeview->GetTreeCtrl();
	CListCtrl& list=GetListCtrl();
	CString name,type,data;
	type=list.GetItemText(list.GetSelectionMark(),1);
	HTREEITEM treeselectitem;
	if(!(treeselectitem=tree.GetSelectedItem())||treeselectitem==tree.GetRootItem())
		return;
	REGEDIT reg;
	MakeRegInfo(tree,treeselectitem,reg);
	if(type=="REG_SZ"||type=="REG_MULTI_SZ"||type=="REG_EXPAND_SZ")
	{
		CRegeditValueTextDlg dlg;
		if(dlg.DoModal()==IDOK)
		{
			if(dlg.m_name=="(默认)")
				dlg.m_name="";
			strcpy(reg.value,dlg.m_name);
			strcpy((char*)reg.data,dlg.m_data);
			data=dlg.m_data;
			reg.datalen=dlg.m_data.GetLength()+1;
			if(type=="REG_SZ")
				reg.type=REG_SZ;
			if(type=="REG_MULTI_SZ")
				reg.type=REG_MULTI_SZ;
			if(type=="REG_EXPAND_SZ")
				reg.type=REG_EXPAND_SZ;
		}
		else
			return;
	}
	if(type=="REG_DWORD_BIG_ENDIAN"||type=="REG_DWORD")
	{
		CRegeditValueWORDdlg dlg;
		if(dlg.DoModal()==IDOK)
		{
			strcpy(reg.value,dlg.m_name);
			DWORD word;
			sscanf(dlg.m_data,"%u",&word);
			char showdata[100];
			sprintf(showdata,"0x%x(%u)",word,word);
			data=showdata;
			memcpy(&reg.data,&word,sizeof(DWORD));
			reg.datalen=sizeof(DWORD);
			if(type=="REG_DWORD_BIG_ENDIAN")
				reg.type=REG_DWORD_BIG_ENDIAN;
			if(type=="REG_DWORD")
				reg.type=REG_DWORD;
		}
		else
			return;
	}
	if(type=="REG_BINARY"||type=="REG_RESOURCE_LIST"||
		type=="REG_FULL_RESOURCE_DESCRIPTOR"||type=="REG_LINK")
	{
		CRegeditValueBinbDlg dlg;
		dlg.DoModal();

⌨️ 快捷键说明

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