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

📄 messagedlg.cpp

📁 借用他人插件
💻 CPP
📖 第 1 页 / 共 2 页
字号:
              // messageDlg.cpp : implementation file
//

#include "stdafx.h"
#include "message.h"
#include "messageDlg.h"
#include "PassWord.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()

/////////////////////////////////////////////////////////////////////////////
// CMessageDlg dialog

CMessageDlg::CMessageDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CMessageDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CMessageDlg)
	m_ReadText = _T("");
	m_SendText = _T("");
	m_PhoneNum = _T("");
	m_BatterLevel = _T("");
	m_Signal = _T("");
	m_CharNum = _T("");
	m_MessageNum = _T("");
	m_ReportCheck = FALSE;
	m_NeedReport = FALSE;
	m_ImmediateDisplay = FALSE;
	m_Time = _T("");
	m_Result = _T("");
	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void CMessageDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CMessageDlg)
	if (first) {
	DDX_Control(pDX, IDC_BUTTON3, SendButton);
	DDX_Control(pDX, IDC_COMBO2, PhoneNumList);
	DDX_Control(pDX, IDC_SMS1, sms);
	DDX_Text(pDX, IDC_ReadText, m_ReadText);
	DDX_Text(pDX, IDC_SendText, m_SendText);
	DDX_CBString(pDX, IDC_COMBO2, m_PhoneNum);
	DDX_Text(pDX, IDC_BATTERLEVEL, m_BatterLevel);
	DDX_Text(pDX, IDC_SIGNAL, m_Signal);
	DDX_Text(pDX, IDC_CHARNUM, m_CharNum);
	DDX_Text(pDX, IDC_MESSAGENUM, m_MessageNum);
	DDX_Check(pDX, IDC_REPORTCHECK, m_ReportCheck);
	DDX_Check(pDX, IDC_NEEDREPORT, m_NeedReport);
	DDX_Check(pDX, IDC_IMMEDIATEDISPLAY, m_ImmediateDisplay);
	DDX_Text(pDX, IDC_RESULT, m_Result);
	DDX_Text(pDX, IDC_TIME, m_Time);
	first=FALSE;
	}else
	if (!timerupdate) {
	DDX_Control(pDX, IDC_BUTTON3, SendButton);
	DDX_Control(pDX, IDC_COMBO2, PhoneNumList);
	DDX_Control(pDX, IDC_SMS1, sms);
	DDX_Text(pDX, IDC_ReadText, m_ReadText);
	DDX_Text(pDX, IDC_SendText, m_SendText);
	DDX_CBString(pDX, IDC_COMBO2, m_PhoneNum);
	DDX_Text(pDX, IDC_BATTERLEVEL, m_BatterLevel);
	DDX_Text(pDX, IDC_SIGNAL, m_Signal);
	DDX_Text(pDX, IDC_CHARNUM, m_CharNum);
	DDX_Text(pDX, IDC_MESSAGENUM, m_MessageNum);
	DDX_Check(pDX, IDC_REPORTCHECK, m_ReportCheck);
	DDX_Check(pDX, IDC_NEEDREPORT, m_NeedReport);
	DDX_Check(pDX, IDC_IMMEDIATEDISPLAY, m_ImmediateDisplay);
	DDX_Text(pDX, IDC_RESULT, m_Result);}
	else
	DDX_Text(pDX, IDC_TIME, m_Time);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CMessageDlg, CDialog)
	//{{AFX_MSG_MAP(CMessageDlg)
	ON_WM_SYSCOMMAND()
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_BN_CLICKED(IDC_BUTTON2, Onclose)
	ON_BN_CLICKED(IDC_BUTTON3, OnSend)
	ON_BN_CLICKED(IDC_RECEIVE, OnReceive)
	ON_BN_CLICKED(IDC_CLEAR, OnClear)
	ON_BN_CLICKED(IDC_DELETE, OnDelete)
	ON_WM_TIMER()
	ON_EN_CHANGE(IDC_SendText, OnChangeSendText)
	ON_BN_CLICKED(IDC_SAVEBOOK, OnSavebook)
	ON_BN_CLICKED(IDC_LOADBOOK, OnLoadbook)
	ON_BN_CLICKED(IDC_ADD, OnAddPhoneNum)
	ON_BN_CLICKED(IDC_DELTEPHONENUM, OnDeltephonenum)
	ON_BN_CLICKED(IDC_MODIFYPHONENUM, OnModifyphonenum)
	ON_CBN_CLOSEUP(IDC_COMBO2, OnCloseupCombo)
	ON_BN_CLICKED(IDC_SAVE, OnSaveMessage)
	ON_EN_SETFOCUS(IDC_SendText, OnSetfocusSendText)
	ON_BN_CLICKED(IDC_BUTTON4, OnOpenSave)
	ON_BN_CLICKED(IDC_BUTTON1, OnInsertFlash)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CMessageDlg message handlers

