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

📄 smppagentdlg.cpp

📁 模拟手机源程序,做短信系统(源码)
💻 CPP
字号:
// SMPPAgentDlg.cpp : implementation file
//

#include "stdafx.h"
#include "SMPPAgent.h"
#include "SMPPAgentDlg.h"
#include "SMPProtocol.h"
#include "AmuseCom.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()

/////////////////////////////////////////////////////////////////////////////
// CSMPPAgentDlg dialog

CSMPPAgentDlg::CSMPPAgentDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CSMPPAgentDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CSMPPAgentDlg)
	m_bShowMain = TRUE;
	m_strHandset = _T("");
	m_strSendContent = _T("");
	m_strSMSCLink = _T("");
	m_strAmuseLink = _T("");
	m_nMOCount = 0;
	m_nReportCount = 0;
	m_nMTCount = 0;
	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void CSMPPAgentDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CSMPPAgentDlg)
	DDX_Control(pDX, IDC_LIST_STATUS, m_clStatus);
	DDX_Control(pDX, IDC_LIST_TESTLINK, m_clTestLink);
	DDX_Control(pDX, IDC_LIST_AMUSE, m_clAmuseDisplay);
	DDX_Check(pDX, IDC_CHECK_SHOW, m_bShowMain);
	DDX_Text(pDX, IDC_EDIT_HANDSET, m_strHandset);
	DDX_Text(pDX, IDC_EDIT_CONTENT, m_strSendContent);
	DDX_Text(pDX, IDC_EDIT_SMSC_LINK, m_strSMSCLink);
	DDX_Text(pDX, IDC_EDIT_AMUSE_LINK, m_strAmuseLink);
	DDX_Text(pDX, IDC_EDIT_MO_COUNT, m_nMOCount);
	DDX_Text(pDX, IDC_EDIT_REPORT_COUNT, m_nReportCount);
	DDX_Text(pDX, IDC_EDIT_MT_COUNT, m_nMTCount);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CSMPPAgentDlg, CDialog)
	//{{AFX_MSG_MAP(CSMPPAgentDlg)
	ON_WM_SYSCOMMAND()
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_WM_TIMER()
	ON_MESSAGE(WM_DISPLAY_MSG,OnDisplayMsg)
	ON_BN_CLICKED(IDC_BUTTON_TEST, OnButtonTest)
	ON_BN_CLICKED(IDC_CHECK_SHOW, OnCheckShow)
	ON_WM_CLOSE()
	ON_BN_CLICKED(IDC_BUTTON_SEND, OnButtonSend)
	ON_LBN_DBLCLK(IDC_LIST_AMUSE, OnDblclkListAmuse)
	ON_WM_CTLCOLOR()
	ON_BN_CLICKED(IDC_BUTTON2, OnButton2)
	//}}AFX_MSG_MAP
	ON_MESSAGE(WM_CLOSESOCKET_USER, OnButton2)
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CSMPPAgentDlg message handlers

BOOL CSMPPAgentDlg::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_strHandset = "";
	m_nMOCount = 0;
	m_nMTCount = 0;
	m_nReportCount = 0;

	m_strSMSCLink = " ";
	m_strAmuseLink = " ";
	UpdateData(false);

	SetTimer(1,500,NULL);	
	
	m_tnid.cbSize=sizeof(NOTIFYICONDATA);
	m_tnid.hWnd=this->m_hWnd;
	m_tnid.uFlags=NIF_MESSAGE|NIF_ICON|NIF_TIP;
	m_tnid.uCallbackMessage=WM_TRAY_NOTIFYICON;
	strcpy(m_tnid.szTip,"手机娱乐通讯模块");
	m_tnid.uID=IDR_MAINFRAME;
	HICON hIcon;
	hIcon=AfxGetApp()->LoadIcon(IDR_MAINFRAME);
	m_tnid.hIcon=hIcon;
	::Shell_NotifyIcon(NIM_ADD,&m_tnid);

	CreateDirectory(".\\ERRLOG",NULL);

	CTime timeNow(CTime::GetCurrentTime());
	CString strNow=timeNow.Format(".\\ERRLOG\\AGENTERR_%Y%m%d.txt");

	SetTimer(3,((23-timeNow.GetHour())*60+(60-timeNow.GetMinute()))*60*1000,NULL);

	//打开日志文件;
	if(!m_fileLog.Open(strNow,CFile::modeNoTruncate|CFile::modeCreate|
		CFile::modeWrite|CFile::shareDenyWrite))
	{
		AfxMessageBox("ERROR:打开日志文件时出错!");
		m_fileLog.m_hFile = 0xFFFFFFFF;
		return false;
	}
	
	//文件定位指针移到文件的末尾;
	m_fileLog.SeekToEnd();

	return TRUE;  // return TRUE  unless you set the focus to a control
}

void CSMPPAgentDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
	if ((nID & 0xFFF0) == IDM_ABOUTBOX)
	{
		CAboutDlg dlgAbout;
		dlgAbout.DoModal();
	}
	else if(nID==SC_MINIMIZE)
	{
		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 CSMPPAgentDlg::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 CSMPPAgentDlg::OnQueryDragIcon()
{
	return (HCURSOR) m_hIcon;
}

void CSMPPAgentDlg::OnTimer(UINT nIDEvent) 
{
	// TODO: Add your message handler code here and/or call default

	//int m_nTestConnInterval;
	switch(nIDEvent)
	{
	case 1:
		KillTimer(1);

		m_nTestConnInterval = GetPrivateProfileInt("游戏引擎", "TESTCONN_INTERVAL", 0,PROFILE_NAME);
		if(m_nTestConnInterval == 0)
			return ;

		m_pcAmuseCom = new CAmuseCom(this);

		SetTimer(2,m_nTestConnInterval,NULL);	
		m_pcAmuseCom->TestLinkTwo();		
		break;

	case 2:
		m_pcAmuseCom->TestLinkTwo();		
		break;

	case 3:
		KillTimer(3);

		CTime timeNow(CTime::GetCurrentTime());
		CString strNow=timeNow.Format(".\\ERRLOG\\AGENTERR_%Y%m%d.txt");

		if(m_fileLog.m_hFile != NULL)	
			m_fileLog.Close();		

		if(!m_fileLog.Open(strNow,CFile::modeNoTruncate|CFile::modeCreate|
			CFile::modeWrite|CFile::shareDenyWrite))
		{
			m_clAmuseDisplay.InsertString(-1,"ERROR:打开日志文件时出错!");			
		}
		SetTimer(3,24*60*60*1000,NULL);

		break;
	}		

	CDialog::OnTimer(nIDEvent);
}

void CSMPPAgentDlg::OnDisplayMsg(WPARAM nType,LPARAM lParam)
{
	char szCurrDate[10];
	char szCurrTime[10];
	char szShowMsg[MAX_DISPLAY_LEN+500];
	
	_strdate(szCurrDate);		//取得当前日期;
	_strtime(szCurrTime);		//取得当前时间;

	switch(nType)
	{
	case 0:
		break;

	case APP_AMUSECOM:	
		sprintf(szShowMsg,"%s %s [协议转换层]%s\r\n",szCurrDate,szCurrTime,(char*)lParam);		
		break;

	case APP_SMPPROTOCOL:	
		sprintf(szShowMsg,"%s %s    [SMPP协议层]%s\r\n",szCurrDate,szCurrTime,(char*)lParam);		
		break;

	case APP_AMUSECOM+10:
		sprintf(szShowMsg,"%s %s       [SOCKET]%s\r\n",szCurrDate,szCurrTime,(char*)lParam);
		break;
	}	
	m_clAmuseDisplay.AddString(szShowMsg);
	m_clAmuseDisplay.SetCurSel(m_clAmuseDisplay.GetCount()-1);
}

int CSMPPAgentDlg::Display(int nType,char* szDisMsg)
{
	char szTemp[MAX_DISPLAY_LEN+500];
	int  nIsTestLink = 0;
	int  nIsErrorMsg = 0;

	strcpy(szTemp,szDisMsg);
	szTemp[8] = '\0';
	if(!strcmp(szTemp,"[TSTLNK]"))
	{
		nIsTestLink = 1;		
	}

	if(!strcmp(szTemp,"[STATUS]"))
	{
		nIsTestLink = 2;		
	}

	memcpy(szTemp,szDisMsg + 8,7);
	szTemp[7] = '\0';
//	if(!strcmp(szTemp,"[ERROR]"))
		nIsErrorMsg = 1;

	char szCurrDate[10];
	char szCurrTime[10];
	char szShowMsg[MAX_DISPLAY_LEN+500];
	
	_strdate(szCurrDate);		//取得当前日期;
	_strtime(szCurrTime);		//取得当前时间;

	szCurrDate[5] = '\0';
	//nIsTestLink = 0;
	switch(nType)
	{
	case 0:
		break;

	case APP_AMUSECOM:	
		if(nIsTestLink == 0)
			sprintf(szShowMsg,"%s %s %s\r\n",szCurrDate,szCurrTime,szDisMsg);		
		else if(nIsTestLink == 1)
			sprintf(szShowMsg,"%s [协议转换层]%s\r\n",szCurrTime,szDisMsg);
		else
			sprintf(szShowMsg,"%s [转换层]%s\r\n",szCurrTime,szDisMsg);	

		break;

	case APP_SMPPROTOCOL:
		if(nIsTestLink == 0)
			sprintf(szShowMsg,"%s %s %s\r\n",szCurrDate,szCurrTime,szDisMsg);		
		else if(nIsTestLink == 1)
			sprintf(szShowMsg,"%s    [SMPP协议层]%s\r\n",szCurrTime,szDisMsg);		
		else
			sprintf(szShowMsg,"%s [SMPP层]%s\r\n",szCurrTime,szDisMsg);		

		break;

	case APP_AMUSECOM+10:	
		sprintf(szShowMsg,"%s %s       [SOCKET][AMUSE]%s\r\n",szCurrDate,szCurrTime,szDisMsg);
		break;

	case APP_SMPPROTOCOL+10:
		sprintf(szShowMsg,"%s %s       [SOCKET][SMPP]%s\r\n",szCurrDate,szCurrTime,szDisMsg);
		break;
	}

	int nListCount;

	if(!strcmp(szDisMsg," "))
		strcpy(szShowMsg," ");
	
	switch(nIsTestLink)
	{
	case 0:
		if(m_bShowMain)
		{
			nListCount = m_clAmuseDisplay.GetCount();
			if(nListCount >= MAX_DISPLAY_COUNT)
			{
				m_clAmuseDisplay.ResetContent();
				nListCount = 0;
			}

			m_clAmuseDisplay.AddString(szShowMsg);
			m_clAmuseDisplay.SetCurSel(nListCount);
		}
		break;
	/*
	case 1:
		nListCount = m_clTestLink.GetCount();
		if(nListCount >= MAX_DISPLAY_COUNT)
		{
			m_clTestLink.ResetContent();
			nListCount = 0;
		}

		m_clTestLink.AddString(szShowMsg);
		m_clTestLink.SetCurSel(m_clTestLink.GetCount()-1);
		break;

	case 2:
		nListCount = m_clStatus.GetCount();
		if(nListCount >= MAX_DISPLAY_COUNT)
		{
			m_clStatus.ResetContent();
			nListCount = 0;
		}

		m_clStatus.AddString(szShowMsg);
		m_clStatus.SetCurSel(m_clStatus.GetCount()-1);
		break;
		*/
	}

	if((nIsTestLink == 0)&&(m_fileLog != 0xFFFFFFFF))
	{
		m_fileLog.Write(szShowMsg,strlen(szShowMsg));
	}

	
	return 1;
}

void CSMPPAgentDlg::OnButtonTest() 
{
	// TODO: Add your control notification handler code here
	m_pcAmuseCom->TestLinkTwo();
	GetDlgItem(IDC_BUTTON_TEST)->EnableWindow(FALSE);
}

void CSMPPAgentDlg::OnCheckShow() 
{
	// TODO: Add your control notification handler code here	
	m_bShowMain = !m_bShowMain;	
}

void CSMPPAgentDlg::OnOK()
{
}

void CSMPPAgentDlg::OnCancel()
{
	if(MessageBox("你确定要退出系统吗?","注意",MB_YESNO|MB_ICONQUESTION)==IDYES)
	{	
		Exit(1);
	}
}

void CSMPPAgentDlg::OnClose() 
{
	// TODO: Add your message handler code here and/or call default

	//return ;
	CDialog::OnClose();
}

LRESULT CSMPPAgentDlg::WindowProc(UINT message, WPARAM wParam, LPARAM lParam) 
{
	switch(message)
	{
		case WM_TRAY_NOTIFYICON:			
			if(lParam==WM_LBUTTONDOWN)
			{					
				if(IsIconic())
					ShowWindow(SW_SHOWNORMAL);
				else
				{
					ShowWindow(SW_SHOWNORMAL);
					SetForegroundWindow();
				}
			}			
			break;
	}
	return CDialog::WindowProc(message, wParam, lParam);
}


void CSMPPAgentDlg::OnButtonSend() 
{
	// TODO: Add your control notification handler code here
	UpdateData(true);

	if(m_strHandset.GetLength() != 11)
	{
		MessageBox("手机号必须是11位!");
		return;
	}

	if(m_strSendContent.GetLength() ==0)
		return;

	for(int i=1;i<=1;i++)
	{
		m_pcAmuseCom->SMPPAppSubmit(0,m_strHandset.GetBuffer(m_strHandset.GetLength()),m_pcAmuseCom->m_szServiceNum,
								m_strSendContent.GetBuffer(m_strHandset.GetLength()));		
	}
}

int	 CSMPPAgentDlg::Exit(int nFlag)
{
	::Shell_NotifyIcon(NIM_DELETE,&m_tnid);
	CDialog::OnCancel();

	return 1;
}

void CSMPPAgentDlg::OnDblclkListAmuse() 
{
	// TODO: Add your control notification handler code here
	
	char szMsg[5000];
	m_clAmuseDisplay.GetText(m_clAmuseDisplay.GetCurSel(),szMsg);
	MessageBox(szMsg,"信息内容",MB_ICONINFORMATION);
}

int CSMPPAgentDlg::ShowStatus(int nType,int nValue,char* szMsg)
{
	CSMPPAgentDlg*  pcDlg;
	pcDlg = (CSMPPAgentDlg*) AfxGetMainWnd();

	pcDlg->UpdateData(true);
	switch(nType)
	{
	case APP_SMPPROTOCOL+STAT_MO_COUNT:
		m_nMOCount = nValue;
		break;

	case APP_SMPPROTOCOL+STAT_MT_COUNT:
		m_nMTCount = nValue;
		break;

	case APP_SMPPROTOCOL+STAT_REPORT_COUNT:
		m_nReportCount = nValue;
		break;

	case APP_SMPPROTOCOL+STAT_SMSC_LINK:
		if(nValue == 0)
			m_strSMSCLink = "断开";
		else if(nValue == 1)
			m_strSMSCLink = "正常";

		m_nSMSCLink = nValue;
		break;

	case APP_AMUSECOM+STAT_AMUSE_LINK:
		if(nValue == 0)
			m_strAmuseLink = "断开";
		else if(nValue == 1)
			m_strAmuseLink = "正常";

		m_nAmuseLink = nValue;
		break;
	}


	pcDlg->UpdateData(false);

	return 1;
}

HBRUSH CSMPPAgentDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) 
{
	HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
	
	// TODO: Change any attributes of the DC here
	UINT nID=pWnd->GetDlgCtrlID ();

	switch (nCtlColor)
	{
	case CTLCOLOR_EDIT:
		if (nID == IDC_EDIT_SMSC_LINK) 
		{				
			pDC->SetBkColor (RGB(212,212,212));
			if(m_nSMSCLink == 0)
				pDC->SetTextColor (RGB(255,0,0));
			else if(m_nSMSCLink == 1)
				pDC->SetTextColor (RGB(0,255,0));

			return CreateSolidBrush (RGB(212,212,212));
		}
		if (nID == IDC_EDIT_AMUSE_LINK) 
		{
			pDC->SetBkColor (RGB(212,212,212));
			if(m_nAmuseLink == 0)
				pDC->SetTextColor (RGB(255,0,0));
			else if(m_nAmuseLink == 1)
				pDC->SetTextColor (RGB(0,255,0));

			return CreateSolidBrush (RGB(212,212,212));
		}
	}	
	// TODO: Return a different brush if the default is not desired
	return hbr;
}

void CSMPPAgentDlg::OnButton2() 
{
	m_pcAmuseCom->m_pcSMPProtocol->SMPPLogOut();
}

⌨️ 快捷键说明

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