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

📄 infoview.cpp

📁 简单的远程控制工具,分为服务器与客户斋,让你了解socket编程的知识.
💻 CPP
字号:
// InfoView.cpp : implementation file
//

#include "stdafx.h"
#include "Ctrl_Clnt9.h"
#include "MainFrm.h"

#include "InfoView.h"

#include "CmdView.h"

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

/////////////////////////////////////////////////////////////////////////////
// CInfoView

IMPLEMENT_DYNCREATE(CInfoView, CCJListView)

CInfoView::CInfoView()
{
	m_nFormat = INFO_FORMAT;
}

CInfoView::~CInfoView()
{
}


BEGIN_MESSAGE_MAP(CInfoView, CCJListView)
	//{{AFX_MSG_MAP(CInfoView)
	ON_WM_LBUTTONDOWN()
	ON_COMMAND(IDM_INFO_DELALL, OnInfoDelall)
	ON_COMMAND(IDM_INFO_DELITEM, OnInfoDelitem)
	ON_WM_CONTEXTMENU()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CInfoView drawing

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

BOOL CInfoView::PreCreateWindow(CREATESTRUCT& cs) 
{
	// TODO: Add your specialized code here and/or call the base class
	cs.style |= LVS_REPORT;
	
	return CCJListView::PreCreateWindow(cs);
}
/////////////////////////////////////////////////////////////////////////////
// CInfoView diagnostics

#ifdef _DEBUG
void CInfoView::AssertValid() const
{
	CCJListView::AssertValid();
}

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

/////////////////////////////////////////////////////////////////////////////
// CInfoView message handlers

void CInfoView::OnInitialUpdate() 
{
	CCJListView::OnInitialUpdate();
	
	// TODO: Add your specialized code here and/or call the base class
	m_pListCtrl = &GetListCtrl();

	// Create the large and small image lists
/*	m_ImageList.Create (16, 16, true, 2, 1);
	m_ImageListNormal.Create (32, 32, true, 2, 1);
	HICON hIcon;
	
	for (int i =0; i < 2; ++i) {
		hIcon= AfxGetApp()->LoadIcon (nImages[i]);
		m_ImageList.Add (hIcon);
		m_ImageListNormal.Add (hIcon);
	}

	m_pListCtrl->SetImageList (&m_ImageList, LVSIL_SMALL);
	m_pListCtrl->SetImageList (&m_ImageListNormal, LVSIL_NORMAL);
	m_pListCtrl->SetTextColor (RGB(0,0,255));
*/
	m_Font.CreatePointFont (85, _T("Times New Roman"));
    m_pListCtrl->SetFont (&m_Font);
	
	m_pListCtrl->SetExtendedStyle(LVS_EX_FULLROWSELECT | 
				 LVS_EX_ONECLICKACTIVATE | 
				 LVS_EX_UNDERLINEHOT | 
				 LVS_EX_GRIDLINES);
	
	m_headerCtrl.m_bBoldFont = TRUE;	

	Insert_Column (0, 500, "Result From Remote Computer");
/*	Insert_Column (1, 150, "The Second");
	Insert_Column (2, 200, "The Third");

	Insert_Item (0,0,"0 The Item0");
	Insert_Item (0,1,"1 The Item1");
	Insert_Item (0,2,"2 The Item2");
	Insert_Item (1,0,"3 The Item3");
	Insert_Item (1,1,"4 The Item4");
	Insert_Item (1,2,"5 The Item5");
*/
  
}

void CInfoView::Insert_Column (int nCols, int nWidth, CString strText)
{
	if (nCols == -1)
	{
		m_pListCtrl->DeleteAllItems ();
		while (m_pListCtrl->DeleteColumn (0) );
		return;
	}

	LV_COLUMN lvCol;
	lvCol.mask = LVCF_FMT|LVCF_WIDTH|LVCF_TEXT|LVCF_SUBITEM;
    lvCol.cx = nWidth;
	lvCol.fmt = LVCFMT_LEFT;

	lvCol.iSubItem = nCols;
	lvCol.pszText = (char*)(LPCTSTR)strText;
	int nRC = m_pListCtrl->InsertColumn(nCols, &lvCol);
}

void CInfoView::Insert_Item (int nRows, int nSubItem, CString strText)
{
	if (nRows == -1)
		m_pListCtrl->DeleteAllItems ();

	nRows = m_pListCtrl->GetItemCount ();

	LV_ITEM		lvi;
	lvi.mask = LVIF_TEXT;
	lvi.iSubItem = 0;

	lvi.iItem = nRows;
	lvi.pszText = (LPSTR)(LPCTSTR)strText;

	if (nSubItem == 0)
		m_pListCtrl->InsertItem(&lvi);
	else
		m_pListCtrl->SetItemText(nRows-1, nSubItem, (LPSTR)(LPCTSTR)strText);
}

