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

📄 easynetsenddlg.cpp

📁 net send 消息发送工具
💻 CPP
字号:
// EasyNetSendDlg.cpp : implementation file
//

#include "stdafx.h"
#include "EasyNetSend.h"
#include "EasyNetSendDlg.h"
#include "Animate.h"
#include "lm.h"
#include "GroupDlg.h"

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

/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About

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()

/////////////////////////////////////////////////////////////////////////////
// CEasyNetSendDlg dialog

CEasyNetSendDlg::CEasyNetSendDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CEasyNetSendDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CEasyNetSendDlg)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	m_hIcon = AfxGetApp()->LoadIcon(IDI_BIRD1);
	m_iCurGroupItem = -1;
	strcpy(m_szCfgFileName,".\\ENS.ini");
}

void CEasyNetSendDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CEasyNetSendDlg)
	DDX_Control(pDX, IDC_B_GROUP, m_BGroup);
	DDX_Control(pDX, IDC_L_GROUP, m_LGroup);
	DDX_Control(pDX, IDC_E_FROM, m_EFrom);
	DDX_Control(pDX, IDC_ECOUNT, m_ECount);
	DDX_Control(pDX, IDC_E_RECEIVER, m_EReceiver);
	DDX_Control(pDX, IDC_E_MSG, m_EMsg);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CEasyNetSendDlg, CDialog)
	//{{AFX_MSG_MAP(CEasyNetSendDlg)
	ON_WM_SYSCOMMAND()
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_BN_CLICKED(IDC_B_GROUP, OnBGroup)
	ON_NOTIFY(NM_RCLICK, IDC_L_GROUP, OnRclickLGroup)
	ON_NOTIFY(NM_CLICK, IDC_L_GROUP, OnClickLGroup)
	//}}AFX_MSG_MAP
	ON_COMMAND(ID_M_ADD_GROUP,OnAddGroup)
	ON_COMMAND(ID_M_EDIT_GROUP,OnEditGroup)
	ON_COMMAND(ID_M_DEL_GROUP,OnDelGroup)
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CEasyNetSendDlg message handlers

BOOL CEasyNetSendDlg::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
	DWORD styles = LVS_EX_FULLROWSELECT | LVS_EX_HEADERDRAGDROP|LVS_EX_GRIDLINES ;
	ListView_SetExtendedListViewStyleEx(m_LGroup.m_hWnd, styles, styles );

	m_LGroup.InsertColumn(0,"Name",LVCFMT_LEFT,70);
	m_LGroup.InsertColumn(1,"Member",LVCFMT_LEFT,124);

	m_ECount.SetWindowText("1");

	unsigned long Len=128;
	::GetComputerName(m_szComputerName,&Len);
	char szFrom[128];
	GetPrivateProfileString("GENERAL","SENDER","",szFrom,128,GetCfgFileName());
	if(szFrom[0]==0)
	{
		strcpy(szFrom,m_szComputerName);
	}
	m_EFrom.SetWindowText(szFrom);

	MultiByteToWideChar(CP_ACP,0,m_szComputerName,strlen(m_szComputerName)+1,
		m_wComputerName,sizeof(m_szComputerName)/sizeof(m_wComputerName[0]));

	m_EMsg.SetLimitText(1024);
	
	m_bShowGroupFlag = 	GetPrivateProfileInt("GENERAL","SHOWGROUPLIST",1,GetCfgFileName());

	//调整窗口尺寸
	CRect rect;
	GetWindowRect(&rect);
	m_OrgRect = rect;
	if(!m_bShowGroupFlag)
	{
		m_LGroup.ShowWindow(SW_HIDE);
		rect.DeflateRect(0,0,230,0);
		MoveWindow(&rect,TRUE);
	}

	//保证配置文件存在
	WritePrivateProfileString("GENERAL","BINGO","1",GetCfgFileName());

	m_bShowGroupFlag = 	GetPrivateProfileInt("GENERAL","SHOWGROUPLIST",1,GetCfgFileName());

	FreshListByCfg();

