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

📄 smssenddlg.cpp

📁 移动
💻 CPP
字号:
// SmsSendDlg.cpp : implementation file
//

#include "stdafx.h"
#include "SmsSend.h"
#include "SmsSendDlg.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_message(CAboutDlg)
	//}}AFX_message
	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_message_MAP(CAboutDlg)
		// No message handlers
	//}}AFX_message_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CSmsSendDlg dialog

CSmsSendDlg::CSmsSendDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CSmsSendDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CSmsSendDlg)
	ip = _T("");
	message = _T("");
	msisdn = _T("");
	port = 0;
	pwd = _T("");
	src = _T("");
	user = _T("");
	SockType = -1;
	m_curmsisdn = _T("");
	m_http = _T("");
	systemid = _T("");
	ylfPort = 0;
	ylfIP = _T("");
	bFlash = FALSE;
	m_msg_len = 0;
	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	ylfPort = 9002;
	ylfIP = "192.168.1.119";
	SockType=0;

	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);

	ip=	AfxGetApp()->GetProfileString("sms_send_test","ip",ip);
	port=AfxGetApp()->GetProfileInt("sms_send_test","port",port);
	user=AfxGetApp()->GetProfileString("sms_send_test","user",user);
	pwd=AfxGetApp()->GetProfileString("sms_send_test","pwd",pwd);
	src=AfxGetApp()->GetProfileString("sms_send_test","src",src);
	msisdn=AfxGetApp()->GetProfileString("sms_send_test","msisdn",msisdn);
	message=AfxGetApp()->GetProfileString("sms_send_test","message",message);

	ylfIP=	AfxGetApp()->GetProfileString("sms_send_test","ylfip",ylfIP);
	ylfPort=AfxGetApp()->GetProfileInt("sms_send_test","ylfport",ylfPort);
	SockType=AfxGetApp()->GetProfileInt("sms_send_test","SockType",SockType);
	
	systemid=	AfxGetApp()->GetProfileString("sms_send_test","systemid",systemid);

	CString str;
	for(int i=0;i<MAX_MSISDN;i++)
	{
		str.Format("msisdn%d",i);
		msisdns[i]=AfxGetApp()->GetProfileString("sms_send_test",str,"");
	}
	bSendAliveMsg=false;
}

void CSmsSendDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CSmsSendDlg)
	DDX_Control(pDX, IDC_EDIT_IP2, ylfIPc);
	DDX_Control(pDX, IDC_EDIT_PORT2, ylfPortc);
	DDX_Control(pDX, IDC_EDIT_SYSTEM_ID, systemidc);
	DDX_Control(pDX, IDC_EDIT_MSISDN, msisdnc);
	DDX_Control(pDX, IDC_MSISDN_LIST, msisdnList);
	DDX_Control(pDX, IDC_LIST1, listc);
	DDX_Text(pDX, IDC_EDIT_IP, ip);
	DDX_Text(pDX, IDC_EDIT_MESSAGE, message);
	DDX_Text(pDX, IDC_EDIT_MSISDN, msisdn);
	DDX_Text(pDX, IDC_EDIT_PORT, port);
	DDX_Text(pDX, IDC_EDIT_PWD, pwd);
	DDX_Text(pDX, IDC_EDIT_SRC, src);
	DDX_Text(pDX, IDC_EDIT_USER, user);
	DDX_CBIndex(pDX, IDC_COMBO1, SockType);
	DDX_LBString(pDX, IDC_MSISDN_LIST, m_curmsisdn);
	DDX_CBString(pDX, IDC_COMBO2, m_http);
	DDX_Text(pDX, IDC_EDIT_SYSTEM_ID, systemid);
	DDV_MaxChars(pDX, systemid, 10);
	DDX_Text(pDX, IDC_EDIT_PORT2, ylfPort);
	DDX_Text(pDX, IDC_EDIT_IP2, ylfIP);
	DDX_Check(pDX, IDC_CHECK_FLASH, bFlash);
	DDX_Text(pDX, IDC_MSG_LENG, m_msg_len);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CSmsSendDlg, CDialog)
	//{{AFX_MSG_MAP(CSmsSendDlg)
	ON_WM_SYSCOMMAND()
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_BN_CLICKED(IDC_OPEN, OnOpen)
	ON_BN_CLICKED(IDC_SEND, OnSend)
	ON_BN_CLICKED(IDC_CLEAR, OnClear)
	ON_LBN_SELCHANGE(IDC_MSISDN_LIST, OnSelchangeMsisdnList)
	ON_BN_CLICKED(IDC_BUTTON1, OnWapPush)
	ON_WM_TIMER()
	ON_WM_CANCELMODE()
	ON_CBN_SELCHANGE(IDC_COMBO1, OnSelchangeXY)
	ON_BN_CLICKED(IDC_BUTTON_READ, OnButtonRead)
	ON_BN_CLICKED(IDC_CHECK_SEND_ALIVE_MSG, OnCheckSendAliveMsg)
	ON_BN_CLICKED(IDC_BUTTON_SEND_ALIVE_MSG, OnButtonSendAliveMsg)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CSmsSendDlg message handlers

