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

📄 dlgsendmes.cpp

📁 Send SMS useing Com,it is simple
💻 CPP
字号:
// DlgSendMes.cpp : implementation file
//

#include "stdafx.h"
#include "AdoDataGrid.h"
#include "DlgSendMes.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
extern BOOL ReadReg(const char *subkey, char *itemname, BYTE *buf);
extern BOOL SaveReg(const char *subkey, char *itemname, BYTE *buf,DWORD type=REG_SZ);
extern BOOL DealRegInfo(char *subkey, char *itemname, char *buf);
/////////////////////////////////////////////////////////////////////////////
// CDlgSendMes dialog

char s_AllContext[500]={'\0'};
char Name[33]={'\0'};
char PassWord[65]={'\0'};
char Ip[51]={'\0'};
UINT Port=0;

const char filter[]="0123456789";

CDlgSendMes::CDlgSendMes(CWnd* pParent /*=NULL*/)
	: CDialog(CDlgSendMes::IDD, pParent)
{
	//{{AFX_DATA_INIT(CDlgSendMes)
	m_EditMes = _T("");
	m_ports = _T("");
	m_ip = _T("");
	m_name = _T("");
	m_password = _T("");
	//}}AFX_DATA_INIT
}


void CDlgSendMes::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CDlgSendMes)
	DDX_Control(pDX, IDC_EDIT_PORT, m_portctr);
	DDX_Control(pDX, IDCANCEL, m_Cancel);
	DDX_Control(pDX, IDC_DELETE, m_BDelete);
	DDX_Control(pDX, IDC_BUTTON_OUT, m_BOut);
	DDX_Control(pDX, IDC_BUTTON_IN, m_BIn);
	DDX_Control(pDX, IDC_EDIT_MES, m_EditContrl);
	DDX_Control(pDX, IDC_CHOOSE, m_Choose);
	DDX_Text(pDX, IDC_EDIT_MES, m_EditMes);
	DDV_MaxChars(pDX, m_EditMes, 499);
	DDX_Text(pDX, IDC_EDIT_PORT, m_ports);
	DDV_MaxChars(pDX, m_ports, 8);
	DDX_Text(pDX, IDC_EDIT_IP, m_ip);
	DDV_MaxChars(pDX, m_ip, 50);
	DDX_Text(pDX, IDC_EDIT_USERNAME, m_name);
	DDV_MaxChars(pDX, m_name, 32);
	DDX_Text(pDX, IDC_EDIT_PASSWORD, m_password);
	DDV_MaxChars(pDX, m_password, 64);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CDlgSendMes, CDialog)
	//{{AFX_MSG_MAP(CDlgSendMes)
	ON_LBN_SELCHANGE(IDC_CHOOSE, OnSelchangeChoose)
	ON_LBN_DBLCLK(IDC_CHOOSE, OnDblclkChoose)
	ON_EN_CHANGE(IDC_EDIT_MES, OnChangeEditMes)
	ON_BN_CLICKED(IDC_BUTTON_OUT, OnButtonOut)
	ON_BN_CLICKED(IDC_BUTTON_IN, OnButtonIn)
	ON_BN_CLICKED(IDC_DELETE, OnDelete)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CDlgSendMes message handlers

void CDlgSendMes::OnSelchangeChoose() 
{
	// TODO: Add your control notification handler code here
	int index;
	index=m_Choose.GetCurSel();
	if(index==LB_ERR )
		return;
	if(m_Choose.GetText(index,s_ListContext)==LB_ERR)
		return;
	m_BOut.EnableWindow(TRUE);
	m_BDelete.EnableWindow(TRUE);
}

void CDlgSendMes::OnDblclkChoose() 
{
	// TODO: Add your control notification handler code here
	OnButtonOut();
}

void CDlgSendMes::OnChangeEditMes() 
{
	// TODO: If this is a RICHEDIT control, the control will not
	// send this notification unless you override the CDialog::OnInitDialog()
	// function and call CRichEditCtrl().SetEventMask()
	// with the ENM_CHANGE flag ORed into the mask.
	
	// TODO: Add your control notification handler code here
	m_BIn.EnableWindow(TRUE);
}

void CDlgSendMes::OnButtonOut() 
{
	// TODO: Add your control notification handler code here
	UpdateData(TRUE);
	m_EditMes.Format("%s",s_ListContext);
	UpdateData(FALSE);
}