//////////////////加签名档//////////////////////////////////////////////
/*	SYSTEMTIME Time;
	GetLocalTime(&Time);
	CString strTime;
	strTime.Format("%d-%02d-%02d", Time.wYear, Time.wMonth, Time.wDay);

	CString str="\r\n\r\n\r\n>>>                        _\r\n";
			str+=">>>                       (  \">      宝信公司研究开发部\r\n";
		    str+=">>>                        )(          纪娣芳\r\n";
			str+=">>>                       // )        jidifang@163.com\r\n";
			str+=">>>                    --//\"\"--------";
			str+=strTime;
			str+="-----------------\r\n";
			str+=">>>                    -/-------------------------------------------\r\n";
	m_EMsg.SetWindowText(str);
	m_EMsg.PostMessage(WM_LBUTTONDOWN,0,0);
	m_EMsg.PostMessage(WM_LBUTTONUP,0,0);
*/
/////////////////////////////////////////////////////////////////////
	return TRUE;
}

void CEasyNetSendDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
	if ((nID & 0xFFF0) == IDM_ABOUTBOX)
	{
		CAboutDlg dlgAbout;
		dlgAbout.DoModal();
	}
	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 CEasyNetSendDlg::OnPaint() 
{
	int cxIcon = GetSystemMetrics(SM_CXICON);
	int cyIcon = GetSystemMetrics(SM_CYICON);

	if (IsIconic())
	{
		CPaintDC dc(this); // device context for painting

		SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);

		// Center icon in client rectangle

		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
	{
	//	CDC* pDC=GetWindowDC();
	//	DrawIconEx(pDC->m_hDC,a,0,m_hIcon,16,16,0,NULL,DI_NORMAL);
		CDialog::OnPaint();
	}
}

// The system calls this to obtain the cursor to display while the user drags
//  the minimized window.
HCURSOR CEasyNetSendDlg::OnQueryDragIcon()
{
	return (HCURSOR) m_hIcon;
}

void CEasyNetSendDlg::OnOK()
{
	// TODO: Add extra validation here
	CString strMsg;
	CString strReceiver;
	CString strCount;

	m_ECount.GetWindowText(strCount);
	strCount.TrimLeft();
	strCount.TrimRight();
	int iCount=atoi(strCount);
	if(iCount==0)
	{
		AfxMessageBox("输入的发送次数非法");
	}

	char szReceiver[1024];
	char szSubBuff[1024];
	char * pSub;

	m_EMsg.GetWindowText(strMsg);
	if(strMsg.GetLength()==0)
	{
		AfxMessageBox("消息内容不能为空");
		return;
	}
	m_EReceiver.GetWindowText(szReceiver,1023);

	TrimLeftSZ(szReceiver);
	//右截空格
	CString strTmp;
	strTmp=szReceiver;
	strTmp.TrimRight();
	strcpy(szReceiver,strTmp);
	
	if(strlen(szReceiver)==0)
	{
		AfxMessageBox("消息接受人不能为空");
	}

	char * p1=NULL;
	char * p2=NULL;
	//分解接收人字串,向每一个接收者发送信息
	while(1)
	{
		TrimLeftSZ(szReceiver);
		pSub=CutSubStr(szReceiver,szSubBuff,' ');

		strReceiver=szSubBuff;
		SendMsg(strReceiver,strMsg,iCount);
		if(!pSub)
		{
			break;
		}
	}
}