BOOL CMessageDlg::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

	//口令验证
	PassWord PassWordDlg;
	//提示输入密码
	while(IDOK==PassWordDlg.DoModal())
	{
		if(PassWordDlg.GetPassWord()=="")

		{
			m_NeedReport=TRUE;
			m_ReportCheck=TRUE;
			IsUnicode=TRUE;
			m_ImmediateDisplay=TRUE;
			
			UpdateData(FALSE);
			
			if (sms.Open())
			{
				;
			}
			else
				MessageBox (_T("连接失败!"));
			
			PhoneState();
			
			GetPhoneNumber();
			
			CWnd::SetTimer(1,1000,NULL);
			timerupdate=FALSE;
			first=TRUE;
			return TRUE;
		}
		else
			//密码错误,提出警告,重新输入
			AfxMessageBox(_T("密码输入错误,请重试!\n注意字母的大小写。"),MB_ICONWARNING);
	}

	//选择退出
	exit(0);
}

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

void CMessageDlg::Onclose() 
{
	if (false==sms.CheckConnection()) 
	{		
		if (sms.Open())
		{
			MessageBox (_T("连接成功!"));
		}
		else
			MessageBox (_T("连接失败!"));
	}
}

void CMessageDlg::OnSend() 
{
	SendButton.EnableWindow(FALSE);

	PhoneState();

	NeedReport=m_NeedReport;

	sms.SetAutoDeleteReports(m_ReportCheck);

	PhoneNumber=m_PhoneNum.Right(11);

	//消息内容为空不发送
	if (1>m_SendText.GetLength())
	{
		SendButton.SetState(FALSE);

		MessageBox(_T("无消息!"));
		SendButton.EnableWindow(TRUE);
		return;
	}

	if (_T("13")==PhoneNumber.Left(2))
	{
		if (m_ImmediateDisplay&&-1==m_SendText.Find(_T("<F>"))&&-1==m_SendText.Find(_T("</F>"))) 
		{
			if(sms.SendSMSMessage(PhoneNumber, m_SendText, 100, NeedReport, IsUnicode, _T("")))
				Beep(1500,100);
			else
			{
				Beep(300,400);
				MessageBox(_T("发送失败!"));
				SendButton.EnableWindow(TRUE);
				return ;
			}
		}
		else
		{
/*			if (m_ImmediateDisplay)
			{
				if(sms.SendNewsFlashMessage(PhoneNumber,m_SendText,6,FALSE))
					Beep(1500,100);
				else
				{
					Beep(300,400);
					MessageBox(_T("发送失败!"));
				}
			}
			else
*/			{
				if(sms.SendFlashMessage(PhoneNumber,m_SendText,6,FALSE))
					Beep(1500,100);
				else
				{
					Beep(300,400);
					MessageBox(_T("发送失败!"));
					SendButton.EnableWindow(TRUE);
					return;
				}
			}
		}
	}
	else
	{
		MessageBox(_T("非手机号码:\r\n\r\n")+PhoneNumber);
		SendButton.EnableWindow(TRUE);
		return;
	}

	//将自己的信息存储
	SaveSelf();

	if (70<m_SendText.GetLength())
	{
		m_SendText.Delete(0,70);
		
		char ch[20];
		_itoa(m_SendText.GetLength(),ch,10);
		m_CharNum=ch;
		
		UpdateData(FALSE);
		OnSend();
	}

	SendButton.EnableWindow(TRUE);


	m_Result=_T("已发送!");
	m_SendText="";
	UpdateData(FALSE);
}

BOOL CMessageDlg::DestroyWindow() 
{
	// TODO: Add your specialized code here and/or call the base class
	sms.Close();
	return CDialog::DestroyWindow();
}

BEGIN_EVENTSINK_MAP(CMessageDlg, CDialog)
    //{{AFX_EVENTSINK_MAP(CMessageDlg)
	ON_EVENT(CMessageDlg, IDC_SMS1, 1 /* OnSMSMessageReceived */, OnOnSMSMessageReceived, VTS_I4 VTS_R8 VTS_BSTR VTS_BSTR VTS_BOOL)
	ON_EVENT(CMessageDlg, IDC_SMS1, 2 /* OnSMSReportReceived */, OnOnSMSReportReceivedSms, VTS_I4 VTS_R8 VTS_BSTR VTS_I4)
	//}}AFX_EVENTSINK_MAP