BOOL CSmsSendDlg::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
	UpdateMsisdnList();
	if(SockType!=SOCK_YLF_CMPP)
	{
		ylfIPc.SetReadOnly();
		ylfPortc.SetReadOnly();
		systemidc.SetReadOnly();
	}
	else
	{
		ylfIPc.SetReadOnly(FALSE);
		ylfPortc.SetReadOnly(FALSE);
		systemidc.SetReadOnly(FALSE);
	}

	SetTimer(2,5000,NULL);
	return TRUE;  // return TRUE  unless you set the focus to a control
}

void CSmsSendDlg::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 CSmsSendDlg::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 CSmsSendDlg::OnQueryDragIcon()
{
	return (HCURSOR) m_hIcon;
}

void CSmsSendDlg::OnOpen() 
{
	BeginWaitCursor();
	UpdateData();
	CString error;
	if(SockType<0)
	{
		AfxMessageBox("你还未选协议");
		return;
	}
	int connect=0;
	int open=0;
	if(SockType==SOCK_SMPP)
	{
		SmppSock.fLogout();
		SmppSock.fDisconnect();
		Sleep(1000);
		connect=SmppSock.fConnect(ip.GetBuffer(0),port);
		open=SmppSock.fLogin(user.GetBuffer(0),pwd.GetBuffer(0));
		error=SmppSock.error;
	}
	else if(SockType==SOCK_CMPP)
	{
		CmppSock.fLogout();
		CmppSock.fDisconnect();
		Sleep(1000);
		connect=CmppSock.fConnect(ip.GetBuffer(0),port);
		open=CmppSock.fLogin(user.GetBuffer(0),pwd.GetBuffer(0));
		error=CmppSock.error;
	}
	else if(SockType==SOCK_YLF_CMPP)
	{
		ylfSock.fDisconnect();
		Sleep(1000);
		connect=ylfSock.fConnect(ylfIP.GetBuffer(0),ylfPort);
		open=ylfSock.fLogin(ip.GetBuffer(0),port,systemid.GetBuffer(0),user.GetBuffer(0),pwd.GetBuffer(0));
		error=ylfSock.error;
	}
	else if(SockType==SOCK_YLF_SRIP)
	{
		SRIPHostSock.fDisconnect();
		Sleep(100);
		connect=SRIPHostSock.fConnect(ip.GetBuffer(0),port);
		open=SRIPHostSock.fLogin(user.GetBuffer(0),pwd.GetBuffer(0));
		error=SRIPHostSock.error;
	}
	else if(SockType==SOCK_SGIP)
	{
		SGIPSock.fLogout();
		SGIPSock.fDisconnect();
		Sleep(1000);
		connect=SGIPSock.fConnect(ip.GetBuffer(0),port);
		open=SGIPSock.fLogin(user.GetBuffer(0),pwd.GetBuffer(0));
		error=SGIPSock.error;
	}
	else if(SockType==SOCK_Nokia)
	{
		NokiaSock.fLogout();
		NokiaSock.fDisconnect();
		Sleep(1000);
		connect=NokiaSock.fConnect(ip.GetBuffer(0),port);
		open=NokiaSock.fLogin(user.GetBuffer(0),pwd.GetBuffer(0));
		error=NokiaSock.error;
	}
	else if(SockType==SOCK_YLF_WAP)
	{
		ylfWapSock.fDisconnect();
		Sleep(100);
		connect=ylfWapSock.fConnect(ip.GetBuffer(0),port);
		open=ylfWapSock.fLogin(user.GetBuffer(0),pwd.GetBuffer(0));
		error=ylfWapSock.error;
	}
	else if(SockType==SOCK_DR_CMPP)
	{
		drSock.fLogout();
		drSock.fDisconnect();
		AddList(drSock.error);
		Sleep(1000);
		connect=drSock.fConnect(ip.GetBuffer(0),port);
		open=drSock.fLogin(user.GetBuffer(0),pwd.GetBuffer(0));
		error=drSock.error;
	}
	char buf[200];
	sprintf(buf,"连接返回码为:%d(1为成功),用户登录返回码为:%d(大于0为成功)",connect,open);
	AddList(buf);
	AddList(error);
	EndWaitCursor();
}