void CEasyNetSendDlg::SendMsg(CString &strReceiver,CString &strMsg,int iCount)
{
	CString strCommand;
	CString strErrorMsg;

	strCommand="net send";
	strCommand+=" ";

	strCommand+=strReceiver;
	strCommand+=" ";

	strCommand+=strMsg;

	//发送者
	char szFrom[128];
	m_EFrom.GetWindowText(szFrom,128);
	WritePrivateProfileString("GENERAL","SENDER",szFrom,GetCfgFileName());
	wchar_t wFrom[128];
	//转UNICODE码
	MultiByteToWideChar(CP_ACP,0,szFrom,strlen(szFrom)+1,
		wFrom,sizeof(szFrom)/sizeof(wFrom[0]));

	//接收者
	char szTo[128];
	strcpy(szTo,strReceiver);
	wchar_t wTo[128];
	//转UNICODE码
	MultiByteToWideChar(CP_ACP,0,szTo,strlen(szTo)+1,
		wTo,sizeof(szTo)/sizeof(wTo[0]));

	//内容
	char szContent[1024];
	strcpy(szContent,strMsg);
	wchar_t wContent[1024];
	//转UNICODE码
	MultiByteToWideChar(CP_ACP,0,szContent,strlen(szContent)+1,
		wContent,sizeof(szContent)/sizeof(wContent[0]));

	NET_API_STATUS res;
	for(int i=0;i<iCount;i++)
	{
		res=NetMessageBufferSend(m_wComputerName,wTo,wFrom,(LPBYTE)wContent,strlen(szContent)*2);
		if(res!=NERR_Success)
		{
			if(res==NERR_NameNotFound)
			{
				strErrorMsg.Format("找不到接收者 %s ,发送消息失败",strReceiver);
				AfxMessageBox(strErrorMsg);
			}
			else if(res==NERR_NetworkError)
			{
				strErrorMsg.Format("网络异常,发送消息到 %s 失败",strReceiver);
				AfxMessageBox(strErrorMsg);
			}
			else if(res==ERROR_INVALID_PARAMETER)
			{
				AfxMessageBox("参数错误,发送消息失败");
				return;
			}
			else if(res==ERROR_ACCESS_DENIED)
			{
				AfxMessageBox("权限不足,发送消息失败");
				return;
			}
			else if(res==ERROR_NOT_SUPPORTED)
			{
				AfxMessageBox("这个功能不被支持,发送消息失败");
				return;
			}
			else
			{
				AfxMessageBox("发送消息失败");
				return;
			}
		}
	}

	SetWindowText("EasyNetSend - 发送消息成功!");
}

void CEasyNetSendDlg::OnAddGroup()
{
	CGroupDlg dlg;
	dlg.DoModal();
	int iCount = m_LGroup.GetItemCount();
	dlg.m_strMember.Replace("\r"," ");
	dlg.m_strMember.Replace("\n"," ");
	m_LGroup.InsertItem(iCount,dlg.m_strName);
	m_LGroup.SetItemText(iCount,1,dlg.m_strMember);

	FreshCfgByList();
}

void CEasyNetSendDlg::OnEditGroup()
{
	if(m_iCurGroupItem==-1)
	{
		return;
	}

	CGroupDlg dlg;
	CString str;
	dlg.m_strName = m_LGroup.GetItemText(m_iCurGroupItem,0);
	dlg.m_strMember = m_LGroup.GetItemText(m_iCurGroupItem,1);
	dlg.DoModal();

	dlg.m_strMember.Replace("\r"," ");
	dlg.m_strMember.Replace("\n"," ");
	m_LGroup.SetItemText(m_iCurGroupItem,0,dlg.m_strName);
	m_LGroup.SetItemText(m_iCurGroupItem,1,dlg.m_strMember);
}

void CEasyNetSendDlg::OnDelGroup()
{
	if(m_iCurGroupItem==-1)
	{
		return;
	}

	m_LGroup.DeleteItem(m_iCurGroupItem);
	FreshCfgByList();
}

char * CEasyNetSendDlg::GetCfgFileName()
{
	return m_szCfgFileName;
}

char * CEasyNetSendDlg::TrimLeftSZ(char * pBuff)
{
	CString strTmp;
	strTmp=pBuff;
	strTmp.TrimLeft();
	strcpy(pBuff,strTmp);
	return pBuff;
}

char * CEasyNetSendDlg::CutSubStr(char * pSource,char * pSubBuff,char Division)
{
	char pTmp[1024];
	char * pFirstPos=strchr(pSource,Division);
	if(!pFirstPos)
	{
		strcpy(pSubBuff,pSource);
		return NULL;
	}
	else
	{
		strcpy(pTmp,pSource);
		pFirstPos[0]=0;
		strcpy(pSubBuff,pSource);
		strcpy(pSource,pTmp);
	}

	strcpy(pTmp,pFirstPos+1);
	strcpy(pSource,pTmp);

	return pSubBuff;
}