void CInfoView::Display_Message (LPCTSTR lpText)
{
	CString strHead;
	CString strMsg = lpText;
	int nHead = strMsg.Find (":",0);
	if (nHead > 0)
		strHead = strMsg.Left (nHead);

	if (strHead == "FILE" && m_nFormat != FILE_FORMAT)
	{
		CRect rc;
		GetClientRect (&rc);
		Insert_Column (-1,0,"");
		Insert_Column (0,(int)(rc.Width()*.35),"Name");
		Insert_Column (1,(int)(rc.Width()*.15),"Size");
		Insert_Column (2,(int)(rc.Width()*.2),"Date Time");
		Insert_Column (3,(int)(rc.Width()*.15),"Attribute");
		Insert_Column (4,(int)(rc.Width()*.15),"Others");

		m_nFormat = FILE_FORMAT;
	}
	else if (strHead == "REG" && m_nFormat != REG_FORMAT)
	{
		CRect rc;
		GetClientRect (&rc);
		Insert_Column (-1,0,"");
		Insert_Column (0,(int)(rc.Width()*.45),"Name");
		Insert_Column (1,(int)(rc.Width()*.2),"Type");
		Insert_Column (2,(int)(rc.Width()*.35),"Value");

		m_nFormat = REG_FORMAT;
	}
	else if ((strHead != "REG" && strHead != "FILE") && 
		 m_nFormat != INFO_FORMAT)
	{
		CRect rc;
		GetClientRect (&rc);
		Insert_Column (-1,0,"");
		Insert_Column (0,(int)(rc.Width()*.98),"Result from remote");

		m_nFormat = INFO_FORMAT;
	}

	CMainFrame *pWnd = (CMainFrame *) AfxGetApp ()->m_pMainWnd;
	CCmdView* pCmdView = (CCmdView*) pWnd->m_wndWorkspace.GetActiveView();
	if (pCmdView != NULL)
		pWnd->m_pEditText->SetWindowText (pCmdView->m_strCboParam1);
	if (strHead == "FILE")
	{
		CString strTxt;
		int	nSplit = 0;

		strMsg = strMsg.Right (strMsg.GetLength ()-nHead-2);
		for (int i = 0; i < 5; i++)
		{
			nSplit = strMsg.Find ("|",0);
			if (nSplit <= 0)
				strTxt = strMsg;
			else
				strTxt = strMsg.Left (nSplit);
			while (strTxt[0] == ' ') 
			{
				strTxt = strTxt.Right (strTxt.GetLength ()-1);
				if (strTxt.GetLength () <= 0)
					break;
			}
			Insert_Item (1,i,strTxt);

			if (nSplit < 0)
				break;
			nSplit ++;
			strMsg = strMsg.Right (strMsg.GetLength ()-nSplit);
		}
		return;
	}

	if (strHead == "REG")
	{
		CString strTxt;
		int	nSplit = 0;

		strMsg = strMsg.Right (strMsg.GetLength ()-nHead-2);
		for (int i = 0; i < 3; i++)
		{
			nSplit = strMsg.Find ("|",0);
			if (nSplit <= 0)
				strTxt = strMsg;
			else
				strTxt = strMsg.Left (nSplit);
			while (strTxt[0] == ' ') 
			{
				strTxt = strTxt.Right (strTxt.GetLength ()-1);
				if (strTxt.GetLength () <= 0)
					break;
			}
			Insert_Item (1,i,strTxt);

			if (nSplit < 0)
				break;
			nSplit ++;
			strMsg = strMsg.Right (strMsg.GetLength ()-nSplit);
		}
		return;		
	}
	strMsg = strMsg.Right (strMsg.GetLength ()-nHead-2);
	Insert_Item (1,0,strMsg);
}

void CInfoView::OnLButtonDown(UINT nFlags, CPoint point) 
{
	// TODO: Add your message handler code here and/or call default
	char	szText[200];
	CString	strTxt;

	m_nIndex = m_pListCtrl->HitTest(point);
	if (m_nIndex >= 0)
	{
		CMainFrame *pWnd = (CMainFrame *) AfxGetApp ()->m_pMainWnd;
		CCmdView* pCmdView = (CCmdView*) pWnd->m_wndWorkspace.GetActiveView();
		pWnd->m_pEditText->GetWindowText (szText,sizeof (szText));
		strTxt = szText;
		m_pListCtrl->GetItemText (m_nIndex, 0, szText,sizeof (szText));
		if (strlen (szText) > 0)
		{
			strTxt = strTxt + szText;
			if (pCmdView != NULL)
			{
				pCmdView->m_strCboParam1 = strTxt;
				pCmdView->UpdateData (FALSE);
			}
		}
	}

	CCJListView::OnLButtonDown(nFlags, point);
}

void CInfoView::OnInfoDelall() 
{
	// TODO: Add your command handler code here
	if (m_pListCtrl != NULL)
		m_pListCtrl->DeleteAllItems ();
}

void CInfoView::OnInfoDelitem() 
{
	// TODO: Add your command handler code here
	if (m_pListCtrl != NULL && m_nIndex >= 0)
		m_pListCtrl->DeleteItem (m_nIndex);
	
}

void CInfoView::OnContextMenu(CWnd* pWnd, CPoint point) 
{
	// TODO: Add your message handler code here
/*	if (m_menuID == -1 )
	{ 
		// Gonzalo Pereyra
		DefWindowProc(WM_CONTEXTMENU, LONG(m_hWnd), 
			MAKELPARAM(point.x,point.y)); 

		TRACE0(_T("Warning: No control bar menu defined.\n")); 
		return; 
	}
*/
	if (point.x == -1 && point.y == -1)
	{
		//keystroke invocation
		CRect rect;
		GetClientRect(rect);
		ClientToScreen(rect);
		
		point = rect.TopLeft();
		point.Offset(5, 5);
	}
	
	CMenu menu;
	VERIFY(menu.LoadMenu(IDR_MENU_INFO));
	
	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);	
}

⌨️ 快捷键说明

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