void CSmsSendDlg::OnSend() 
{
	BeginWaitCursor();
	int sendFail=0;
	UpdateData();
	if(SockType==SOCK_SMPP)
	{
		SmppSock.SetFlashState(bFlash);
		SmppSock.m_msg_len=m_msg_len;
		sendFail=SmppSock.fSendSM(msisdn.GetBuffer(0),src.GetBuffer(0),message.GetBuffer(0),false);
	}
	else if(SockType==SOCK_CMPP)
	{
		sendFail=CmppSock.fSendSM(msisdn.GetBuffer(0),src.GetBuffer(0),message.GetBuffer(0),false);
	}
	else if(SockType==SOCK_YLF_CMPP)
	{
		sendFail=ylfSock.fSendSM(msisdn.GetBuffer(0),message.GetBuffer(0));
	}
	else if(SockType==SOCK_YLF_SRIP)
	{
		for(int i=0;i<100;i++)
		{
			if(!SRIPHostSock.AddMsisdn(434731287,275,712345,12,0))break;
		}
		sendFail=SRIPHostSock.Submit();
	}
	else if(SockType==SOCK_SGIP)
	{
		sendFail=SGIPSock.fSendSM(msisdn.GetBuffer(0),src.GetBuffer(0),message.GetBuffer(0),false);
	}
	else if(SockType==SOCK_Nokia)
	{
		sendFail=NokiaSock.fSendSM(msisdn.GetBuffer(0),src.GetBuffer(0),message.GetBuffer(0),false);
	}
	else if(SockType==SOCK_YLF_WAP)
	{
		sendFail=ylfWapSock.fSendSM(msisdn.GetBuffer(0),m_http.GetBuffer(0),message.GetBuffer(0));
	}
	else if(SockType==SOCK_DR_CMPP)
	{
		sendFail=drSock.fSendSM(msisdn.GetBuffer(0),src.GetBuffer(0),message.GetBuffer(0),false);
	}
	char buf[200];
	sprintf(buf,"%s,发送返回码为:%d(1为成功)",(sendFail==1)?"发送成功":"发送失败",sendFail);
	AddList(buf);
	AddMsisdnList();
	EndWaitCursor();
}

void CSmsSendDlg::OnClear() 
{
	listc.ResetContent();
}

void CSmsSendDlg::AddList(CString str)
{
	listc.AddString(str);
}

void CSmsSendDlg::SaveRegistry()
{
	AfxGetApp()->WriteProfileString("sms_send_test","ip",ip);
	AfxGetApp()->WriteProfileInt("sms_send_test","port",port);
	AfxGetApp()->WriteProfileString("sms_send_test","user",user);
	AfxGetApp()->WriteProfileString("sms_send_test","pwd",pwd);
	AfxGetApp()->WriteProfileString("sms_send_test","src",src);
	AfxGetApp()->WriteProfileString("sms_send_test","msisdn",msisdn);
	AfxGetApp()->WriteProfileString("sms_send_test","message",message);
//for ylfCmppServer
	AfxGetApp()->WriteProfileString("sms_send_test","ylfip",ylfIP);
	AfxGetApp()->WriteProfileInt("sms_send_test","ylfport",ylfPort);
	AfxGetApp()->WriteProfileString("sms_send_test","systemid",systemid);
	AfxGetApp()->WriteProfileInt("sms_send_test","SockType",SockType);
	
	CString str;
	for(int i=0;i<MAX_MSISDN;i++)
	{
		str.Format("msisdn%d",i);
		AfxGetApp()->WriteProfileString("sms_send_test",str,msisdns[i]);
	}

}