void CEasyNetSendDlg::FreshCfgByList()
{
	int iCount = m_LGroup.GetItemCount();
	char szTmp[128];
	sprintf(szTmp,"%d",iCount);
	CString strName;
	CString strMember;
	CString strGroupIndex;
	WritePrivateProfileString("GENERAL","GROUPCOUNT",szTmp,GetCfgFileName());
	for(int i=0;i<iCount;i++)
	{
		strGroupIndex.Format("GROUP%d",i);
		strName = m_LGroup.GetItemText(i,0);
		strMember = m_LGroup.GetItemText(i,1);
		::WritePrivateProfileString(strGroupIndex,"NAME",strName,GetCfgFileName());
		::WritePrivateProfileString(strGroupIndex,"MEMBER",strMember,GetCfgFileName());
	}
}

void CEasyNetSendDlg::FreshListByCfg()
{
	int iGroupCount =::GetPrivateProfileInt("GENERAL","GROUPCOUNT",0,GetCfgFileName());

	CString strGroupIndex;
	char szName[128];
	char szMember[128];
	for(int i=0;i<iGroupCount;i++)
	{
		strGroupIndex.Format("GROUP%d",i);
		GetPrivateProfileString(strGroupIndex,"NAME","",szName,128,GetCfgFileName());
		GetPrivateProfileString(strGroupIndex,"MEMBER","",szMember,128,GetCfgFileName());
		m_LGroup.InsertItem(i,szName);
		m_LGroup.SetItemText(i,1,szMember);
	}
}

void CEasyNetSendDlg::OnBGroup() 
{
	// TODO: Add your control notification handler code here
	CRect rect;
//	WritePrivateProfileString("GENERAL","BINGO","1",GetCfgFileName());
	if(!m_bShowGroupFlag)
	{
		GetWindowRect(&rect);
		rect.right=rect.left+m_OrgRect.Width();
		rect.bottom=rect.top+m_OrgRect.Height();
		m_LGroup.ShowWindow(SW_SHOW);
		MoveWindow(rect,TRUE);
		m_bShowGroupFlag=TRUE;
		m_BGroup.SetWindowText("Group<<");
		WritePrivateProfileString("GENERAL","SHOWGROUPLIST","1",GetCfgFileName());
	}
	else
	{
		m_LGroup.ShowWindow(SW_HIDE);
		GetWindowRect(&rect);
		rect.DeflateRect(0,0,230,0);
		MoveWindow(&rect,TRUE);
		m_bShowGroupFlag=FALSE;
		m_BGroup.SetWindowText("Group>>");
		WritePrivateProfileString("GENERAL","SHOWGROUPLIST","0",GetCfgFileName());
	}
}

void CEasyNetSendDlg::OnRclickLGroup(NMHDR* pNMHDR, LRESULT* pResult) 
{
	// TODO: Add your control notification handler code here
	CMenu DynaMenu;
	DynaMenu.CreatePopupMenu();

	DynaMenu.AppendMenu(MF_STRING,ID_M_ADD_GROUP, "添加");

	POSITION pt = m_LGroup.GetFirstSelectedItemPosition();

	if (pt != NULL)
	{
		DynaMenu.AppendMenu(MF_STRING,ID_M_EDIT_GROUP, "编辑");
		DynaMenu.AppendMenu(MF_STRING,ID_M_DEL_GROUP, "删除");
		m_iCurGroupItem = m_LGroup.GetNextSelectedItem(pt);
	}
	else
	{
		m_iCurGroupItem = -1;
	}

	CPoint point;
	::GetCursorPos(&point);
	DynaMenu.TrackPopupMenu(TPM_RIGHTBUTTON, point.x, point.y, this);

	*pResult = 0;
}

void CEasyNetSendDlg::OnClickLGroup(NMHDR* pNMHDR, LRESULT* pResult) 
{
	// TODO: Add your control notification handler code here
	POSITION pt = m_LGroup.GetFirstSelectedItemPosition();

	if (pt != NULL)
	{
		m_iCurGroupItem = m_LGroup.GetNextSelectedItem(pt);
	}

	CString str = m_LGroup.GetItemText(m_iCurGroupItem,1);
	m_EReceiver.SetWindowText(str);

	*pResult = 0;
}

⌨️ 快捷键说明

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