END_EVENTSINK_MAP()

void CMessageDlg::OnOnSMSMessageReceived(long Index, double Time, LPCTSTR Text, LPCTSTR Send, BOOL HasPicture) 
{
	if(sms.ReadSMSMessage(Index))
	{
		if (-1==ReadStr.Find(sms.GetLastReadSMSSend()))
		{
			
			ReadStr=ReadStr+_T("[来自]:");
			ReadStr=ReadStr+sms.GetLastReadSMSSend();
			ReadStr=ReadStr+_T("\r\n");
			
			Var_datetime=sms.GetLastReadSMSTime();
			Var_DateTime=Var_datetime;
			
			ReadStr=ReadStr+_T("[时间]:");
			ReadStr=ReadStr+Var_DateTime.Format(_T("%Y.%m.%d "));
			ReadStr=ReadStr+Var_DateTime.Format(_T("%H:%M:%S"));
			
			ReadStr=ReadStr+_T("\r\n");
			ReadStr=ReadStr+_T("[内容]:");
			ReadStr=ReadStr+sms.GetLastReadSMSText();
			ReadStr=ReadStr+_T("\r\n\r\n");
			m_ReadText=ReadStr;
			UpdateData(FALSE);
		}
		else
		{
			CString str;
			int pos;
			if (""==sms.GetLastReadSMSSend()) 
			{
				pos=ReadStr.Find(_T("\r\n[来自]:"),
					ReadStr.Find(_T("存储信息")));
			}
			else
				pos=ReadStr.Find(_T("\r\n[来自]:"),
				ReadStr.Find(sms.GetLastReadSMSSend()));
			
			if(pos==-1)
			{
				pos=10000;//如果只有一条信息,则在尾部加入信息
			}
			
			pos=pos+2;
			
			if(""==sms.GetLastReadSMSSend())
			{
				str=str+_T("[来自]:存储信息");
				str=str+_T("\r\n");
			}
			
			Var_datetime=sms.GetLastReadSMSTime();
			Var_DateTime=Var_datetime;
			
			str=str+_T("[时间]:");
			str=str+Var_DateTime.Format(_T("%Y.%m.%d "));
			str=str+Var_DateTime.Format(_T("%H:%M:%S"));
			
			str=str+"\r\n";
			str=str+_T("[内容]:");
			str=str+sms.GetLastReadSMSText();
			str=str+"\r\n\r\n";
			
			ReadStr.Insert(pos,str);
			
			m_ReadText=ReadStr;
			UpdateData(FALSE);
		}
	}

	Beep(900,100);
}

void CMessageDlg::OnReceive() 
{

	int i;

	ReadStr="";
	
	for(i=1;i<=sms.GetInboxCount();i++)
	{
		if(sms.ReadSMSMessage(i)&&0==sms.GetLastReadSMSMsgType())
		{
			if (-1==ReadStr.Find(sms.GetLastReadSMSSend()))
			{
				
				ReadStr=ReadStr+_T("[来自]:");
				ReadStr=ReadStr+sms.GetLastReadSMSSend();
				ReadStr=ReadStr+_T("\r\n");
				
				Var_datetime=sms.GetLastReadSMSTime();
				Var_DateTime=Var_datetime;
				
				ReadStr=ReadStr+_T("[时间]:");
				ReadStr=ReadStr+Var_DateTime.Format(_T("%Y.%m.%d "));
				ReadStr=ReadStr+Var_DateTime.Format(_T("%H:%M:%S"));
				
				ReadStr=ReadStr+_T("\r\n");
				ReadStr=ReadStr+_T("[内容]:");
				ReadStr=ReadStr+sms.GetLastReadSMSText();
				ReadStr=ReadStr+_T("\r\n\r\n");
				m_ReadText=ReadStr;
				UpdateData(FALSE);
			}
			else
			{
				CString str;
				int pos;
				if (""==sms.GetLastReadSMSSend()) 
				{
					pos=ReadStr.Find(_T("\r\n[来自]:"),
						ReadStr.Find(_T("存储信息")));
				}
				else
					pos=ReadStr.Find(_T("\r\n[来自]:"),
					   ReadStr.Find(sms.GetLastReadSMSSend()));

				if(pos==-1)
				{
					pos=10000;//如果只有一条信息,则在尾部加入信息
				}

⌨️ 快捷键说明

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