void CSmsSendDlg::OnSelchangeMsisdnList() 
{
	UpdateData();
	if(m_curmsisdn!="")
	{
		msisdn=m_curmsisdn;
		msisdnc.SetWindowText(msisdn);
	}
}

void CSmsSendDlg::AddMsisdnList()
{
	for(int i=0;i<MAX_MSISDN;i++)
	{
		if(msisdns[i]==msisdn)return;
	}
	for(i=MAX_MSISDN-1;i>0;i--)
	{
		msisdns[i]=msisdns[i-1];
	}
	msisdns[0]=msisdn;
	UpdateMsisdnList();
}

void CSmsSendDlg::UpdateMsisdnList()
{
	msisdnList.ResetContent();
	for(int i=0;i<MAX_MSISDN;i++)
	{
		if(msisdns[i]=="")continue;
		msisdnList.AddString(msisdns[i]);
	}
}

void CSmsSendDlg::OnWapPush() 
{
	BeginWaitCursor();
	int sendFail=0;
	UpdateData();
	if(SockType==SOCK_SMPP)
	{
		sendFail=SmppSock.fSendWapSM(msisdn.GetBuffer(0),src.GetBuffer(0)
			,message.GetBuffer(0),m_http.GetBuffer(0),false);
	}
	char buf[200];
	sprintf(buf,"%s,发送返回码为:%d(1为成功)",(sendFail==1)?"发送成功":"发送失败",sendFail);
	AddList(buf);
	AddMsisdnList();
	EndWaitCursor();
}

void CSmsSendDlg::OnTimer(UINT nIDEvent) 
{
	if(bSendAliveMsg)
	{
		SendAliveMsg();
	}
	CheckSms();
	CDialog::OnTimer(nIDEvent);
}

void CSmsSendDlg::OnCancelMode() 
{
	CDialog::OnCancelMode();
	
	// TODO: Add your message handler code here
	
}


void CSmsSendDlg::OnSelchangeXY() 
{
	UpdateData();
	if(SockType!=SOCK_YLF_CMPP)
	{
		ylfIPc.SetReadOnly();
		ylfPortc.SetReadOnly();
		systemidc.SetReadOnly();
	}
	else
	{
		ylfIPc.SetReadOnly(FALSE);
		ylfPortc.SetReadOnly(FALSE);
		systemidc.SetReadOnly(FALSE);
	}
	
}

void CSmsSendDlg::OnButtonRead() 
{
	if(SockType==SOCK_SMPP)
	{
	}
	else if(SockType==SOCK_CMPP)
	{
		if(CmppSock.fReadAndAtuoAnswer()==1)
		{
			AddList("read 成功");
		}
	}
	else if(SockType==SOCK_SGIP)
	{
	}
	else if(SockType==SOCK_YLF_CMPP)
	{
	}
	
}

void CSmsSendDlg::OnCheckSendAliveMsg() 
{
	bSendAliveMsg=!bSendAliveMsg;
	if(bSendAliveMsg)
	{
		OnButtonSendAliveMsg();
	}
}

void CSmsSendDlg::OnButtonSendAliveMsg() 
{
	SendAliveMsg();
}

void CSmsSendDlg::SendAliveMsg()
{
	if(SockType==SOCK_SMPP)
	{
		if(SmppSock.fAliveTst()==1)
		{
			AddList("AliveTst 成功");
		}
	}
	else if(SockType==SOCK_CMPP)
	{
		if(CmppSock.fAliveTst()==1)
		{
			AddList("AliveTst 成功");
		}
	}
	else if(SockType==SOCK_SGIP)
	{
	}
	else if(SockType==SOCK_YLF_CMPP)
	{
		if(ylfSock.fAliveTst()==1)
		{
			AddList("AliveTst 成功");
		}
	}
	else if(SockType==SOCK_YLF_WAP)
	{
		if(ylfWapSock.fAliveTst()==1)
		{
			AddList("AliveTst 成功");
		}
	}
	else if(SockType==SOCK_DR_CMPP)
	{
		if(drSock.fAliveTst()==1)
		{
			AddList("AliveTst 成功");
		}
	}
}

void CSmsSendDlg::CheckSms()
{
	if(SockType==SOCK_SMPP)
	{
		SmppSock.Check();
	}
	else if(SockType==SOCK_CMPP)
	{
		CmppSock.Check();
	}
}

⌨️ 快捷键说明

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