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

📄 receivemsgmboxdlg.cpp

📁 tc35i(GSM模块)的控制程序VC源码
💻 CPP
字号:
// ReceiveMsgMBoxDlg.cpp : implementation file
//

#include "stdafx.h"
#include "GSM_Ctrl_Prj.h"
#include "ReceiveMsgMBoxDlg.h"
#include "Common.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

bool CReceiveMsgMBoxDlg::m_isShow = false;
/////////////////////////////////////////////////////////////////////////////
// CReceiveMsgMBoxDlg dialog


CReceiveMsgMBoxDlg::CReceiveMsgMBoxDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CReceiveMsgMBoxDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CReceiveMsgMBoxDlg)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT
}


void CReceiveMsgMBoxDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CReceiveMsgMBoxDlg)
	DDX_Control(pDX, IDC_RECMBOXLIST, m_recMBoxList);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CReceiveMsgMBoxDlg, CDialog)
	//{{AFX_MSG_MAP(CReceiveMsgMBoxDlg)
	ON_BN_CLICKED(IDC_RMDELBTN, OnRmDelBtn)
	ON_BN_CLICKED(IDC_RMREPLYBTN, OnRmReplyBtn)
	ON_BN_CLICKED(IDC_RMRECALLBTN, OnRmRecallBtn)
	//}}AFX_MSG_MAP
	ON_MESSAGE(MSG_SAVE_SHORT_MSG,OnAddSaveShortMsg)
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CReceiveMsgMBoxDlg message handlers
LRESULT CReceiveMsgMBoxDlg::OnAddSaveShortMsg(WPARAM wParam, LPARAM lParam){	
	int nItem;
	nItem = m_recMBoxList.InsertItem(0,m_telStr.GetBuffer(m_telStr.GetLength()));
	m_recMBoxList.SetItemText(nItem , 1 , m_msgContent.GetBuffer(m_msgContent.GetLength()));
	m_recMBoxList.SetItemText(nItem , 2 , m_timeStr.GetBuffer(m_timeStr.GetLength()));
    SaveAll();
	return 0L;
}
//void CReceiveMsgMBoxDlg::OnAddAndSaveShortMsg(){
//	int nItem;
//	nItem = m_recMBoxList.InsertItem(0,m_telStr.GetBuffer(m_telStr.GetLength()));
//	m_recMBoxList.SetItemText(nItem , 1 , m_msgContent.GetBuffer(m_msgContent.GetLength()));
//	m_recMBoxList.SetItemText(nItem , 2 , m_timeStr.GetBuffer(m_timeStr.GetLength()));
//    SaveAll();
// }
void CReceiveMsgMBoxDlg::SaveAll()
{
	CStdioFile file;
	CString strPhone;
	CString strContent;
	CString strTime;
	int i;
    int nCnt = m_recMBoxList.GetItemCount();
	if(!file.Open(m_strFileName , CFile::modeCreate|CFile::modeWrite|CFile::typeText))
		return ;
    for(i=0 ; i<nCnt ; i++)
	{
    	strPhone = m_recMBoxList.GetItemText(i , 0);
    	strContent = m_recMBoxList.GetItemText(i , 1);
		strTime = m_recMBoxList.GetItemText(i , 2);
    	m_strFileLine = strPhone + "\t" + strContent + "\t" + strTime + "\r\n";
    	file.WriteString(m_strFileLine);
	}
}
void CReceiveMsgMBoxDlg::SetSaveStr(CString contentStr,CString timeStr,CString telStr)
{
   m_timeStr = timeStr;
   m_telStr = telStr;
   m_msgContent = contentStr;
}
void CReceiveMsgMBoxDlg::OnRmDelBtn() 
{
	// TODO: Add your control notification handler code here
	POSITION Pos = m_recMBoxList.GetFirstSelectedItemPosition();
	int nIndex = m_recMBoxList.GetNextSelectedItem(Pos);
	if(nIndex < 0)
	{
		MessageBox("请选择要删除的短信!" , "警告" , MB_OK+MB_ICONWARNING);
		return;
	}
	if(MessageBox("确实要删除此信息吗?" , "警告" , MB_OKCANCEL+MB_ICONWARNING+MB_DEFBUTTON2)==IDCANCEL)
		return;
	m_recMBoxList.DeleteItem(nIndex);
	SaveAll();
}

void CReceiveMsgMBoxDlg::OnRmReplyBtn() 
{
	// TODO: Add your control notification handler code here
//	int nItem;
	POSITION Pos = m_recMBoxList.GetFirstSelectedItemPosition();
	int nIndex = m_recMBoxList.GetNextSelectedItem(Pos);
	if(nIndex < 0)
	{
		MessageBox("请选择要回复的信息!" , "警告" , MB_OK+MB_ICONWARNING);
		return;
	}
	m_telStr=m_recMBoxList.GetItemText(nIndex,0);
	AfxGetMainWnd()->SendMessage(MSG_CALL_OR_MSG_BACK,BACK_MSG,(long)&m_telStr);
}

void CReceiveMsgMBoxDlg::OnRmRecallBtn() 
{
	// TODO: Add your control notification handler code here
//	int nItem;
	POSITION Pos = m_recMBoxList.GetFirstSelectedItemPosition();
	int nIndex = m_recMBoxList.GetNextSelectedItem(Pos);
	if(nIndex < 0)
	{
		MessageBox("请选择要回复的信息!" , "警告" , MB_OK+MB_ICONWARNING);
		return;
	}
	m_telStr=m_recMBoxList.GetItemText(nIndex,0);
	AfxGetMainWnd()->SendMessage(MSG_CALL_OR_MSG_BACK,BACK_CALL,(long)&m_telStr);
}

BOOL CReceiveMsgMBoxDlg::OnInitDialog() 
{
	CDialog::OnInitDialog();
	m_isShow = true;
	// TODO: Add extra initialization here
		m_recMBoxList.SetExtendedStyle(LVS_EX_FULLROWSELECT|LVS_EX_GRIDLINES);
    //初始化收件列表表头
	m_recMBoxList.InsertColumn(0 , "手机号" , LVCFMT_LEFT , 120 , -1);
	//m_recMBoxList.InsertColumn(1 , "姓名" , LVCFMT_LEFT , 80 , -1);
	m_recMBoxList.InsertColumn(1 , "内容" , LVCFMT_LEFT , 80 , -1);
	m_recMBoxList.InsertColumn(2 , "时间" , LVCFMT_LEFT , 80 , -1);
	//读收件箱
	m_strFileName = "ReceiveMsgMBox.pbl";

	CStdioFile file;
	if(!file.Open(m_strFileName , CFile::modeCreate|CFile::modeNoTruncate|CFile::shareDenyNone|CFile::modeRead|CFile::typeText))
		return FALSE;
	
	char szBuf[300];
	char szPhone[20];
	char szName[20];
	char szContent[200];
	char szTime[30];
	int nItem = 0;
	
	while(file.ReadString(m_strFileLine))
	{
		strcpy(szBuf , (LPCTSTR)m_strFileLine);
		sscanf(szBuf , "%s\t%s\t%s\r\n" , szPhone,szContent,szTime);

		nItem = m_recMBoxList.InsertItem(m_recMBoxList.GetItemCount() , szPhone);
		//m_recMBoxList.SetItemText(nItem , 0 , szPhone);
		m_recMBoxList.SetItemText(nItem , 1 , szContent);
		m_recMBoxList.SetItemText(nItem , 2 , szTime);
		//nItem++;
	}
	file.Close();
	//----------------------------------------------------------
	
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

⌨️ 快捷键说明

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