void CDlgSendMes::OnButtonIn() 
{
	// TODO: Add your control notification handler code here
	UpdateData(TRUE);
	if(m_EditMes.GetLength()<1)
		return;
	m_Choose.AddString(m_EditMes);
	UpdateData(FALSE);
	try
	{
		f_MesFile.Open(pFileName,
			CFile::modeNoTruncate|CFile::modeCreate|CFile::modeReadWrite|CFile::typeText );
		f_MesFile.SeekToEnd( );
		f_MesFile.WriteString(m_EditMes);
		f_MesFile.WriteString("\n");
		f_MesFile.Close();
		
	}
	catch(CFileException e )
	{
		AfxMessageBox( "File could not be opened ");
	}
}

void CDlgSendMes::OnDelete() 
{
	// TODO: Add your control notification handler code here
	int index,count;
	index=m_Choose.GetCurSel();
	if(index==LB_ERR )
		return;
	count=m_Choose.DeleteString(index);
	if(count==LB_ERR)
		return;
	UpdateData(FALSE);
	try
	{
		f_MesFile.Open(pFileName,
			           CFile::modeCreate|CFile::modeReadWrite|CFile::typeText );
		for(int i=count;i>0;i--)
		{
			if(m_Choose.GetText(i-1,s_ListContext)==LB_ERR)
				return;
			f_MesFile.WriteString(s_ListContext);
			f_MesFile.WriteString("\n");
		}
		f_MesFile.Close();
	}
	catch(CFileException e )
	{
		AfxMessageBox( "File could not be opened ");
	}
}

BOOL CDlgSendMes::OnInitDialog() 
{
	CDialog::OnInitDialog();
	s_ListContext[0]='\0';
	CString  temp;
	char buf[51]={'\0'};
	char subkey[20] = "software\\GSL_XCSC";
	const char subkeyo[20] = "software\\GSL_XCSC";
	const char subkeyt[20] = "software\\GSL_XCSC";
	char messagefile[50]="";

	if(ReadReg(subkeyo,"serverip",(BYTE *)buf))
	{
		m_ip.Format("%s",buf);
	}
	else
		m_ip.Format("%s","sms.pdainfo.com.cn");
	if(ReadReg(subkeyt,"serverport",(BYTE *)buf))
	{
		if(strlen(buf)<9 && strlen(buf)>0 &&  !(strspn(buf,filter)<strlen(buf)) )
		{
			m_ports.Format("%s",buf);
		}
		else
			m_ports.Format("%s","13083");
	}
	else
		m_ports.Format("%s","13083");
	if(DealRegInfo(subkey,"messagefile",messagefile))
	{
		pFileName.Format("%s",messagefile);
	}
	else
	{
		pFileName.Format("%s",".\\messagefile.txt");
	}
	UpdateData(FALSE);

	try
	{
		f_MesFile.Open(pFileName,
			CFile::modeNoTruncate|CFile::modeCreate|CFile::modeReadWrite|CFile::typeText );
		while(f_MesFile.ReadString(temp)!=FALSE)
		{
			m_Choose.AddString(temp);
		}
		f_MesFile.Close();
	}
	catch(CFileException e )
	{
		AfxMessageBox( "File could not be opened ");
	}
	// TODO: Add extra initialization here
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

void CDlgSendMes::OnOK() 
{
	// TODO: Add extra validation here
	const char subkey[20] = "software\\GSL_XCSC";
	char buf[50] = {'\0'};
	UpdateData(TRUE);
	strcpy(s_AllContext,m_EditMes);
	if(strlen(s_AllContext)==0)
	{
		MessageBox("发送的内容不能为空!\n请输入发送内容!","发送信息",MB_ICONWARNING);
		return;
	}

	if( m_name.IsEmpty() || m_password.IsEmpty() )
	{
		MessageBox("用户名、密码为空!\n请输入用户名、密码!","发送信息",MB_ICONWARNING);
		return;
	}

	if(!m_ip.IsEmpty())
	{
		strcpy(buf,m_ip);
		SaveReg(subkey,"serverip",(BYTE *)buf);
	}
	else
	{
		MessageBox("服务器IP为空!\n请输入服务器IP!","发送信息",MB_ICONWARNING);
		return;
	}

	if(!m_ports.IsEmpty())
	{
		if( strspn(m_ports,filter)<(size_t)m_ports.GetLength() )
		{
			MessageBox("错误的服务器端口!\n请输入正确的服务器端口!","发送信息",MB_ICONWARNING);
			return;
		}
		strcpy(buf,m_ports);
		SaveReg(subkey,"serverport",(BYTE *)buf);
	}
	else
	{
		MessageBox("服务器端口为空!\n请输入服务器端口!","发送信息",MB_ICONWARNING);
		return;
	}

	strcpy(Name,m_name);
	strcpy(PassWord,m_password);
	strcpy(Ip,m_ip);
	Port=atoi(m_ports);

	CDialog::OnOK();
}

⌨️ 快捷键说明

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