模拟手机通信系统(MFC)

本博客详细介绍了使用MFC(Microsoft Foundation Classes)在Visual Studio中开发手机短信通信系统的全过程。主要内容涵盖窗体结构设计、关键代码解析,以及如何通过对话框实现短信编辑、草稿箱、发件箱和收件箱的功能。通过实例展示了如何利用C++和MFC进行Windows应用程序开发,特别关注了短信通信系统的具体实现。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

第一次用VS写MFC,竟然还用了中文来作为文件名,想起来就觉得可耻呀~

窗体结构

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

关键代码

手机短信通信系统Dlg.h

// 手机短信通信系统Dlg.h : 头文件
//

#pragma once
#include "afxcmn.h"

// C手机短信通信系统Dlg 对话框
class C手机短信通信系统Dlg : public CDialogEx
{
	// 构造
public:
	C手机短信通信系统Dlg(CWnd* pParent = NULL);	// 标准构造函数

// 对话框数据
#ifdef AFX_DESIGN_TIME
	enum { IDD = IDD_MY_DIALOG };
#endif

protected:
	virtual void DoDataExchange(CDataExchange* pDX);	// DDX/DDV 支持

// 实现
protected:
	HICON m_hIcon;

	// 生成的消息映射函数
	virtual BOOL OnInitDialog();
	afx_msg void OnSysCommand(UINT nID, LPARAM lParam);
	afx_msg void OnPaint();
	afx_msg HCURSOR OnQueryDragIcon();
	DECLARE_MESSAGE_MAP()
public:
	CTabCtrl m_tabMain;
	afx_msg void OnTcnSelchangeTab1(NMHDR *pNMHDR, LRESULT *pResult);
};

手机短信通信系统Dlg.cpp

// 手机短信通信系统Dlg.cpp : 实现文件
//

#include "stdafx.h"
#include "手机短信通信系统.h"
#include "手机短信通信系统Dlg.h"
#include "afxdialogex.h"
#include"Dialog1.h"
#include"Dialog2.h"
#include"Dialog3.h"
#include"Dialog4.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#endif

// 用于应用程序“关于”菜单项的 CAboutDlg 对话框

CDialog1 m_para1;
CDialog2 m_para2;
CDialog3 m_para3;
CDialog4 m_para4;

class CAboutDlg : public CDialogEx
{
public:
	CAboutDlg();

	// 对话框数据
#ifdef AFX_DESIGN_TIME
	enum { IDD = IDD_ABOUTBOX };
#endif

protected:
	virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV 支持

// 实现
protected:
	DECLARE_MESSAGE_MAP()
};

CAboutDlg::CAboutDlg() : CDialogEx(IDD_ABOUTBOX)
{
}

void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialogEx::DoDataExchange(pDX);
}

BEGIN_MESSAGE_MAP(CAboutDlg, CDialogEx)
END_MESSAGE_MAP()

// C手机短信通信系统Dlg 对话框

C手机短信通信系统Dlg::C手机短信通信系统Dlg(CWnd* pParent /*=NULL*/)
	: CDialogEx(IDD_MY_DIALOG, pParent)
{
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void C手机短信通信系统Dlg::DoDataExchange(CDataExchange* pDX)
{
	CDialogEx::DoDataExchange(pDX);
	DDX_Control(pDX, IDC_TAB1, m_tabMain);
}

BEGIN_MESSAGE_MAP(C手机短信通信系统Dlg, CDialogEx)
	ON_WM_SYSCOMMAND()
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_NOTIFY(TCN_SELCHANGE, IDC_TAB1, &C手机短信通信系统Dlg::OnTcnSelchangeTab1)
END_MESSAGE_MAP()

// C手机短信通信系统Dlg 消息处理程序

BOOL C手机短信通信系统Dlg::OnInitDialog()
{
	CDialogEx::OnInitDialog();

	// 将“关于...”菜单项添加到系统菜单中。

	// IDM_ABOUTBOX 必须在系统命令范围内。
	ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
	ASSERT(IDM_ABOUTBOX < 0xF000);

	CMenu* pSysMenu = GetSystemMenu(FALSE);
	if (pSysMenu != NULL)
	{
		BOOL bNameValid;
		CString strAboutMenu;
		bNameValid = strAboutMenu.LoadString(IDS_ABOUTBOX);
		ASSERT(bNameValid);
		if (!strAboutMenu.IsEmpty())
		{
			pSysMenu->AppendMenu(MF_SEPARATOR);
			pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
		}
	}

	// 设置此对话框的图标。  当应用程序主窗口不是对话框时,框架将自动
	//  执行此操作
	SetIcon(m_hIcon, TRUE);			// 设置大图标
	SetIcon(m_hIcon, FALSE);		// 设置小图标

	// TODO: 在此添加额外的初始化代码
	//添加选项卡
	m_tabMain.InsertItem(0, _T("编辑短信"));//“选项卡1”可更改,是sheet页的名字;
	m_tabMain.InsertItem(1, _T("草稿箱"));
	m_tabMain.InsertItem(2, _T("发件箱"));
	m_tabMain.InsertItem(3, _T("收件箱"));

	//关联对话框,并且将IDC_TABMAIN控件设为父窗口
	m_para1.Create(IDD_DIALOG1, GetDlgItem(IDC_TAB1));
	m_para2.Create(IDD_DIALOG2, GetDlgItem(IDC_TAB1));
	m_para3.Create(IDD_DIALOG3, GetDlgItem(IDC_TAB1));
	m_para4.Create(IDD_DIALOG4, GetDlgItem(IDC_TAB1));

	//获得IDC_tabMain客户区大小
	CRect rs;
	m_tabMain.GetClientRect(&rs);
	//调整子对话框在父窗口中的位置,可以改动数值,使子窗体的大小合适;
	rs.top += 20;
	rs.bottom -= 3;
	rs.left += 2;
	rs.right -= 2;
	//设置子对话框尺寸并移动到指定位置
	m_para1.MoveWindow(&rs);
	m_para2.MoveWindow(&rs);
	m_para3.MoveWindow(&rs);
	m_para4.MoveWindow(&rs);
	//分别设置隐藏和显示
	m_para1.ShowWindow(true);
	m_para2.ShowWindow(false);
	m_para3.ShowWindow(false);
	m_para4.ShowWindow(false);
	//设置默认的选项卡
	m_tabMain.SetCurSel(0);

	return TRUE;  // 除非将焦点设置到控件,否则返回 TRUE
}

void C手机短信通信系统Dlg::OnSysCommand(UINT nID, LPARAM lParam)
{
	if ((nID & 0xFFF0) == IDM_ABOUTBOX)
	{
		CAboutDlg dlgAbout;
		dlgAbout.DoModal();
	}
	else
	{
		CDialogEx::OnSysCommand(nID, lParam);
	}
}

// 如果向对话框添加最小化按钮,则需要下面的代码
//  来绘制该图标。  对于使用文档/视图模型的 MFC 应用程序,
//  这将由框架自动完成。

void C手机短信通信系统Dlg::OnPaint()
{
	if (IsIconic())
	{
		CPaintDC dc(this); // 用于绘制的设备上下文

		SendMessage(WM_ICONERASEBKGND, reinterpret_cast<WPARAM>(dc.GetSafeHdc()), 0);

		// 使图标在工作区矩形中居中
		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;

		// 绘制图标
		dc.DrawIcon(x, y, m_hIcon);
	}
	else
	{
		CDialogEx::OnPaint();
	}
}

//当用户拖动最小化窗口时系统调用此函数取得光标
//显示。
HCURSOR C手机短信通信系统Dlg::OnQueryDragIcon()
{
	return static_cast<HCURSOR>(m_hIcon);
}

void C手机短信通信系统Dlg::OnTcnSelchangeTab1(NMHDR *pNMHDR, LRESULT *pResult)
{
	// TODO: 在此添加控件通知处理程序代码
	int CurSel = m_tabMain.GetCurSel();
	switch (CurSel)
	{
	case 0:
		m_para1.ShowWindow(true);
		m_para2.ShowWindow(false);
		m_para3.ShowWindow(false);
		m_para4.ShowWindow(false);
		break;
	case 1:
		m_para1.ShowWindow(false);
		m_para2.ShowWindow(true);
		m_para3.ShowWindow(false);
		m_para4.ShowWindow(false);
		break;
	case 2:
		m_para1.ShowWindow(false);
		m_para2.ShowWindow(false);
		m_para3.ShowWindow(true);
		m_para4.ShowWindow(false);
		break;
	case 3:
		m_para1.ShowWindow(false);
		m_para2.ShowWindow(false);
		m_para3.ShowWindow(false);
		m_para4.ShowWindow(true);
		break;
	default:;
	}
	*pResult = 0;
}

手机短信通信系统.h

// 手机短信通信系统.h : PROJECT_NAME 应用程序的主头文件
//

#pragma once

#ifndef __AFXWIN_H__
#error "在包含此文件之前包含“stdafx.h”以生成 PCH 文件"
#endif

#include "resource.h"		// 主符号

// C手机短信通信系统App:
// 有关此类的实现,请参阅 手机短信通信系统.cpp
//

class C手机短信通信系统App : public CWinApp
{
public:
	C手机短信通信系统App();

	// 重写
public:
	virtual BOOL InitInstance();

	// 实现

	DECLARE_MESSAGE_MAP()
};

extern C手机短信通信系统App theApp;

手机短信通信系统.cpp

// 手机短信通信系统.cpp : 定义应用程序的类行为。
//

#include "stdafx.h"
#include "手机短信通信系统.h"
#include "手机短信通信系统Dlg.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#endif

// C手机短信通信系统App

BEGIN_MESSAGE_MAP(C手机短信通信系统App, CWinApp)
	ON_COMMAND(ID_HELP, &CWinApp::OnHelp)
END_MESSAGE_MAP()

// C手机短信通信系统App 构造

C手机短信通信系统App::C手机短信通信系统App()
{
	// 支持重新启动管理器
	m_dwRestartManagerSupportFlags = AFX_RESTART_MANAGER_SUPPORT_RESTART;

	// TODO: 在此处添加构造代码,
	// 将所有重要的初始化放置在 InitInstance 中
}

// 唯一的一个 C手机短信通信系统App 对象

C手机短信通信系统App theApp;

// C手机短信通信系统App 初始化

BOOL C手机短信通信系统App::InitInstance()
{
	// 如果一个运行在 Windows XP 上的应用程序清单指定要
	// 使用 ComCtl32.dll 版本 6 或更高版本来启用可视化方式,
	//则需要 InitCommonControlsEx()。  否则,将无法创建窗口。
	INITCOMMONCONTROLSEX InitCtrls;
	InitCtrls.dwSize = sizeof(InitCtrls);
	// 将它设置为包括所有要在应用程序中使用的
	// 公共控件类。
	InitCtrls.dwICC = ICC_WIN95_CLASSES;
	InitCommonControlsEx(&InitCtrls);

	CWinApp::InitInstance();

	AfxEnableControlContainer();

	// 创建 shell 管理器,以防对话框包含
	// 任何 shell 树视图控件或 shell 列表视图控件。
	CShellManager *pShellManager = new CShellManager;

	// 激活“Windows Native”视觉管理器,以便在 MFC 控件中启用主题
	CMFCVisualManager::SetDefaultManager(RUNTIME_CLASS(CMFCVisualManagerWindows));

	// 标准初始化
	// 如果未使用这些功能并希望减小
	// 最终可执行文件的大小,则应移除下列
	// 不需要的特定初始化例程
	// 更改用于存储设置的注册表项
	// TODO: 应适当修改该字符串,
	// 例如修改为公司或组织名
	SetRegistryKey(_T("应用程序向导生成的本地应用程序"));

	C手机短信通信系统Dlg dlg;
	m_pMainWnd = &dlg;
	INT_PTR nResponse = dlg.DoModal();
	if (nResponse == IDOK)
	{
		// TODO: 在此放置处理何时用
		//  “确定”来关闭对话框的代码
	}
	else if (nResponse == IDCANCEL)
	{
		// TODO: 在此放置处理何时用
		//  “取消”来关闭对话框的代码
	}
	else if (nResponse == -1)
	{
		TRACE(traceAppMsg, 0, "警告: 对话框创建失败,应用程序将意外终止。\n");
		TRACE(traceAppMsg, 0, "警告: 如果您在对话框上使用 MFC 控件,则无法 #define _AFX_NO_MFC_CONTROLS_IN_DIALOGS。\n");
	}

	// 删除上面创建的 shell 管理器。
	if (pShellManager != NULL)
	{
		delete pShellManager;
	}

#if !defined(_AFXDLL) && !defined(_AFX_NO_MFC_CONTROLS_IN_DIALOGS)
	ControlBarCleanUp();
#endif

	// 由于对话框已关闭,所以将返回 FALSE 以便退出应用程序,
	//  而不是启动应用程序的消息泵。
	return FALSE;
}

targetver.h

#pragma once

// 包括 SDKDDKVer.h 将定义可用的最高版本的 Windows 平台。

// 如果要为以前的 Windows 平台生成应用程序,请包括 WinSDKVer.h,并将
// 将 _WIN32_WINNT 宏设置为要支持的平台,然后再包括 SDKDDKVer.h。

#include <SDKDDKVer.h>

stdafx.h

// stdafx.h : 标准系统包含文件的包含文件,
// 或是经常使用但不常更改的
// 特定于项目的包含文件

#pragma once

#ifndef VC_EXTRALEAN
#define VC_EXTRALEAN            // 从 Windows 头中排除极少使用的资料
#endif

#include "targetver.h"

#define _ATL_CSTRING_EXPLICIT_CONSTRUCTORS      // 某些 CString 构造函数将是显式的

// 关闭 MFC 对某些常见但经常可放心忽略的警告消息的隐藏
#define _AFX_ALL_WARNINGS

#include <afxwin.h>         // MFC 核心组件和标准组件
#include <afxext.h>         // MFC 扩展

#include <afxdisp.h>        // MFC 自动化类

#ifndef _AFX_NO_OLE_SUPPORT
#include <afxdtctl.h>           // MFC 对 Internet Explorer 4 公共控件的支持
#endif
#ifndef _AFX_NO_AFXCMN_SUPPORT
#include <afxcmn.h>             // MFC 对 Windows 公共控件的支持
#endif // _AFX_NO_AFXCMN_SUPPORT

#include <afxcontrolbars.h>     // 功能区和控件条的 MFC 支持

#ifdef _UNICODE
#if defined _M_IX86
#pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='x86' publicKeyToken='6595b64144ccf1df' language='*'\"")
#elif defined _M_X64
#pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='amd64' publicKeyToken='6595b64144ccf1df' language='*'\"")
#else
#pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'\"")
#endif
#endif

stdafx.cpp

// stdafx.cpp : 只包括标准包含文件的源文件
// 手机短信通信系统.pch 将作为预编译头
// stdafx.obj 将包含预编译类型信息

#include "stdafx.h"

SendMessage2.h

#pragma once
#include"com_def.h"
int InitList2(PNode &L) {//初始化链表(双向循环链表)
	L = (PNode)malloc(sizeof(Node));
	L->next = L;
	L->prior = L;

	fstream SendMessage;//将发送箱里面短信写入到链表里面
	SendMessage.open("sendbuffer.txt", ios::in);
	while (!SendMessage.eof())
	{
		PNode q = (PNode)malloc(sizeof(Node));
		//if (!q)
		//{
		//	cout << "Error!" << endl;
		//	return 0;
		//}//申请失败则提示错误

		if (!SendMessage.getline(q->Mess.Receiver, 80))
			break;//读出收件人的姓名,读到空行则结束
		if (!SendMessage.getline(q->Mess.News, 80))
			break;//读出发件人的信息,读到空行则结束
		if (!SendMessage.getline(q->Mess.Sender, 80))
			break;//读出收件人姓名,读到空行则结束

		q->Flag = 1;//由于是从发送箱中读取,故默认为1
		L->next->prior = q;//双向循环链表的建立
		q->next = L->next;
		q->prior = L;
		L->next = q;
	}
	SendMessage.close();

	fstream DraftMessage;//将草稿箱里面短信写入到链表里面
	DraftMessage.open("draftbuffer.txt", ios::in);
	while (!DraftMessage.eof())
	{
		PNode q = (PNode)malloc(sizeof(Node));
		//if (!q)
		//{
		//	cout << "Error!" << endl;
		//	return 0;
		//}//申请失败则提示错误

		if (!DraftMessage.getline(q->Mess.Receiver, 80))
			break;//读出收件人的姓名,读到空行则结束
		if (!DraftMessage.getline(q->Mess.News, 80))
			break;//读出发件人的信息,读到空行则结束
		if (!DraftMessage.getline(q->Mess.Sender, 80))
			break;//读出收件人姓名,读到空行则结束

		q->Flag = 2;//由于是从草稿箱中读取,故默认为2
		L->next->prior = q;//双向循环链表的建立
		q->next = L->next;
		q->prior = L;
		L->next = q;
	}
	DraftMessage.close();

	return 1;
}
int DelateSendMessage(PNode L, int i) {//清空发送箱,将链表重新写入发送箱
	int j = 0;
	PNode p = L, q;
	ofstream ofsend("sendbuffer.txt");
	ofsend.clear();//清空发送箱

	while (p->next != L) {//遍历链表
		p = p->next;
		j++;
		if ((p->Flag == 1)) {//删除链表里面发送箱的某条信息
			if (j == i) {
				p->prior->next = p->next;
				p->next->prior = p->prior;
				q = p->prior;
				free(p);
				p = q;
			}
			else {
				ofsend << p->Mess.Receiver << endl << p->Mess.News << endl << p->Mess.Sender << endl;	//除了删除节点,原来其他的发送箱短信重新写入
			}
		}
	}

	ofsend.close(); //写入发送箱
	return 1;
}
string FindSendMessage(PNode L, int i)
{
	string str;
	int j = 0;
	PNode p = L;
	while (p->next != L) {//遍历链表输出发件箱内容
		p = p->next;
		if (p->Flag == 1) {
			j++;
			if (j == i) {
				str = p->Mess.News;
				//cout << "第" << i << "条短信内容为:" << p->Mess.News << endl;
			}
		}
	}
	return str;
}

SendMessage1.h

#pragma once
#include"com_def.h"
#define N "00000000000000000000000000000"//宏定义标志信息结点是从文件读取还是从键盘输入
char *day[] = { "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" };//输出周几需要的数组
int InitList1(PNode &L) {//初始化链表(双向循环链表)
	L = (PNode)malloc(sizeof(Node));
	L->next = L;
	L->prior = L;

	fstream SendMessage;//将发送箱里面短信写入到链表里面
	SendMessage.open("sendbuffer.txt", ios::in);
	while (!SendMessage.eof())
	{
		PNode q = (PNode)malloc(sizeof(Node));
		//if (!q)
		//{
		//	cout << "Error!" << endl;
		//	return 0;
		//}//申请失败则提示错误
		SendMessage.getline(q->ShowTime, 80);//从草稿箱中分别读取年月日、周几、时分秒到信息结点
		if (!SendMessage.getline(q->Mess.Receiver, 80))
			break;//读出收件人的姓名,读到空行则结束
		if (!SendMessage.getline(q->Mess.News, 80))
			break;//读出发件人的信息,读到空行则结束
		if (!SendMessage.getline(q->Mess.Sender, 80))
			break;//读出收件人姓名,读到空行则结束

		q->Flag = 1;//由于是从发送箱中读取,故默认为1
		L->next->prior = q;//双向循环链表的建立
		q->next = L->next;
		q->prior = L;
		L->next = q;
	}
	SendMessage.close();

	fstream DraftMessage;//将草稿箱里面短信写入到链表里面
	DraftMessage.open("draftbuffer.txt", ios::in);
	while (!DraftMessage.eof())
	{
		PNode q = (PNode)malloc(sizeof(Node));
		//if (!q)
		//{
		//	cout << "Error!" << endl;
		//	return 0;
		//}//申请失败则提示错误
		DraftMessage.getline(q->ShowTime, 80);//从草稿箱中分别读取年月日、周几、时分秒到信息结点
		if (!DraftMessage.getline(q->Mess.Receiver, 80))
			break;//读出收件人的姓名,读到空行则结束
		if (!DraftMessage.getline(q->Mess.News, 80))
			break;//读出发件人的信息,读到空行则结束
		if (!DraftMessage.getline(q->Mess.Sender, 80))
			break;//读出收件人姓名,读到空行则结束

		q->Flag = 2;//由于是从草稿箱中读取,故默认为2
		L->next->prior = q;//双向循环链表的建立
		q->next = L->next;
		q->prior = L;
		L->next = q;
	}
	DraftMessage.close();

	return 1;
}
int DelateDraftMessage(PNode L, int i) {//清空草稿箱,将链表重新写入草稿箱
	int j = 0;
	PNode p = L, q;
	ofstream ofdraft("draftbuffer.txt");
	ofdraft.clear();//清空草稿箱

	while (p->prior  != L) {//遍历链表
		p = p->prior ;
		j++;
		if ((p->Flag == 2)) {//删除链表里面草稿箱的某条信息
			if (j == i) {
				p->prior->next = p->next;
				p->next->prior = p->prior;
				q = p->prior;
				free(p);
				p = q;
			}
			else {
				ofdraft << p->Mess.Receiver << endl << p->Mess.News << endl << p->Mess.Sender << endl;	//除了删除节点,原来其他的草稿箱短信重新写入
			}
		}
	}
	ofdraft.close(); //写入草稿箱
	return 1;
}
void SendMessage(PNode &p, int s) {//用来将短信写入3个文件
	ofstream ofsend, ofreceive, ofdraft;
	if (s == 1) {
		ofsend.open("sendbuffer.txt", ios::app);
		ofreceive.open("receivebuffer.txt", ios::app);

		ofsend << (1900 + p->time.year) << "-" << (1 + p->time.mon) << "-" << p->time.mday << "  " << day[p->time.wday] << " ";
		ofsend << p->time.hour << ":" << p->time.min << ":" << p->time.sec << endl;
		ofsend << p->Mess.Receiver << endl << p->Mess.News << endl << p->Mess .Sender  << endl;

		ofreceive << (1900 + p->time.year) << "-" << (1 + p->time.mon) << "-" << p->time.mday << "  " << day[p->time.wday] << " ";
		ofreceive << p->time.hour << ":" << p->time.min << ":" << p->time.sec << endl;

		ofreceive << p->Mess.Sender << endl << p->Mess.News << endl << p->Mess.Receiver << endl;

		ofsend.close();
		ofreceive.close();//分别写入发件箱和收件箱
	}
	else if (s == 2)
	{
		ofdraft.open("draftbuffer.txt", ios::app);
		ofdraft << p->Mess.Receiver << endl << p->Mess.News << endl << p->Mess.Sender << endl;
		ofdraft.close(); //写入草稿箱
	}
}
void DraftToSendbuff(PNode L, int i) {//将草稿箱里的短信发送给发送箱
	int j = 0;
	PNode p = L;
	while (p->next != L) {//遍历链表输出发件箱内容
		p = p->next;
		j++;
		if ((p->Flag == 2) && (j == i)) {
			p->Flag = 1;//修改信息的状态,变为已发送状态
			SendMessage(p, 1);//写入发送箱中
			DelateDraftMessage(L, i);
		}
	}
}
string FindDraftMessage(PNode L, int i)
{
	string str;
	int j = 0;
	PNode p = L;
	while (p->next != L) {//遍历链表输出草稿箱内容
		p = p->next;
		if (p->Flag == 2) {
			j++;
			if (j == i) {
				str = p->Mess.News;
				//cout << "第" << i << "条短信内容为:" << p->Mess.News << endl;
			}
		}
	}
	return str;
}

SendMessage.h

#pragma once
#include"com_def.h"

int InitList(PNode &L) {//初始化链表(双向循环链表)
	L = (PNode)malloc(sizeof(Node));
	L->next = L;
	L->prior = L;

	fstream SendMessage;//将发送箱里面短信写入到链表里面
	SendMessage.open("sendbuffer.txt", ios::in);
	while (!SendMessage.eof())
	{
		PNode q = (PNode)malloc(sizeof(Node));
		//if (!q)
		//{
		//	cout << "Error!" << endl;
		//	return 0;
		//}//申请失败则提示错误
		SendMessage.getline(q->ShowTime, 80);//从草稿箱中分别读取年月日、周几、时分秒到信息结点
		if (!SendMessage.getline(q->Mess.Receiver, 80))
			break;//读出收件人的姓名,读到空行则结束
		if (!SendMessage.getline(q->Mess.News, 80))
			break;//读出发件人的信息,读到空行则结束
		if (!SendMessage.getline(q->Mess.Sender, 80))
			break;//读出收件人姓名,读到空行则结束

		q->Flag = 1;//由于是从发送箱中读取,故默认为1
		L->next->prior = q;//双向循环链表的建立
		q->next = L->next;
		q->prior = L;
		L->next = q;
	}
	SendMessage.close();

	fstream DraftMessage;//将草稿箱里面短信写入到链表里面
	DraftMessage.open("draftbuffer.txt", ios::in);
	while (!DraftMessage.eof())
	{
		PNode q = (PNode)malloc(sizeof(Node));
		//if (!q)
		//{
		//	cout << "Error!" << endl;
		//	return 0;
		//}//申请失败则提示错误
		DraftMessage.getline(q->ShowTime, 80);//从草稿箱中分别读取年月日、周几、时分秒到信息结点
		if (!DraftMessage.getline(q->Mess.Receiver, 80))
			break;//读出收件人的姓名,读到空行则结束
		if (!DraftMessage.getline(q->Mess.News, 80))
			break;//读出发件人的信息,读到空行则结束
		if (!DraftMessage.getline(q->Mess.Sender, 80))
			break;//读出收件人姓名,读到空行则结束

		q->Flag = 2;//由于是从草稿箱中读取,故默认为2
		L->next->prior = q;//双向循环链表的建立
		q->next = L->next;
		q->prior = L;
		L->next = q;
	}
	DraftMessage.close();

	return 1;
}

resource.h

//{{NO_DEPENDENCIES}}
// Microsoft Visual C++ 生成的包含文件。
// 供 手机短信通信系统.rc 使用
//
#define IDM_ABOUTBOX                    0x0010
#define IDD_ABOUTBOX                    100
#define IDS_ABOUTBOX                    101
#define IDD_MY_DIALOG                   102
#define IDR_MAINFRAME                   128
#define IDD_DIALOG1                     130
#define IDD_DIALOG2                     131
#define IDD_DIALOG3                     132
#define IDD_DIALOG4                     133
#define IDI_ICON1                       139
#define IDC_TAB1                        1000
#define IDC_EDIT1                       1001
#define IDC_EDIT2                       1002
#define IDC_EDIT3                       1003
#define IDC_BUTTON1                     1004
#define IDC_BUTTON2                     1005
#define IDC_BUTTON3                     1006
#define IDC_RADIO1                      1007
#define IDC_RADIO2                      1008
#define IDC_RADIO3                      1009
#define IDC_RADIO4                      1010
#define IDC_LIST1                       1011
#define IDC_DATETIMEPICKER1             1012

// Next default values for new objects
// 
#ifdef APSTUDIO_INVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_NEXT_RESOURCE_VALUE        140
#define _APS_NEXT_COMMAND_VALUE         32771
#define _APS_NEXT_CONTROL_VALUE         1017
#define _APS_NEXT_SYMED_VALUE           101
#endif
#endif

ReceiveMessage.h

#pragma once
#include"com_def.h"
int ReadMessage(PNode &L, string receive)//建立
{
	const char* str1 = receive.c_str();

	fstream ReadMessage;
	//PNode ptr;
	L = (PNode)malloc(sizeof(Node));
	L->next = L;
	L->prior = L;
	ReadMessage.open("receivebuffer.txt", ios::in);
	while (!ReadMessage.eof())
	{
		PNode ptr = (PNode)malloc(sizeof(Node));
		if (!ReadMessage.getline(ptr->Mess.Sender, 80))
			break;//读出发件人的姓名,读到空行则结束
		if (!ReadMessage.getline(ptr->Mess.News, 80))
			break;//读出发件人的信息,读到空行则结束
		if (!ReadMessage.getline(ptr->Mess.Receiver, 80))
			break;//读出收件人姓名,读到空行则结束
		if (!strcmp(ptr->Mess.Receiver, str1))//收件箱中的收件人与本ID相同时,才链入链表
		{
			ptr->next = L->next;//双向循环链表的建立
			L->next->prior = ptr;
			ptr->prior = L;
			L->next = ptr;
			ptr->Flag = 0;//设置flag为0表示未读
		}
		//else
		//{
		//	free(ptr);//不相等,则释放读取的废弃结点
		//}
	}
	ReadMessage.close();
	return 0;
}

int DeleteMessage(PNode &L, int i) {//清空收件箱,将链表重新写入草稿箱
	int j = 0;
	PNode p = L, q;
	ofstream WriteFile("receivebuffer.txt");
	WriteFile.clear();//清空收件箱

	while (p->next != L) {//遍历链表
		p = p->next;
		j++;
		if (j == i) {
			p->prior->next = p->next;
			p->next->prior = p->prior;
			q = p->prior;
			free(p);
			p = q;
		}
		else {
			WriteFile << p->Mess.Sender << endl << p->Mess.News << endl << p->Mess.Receiver << endl;	//除了删除节点,原来其他的草稿箱短信重新写入
		}
	}
	WriteFile.close();
	return 1;
}
string  ReadOneMessage(PNode &head, int choice)//查找某条短信,同时标为已读
{
	int i = 0;
	PNode p;
	p = head;
	while (i < choice  && p->next != head)
	{
		p = p->next;
		i++;
	}
	if (i == choice)//退出循环时i 和choice 相等则查找到信息并且输出信息
	{
		p->Flag = 1;
	}
	return p->Mess.News;
}

Dialog4.h

#pragma once
#include "afxwin.h"

// CDialog4 对话框

class CDialog4 : public CDialogEx
{
	DECLARE_DYNAMIC(CDialog4)

public:
	CDialog4(CWnd* pParent = NULL);   // 标准构造函数
	virtual ~CDialog4();

	// 对话框数据
#ifdef AFX_DESIGN_TIME
	enum { IDD = IDD_DIALOG4 };
#endif

protected:
	virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV 支持

	DECLARE_MESSAGE_MAP()
public:
	afx_msg void OnBnClickedButton2();
	afx_msg void OnBnClickedButton1();
	int m_nRadio;
	afx_msg void OnBnClickedRadio2();
	afx_msg void OnBnClickedRadio1();
	afx_msg void OnEnChangeEdit1();
	CEdit m_edit;
	afx_msg HBRUSH OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor);
};

Dialog4.cpp

// Dialog4.cpp : 实现文件
//

#include "stdafx.h"
#include "手机短信通信系统.h"
#include "Dialog4.h"
#include "afxdialogex.h"
#include"ReceiveMessage.h"

// CDialog4 对话框

IMPLEMENT_DYNAMIC(CDialog4, CDialogEx)
PNode head;
CDialog4::CDialog4(CWnd* pParent /*=NULL*/)
	: CDialogEx(IDD_DIALOG4, pParent)
	, m_nRadio(0)
{
}

CDialog4::~CDialog4()
{
}

void CDialog4::DoDataExchange(CDataExchange* pDX)
{
	CDialogEx::DoDataExchange(pDX);
	DDX_Control(pDX, IDC_EDIT1, m_edit);
}

BEGIN_MESSAGE_MAP(CDialog4, CDialogEx)
	ON_BN_CLICKED(IDC_BUTTON2, &CDialog4::OnBnClickedButton2)
	ON_BN_CLICKED(IDC_BUTTON1, &CDialog4::OnBnClickedButton1)
	ON_BN_CLICKED(IDC_RADIO2, &CDialog4::OnBnClickedRadio2)
	ON_BN_CLICKED(IDC_RADIO1, &CDialog4::OnBnClickedRadio1)
	ON_EN_CHANGE(IDC_EDIT1, &CDialog4::OnEnChangeEdit1)
	ON_WM_CTLCOLOR()
END_MESSAGE_MAP()

// CDialog4 消息处理程序

void CDialog4::OnBnClickedButton2()
{
	// TODO: 在此添加控件通知处理程序代码
	CString str;
	GetDlgItem(IDC_EDIT3)->GetWindowText(str);//获取收件人名字
	ReadMessage(head, CStringA(str).GetString());//建立链表
	
	CString str1, str2;
	PNode q;
	int i = 0;
	q = head;
	while (q->next != head)//遍历双向循环链表,读出信息时给信息添加序号显示到屏幕上
						   //同时将结构体内的flag设为1标为已读
	{
		q = q->next;
		str1.Format("%d", ++i);
		str2 += str1;
		str2 += " . ";
		str2 += "发件人:";
		str2 += q->Mess.Sender;
		/*if (q->Flag == 0)
		{
			str2 += "\t未读";
		}
		else
		{
			str2+= "\t已读";
		}*/
		str2 += "\r\n";
		//cout << ++i << ". 发件人: " << q->Mess.Sender << " 发送信息: " << q->Mess.News << endl;
		GetDlgItem(IDC_EDIT1)->SetWindowText(str2);	//设置信息框中的内容
	}
	if (str == "")
	{
		i = -1;
		MessageBox("收件人不能为空");
	}
	if (!i)
	{
		MessageBox("收件箱为空");
		GetDlgItem(IDC_EDIT1)->SetWindowText("");	//设置信息框中的内容
	}
	
}

void CDialog4::OnBnClickedButton1()
{
	// TODO: 在此添加控件通知处理程序代码

	CString str;
	string str1;
	int i;
	if (m_nRadio == 1)
	{
		GetDlgItem(IDC_EDIT2)->GetWindowTextA(str);
		i = _ttoi(str);
		str1 = ReadOneMessage(head, i);
		str = str1.c_str();
		GetDlgItem(IDC_EDIT1)->SetWindowText(str);
	}
	else if (m_nRadio == 2)
	{
		GetDlgItem(IDC_EDIT2)->GetWindowTextA(str);
		i = _ttoi(str);
		DeleteMessage(head, i);
	}
}

void CDialog4::OnBnClickedRadio2()
{
	// TODO: 在此添加控件通知处理程序代码
	m_nRadio = 2;
}

void CDialog4::OnBnClickedRadio1()
{
	// TODO: 在此添加控件通知处理程序代码
	m_nRadio = 1;
}

void CDialog4::OnEnChangeEdit1()
{
	// TODO:  如果该控件是 RICHEDIT 控件,它将不
	// 发送此通知,除非重写 CDialogEx::OnInitDialog()
	// 函数并调用 CRichEditCtrl().SetEventMask(),
	// 同时将 ENM_CHANGE 标志“或”运算到掩码中。

	// TODO:  在此添加控件通知处理程序代码
}

HBRUSH CDialog4::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
	HBRUSH hbr = CDialogEx::OnCtlColor(pDC, pWnd, nCtlColor);

	// TODO:  在此更改 DC 的任何特性
	//if (pWnd->GetDlgCtrlID() == IDC_EDIT1)
	//{
	//	if (nCtlColor == CTLCOLOR_EDIT)
	//		pDC->SetTextColor(RGB(255, 0, 0));     //设置文本颜色为红色
	//	//else if(nCtlColor == CTLCOLOR_EDIT&&flag == 1)
	//	//	pDC->SetTextColor(RGB(255,255,255));     //设置文本颜色为黑色
	//}
	// TODO:  如果默认的不是所需画笔,则返回另一个画笔
	return hbr;
}

Dialog3.h

#pragma once

// CDialog3 对话框

class CDialog3 : public CDialogEx
{
	DECLARE_DYNAMIC(CDialog3)

public:
	CDialog3(CWnd* pParent = NULL);   // 标准构造函数
	virtual ~CDialog3();

	// 对话框数据
#ifdef AFX_DESIGN_TIME
	enum { IDD = IDD_DIALOG3 };
#endif

protected:
	virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV 支持

	DECLARE_MESSAGE_MAP()
public:
	int m_nRadio;
	afx_msg void OnBnClickedRadio1();
	afx_msg void OnBnClickedRadio2();
	afx_msg void OnBnClickedButton2();
	afx_msg void OnBnClickedButton1();
};

Dialog3.cpp

// Dialog3.cpp : 实现文件
//

#include "stdafx.h"
#include "手机短信通信系统.h"
#include "Dialog3.h"
#include "afxdialogex.h"
#include"SendMessage2.h"

// CDialog3 对话框
PNode L2;
IMPLEMENT_DYNAMIC(CDialog3, CDialogEx)

CDialog3::CDialog3(CWnd* pParent /*=NULL*/)
	: CDialogEx(IDD_DIALOG3, pParent)
	, m_nRadio(0)
{
}

CDialog3::~CDialog3()
{
}

void CDialog3::DoDataExchange(CDataExchange* pDX)
{
	CDialogEx::DoDataExchange(pDX);
}

BEGIN_MESSAGE_MAP(CDialog3, CDialogEx)
	ON_BN_CLICKED(IDC_RADIO1, &CDialog3::OnBnClickedRadio1)
	ON_BN_CLICKED(IDC_RADIO2, &CDialog3::OnBnClickedRadio2)
	ON_BN_CLICKED(IDC_BUTTON2, &CDialog3::OnBnClickedButton2)
	ON_BN_CLICKED(IDC_BUTTON1, &CDialog3::OnBnClickedButton1)
END_MESSAGE_MAP()

// CDialog3 消息处理程序

void CDialog3::OnBnClickedRadio1()
{
	// TODO: 在此添加控件通知处理程序代码
	m_nRadio = 1;
}

void CDialog3::OnBnClickedRadio2()
{
	// TODO: 在此添加控件通知处理程序代码
	m_nRadio = 2;
}

void CDialog3::OnBnClickedButton2()
{
	// TODO: 在此添加控件通知处理程序代码
	InitList2(L2);//建立链表
	CString str, str1;
	PNode p = L2;
	int i = 0;

	while (p->next != L2) {//遍历链表输出发件箱内容
		p = p->next;
		if (p->Flag == 1)
		{
			str1.Format("%d", ++i);
			str += str1;
			str += " . ";
			str += "收件人:";
			str += p->Mess.Receiver;
			str += "\r\n";
		}
		GetDlgItem(IDC_EDIT1)->SetWindowText(str);	//设置信息框中的内容
	}
	if (!i)
	{
		MessageBox("发件箱为空");
		GetDlgItem(IDC_EDIT1)->SetWindowText("");	//设置信息框中的内容
	}
}

void CDialog3::OnBnClickedButton1()
{
	// TODO: 在此添加控件通知处理程序代码
	CString str;
	string str1;
	int i;
	if (m_nRadio == 1)
	{
		GetDlgItem(IDC_EDIT2)->GetWindowTextA(str);
		i = _ttoi(str);
		str1 = FindSendMessage(L2, i);
		str = str1.c_str();
		GetDlgItem(IDC_EDIT1)->SetWindowText(str);
	}
	else if (m_nRadio == 2)
	{
		GetDlgItem(IDC_EDIT2)->GetWindowTextA(str);
		i = _ttoi(str);
		DelateSendMessage(L2, i);
	}
}

Dialog2.h

#pragma once

// CDialog2 对话框

class CDialog2 : public CDialogEx
{
	DECLARE_DYNAMIC(CDialog2)

public:
	CDialog2(CWnd* pParent = NULL);   // 标准构造函数
	virtual ~CDialog2();

	// 对话框数据
#ifdef AFX_DESIGN_TIME
	enum { IDD = IDD_DIALOG2 };
#endif

protected:
	virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV 支持

	DECLARE_MESSAGE_MAP()
public:
	afx_msg void OnBnClickedButton2();
	int m_nRadio;
	afx_msg void OnBnClickedRadio1();
	afx_msg void OnBnClickedRadio2();
	afx_msg void OnBnClickedRadio3();
	afx_msg void OnBnClickedRadio4();
	afx_msg void OnBnClickedButton1();
};

Dialog2.cpp

// Dialog2.cpp : 实现文件
//

#include "stdafx.h"
#include "手机短信通信系统.h"
#include "Dialog2.h"
#include "afxdialogex.h"
#include "SendMessage1.h"

// CDialog2 对话框

IMPLEMENT_DYNAMIC(CDialog2, CDialogEx)
PNode L1;

CDialog2::CDialog2(CWnd* pParent /*=NULL*/)
	: CDialogEx(IDD_DIALOG2, pParent)
	, m_nRadio(0)
{
}

CDialog2::~CDialog2()
{
}

void CDialog2::DoDataExchange(CDataExchange* pDX)
{
	CDialogEx::DoDataExchange(pDX);
}

BEGIN_MESSAGE_MAP(CDialog2, CDialogEx)
	ON_BN_CLICKED(IDC_BUTTON2, &CDialog2::OnBnClickedButton2)
	ON_BN_CLICKED(IDC_RADIO1, &CDialog2::OnBnClickedRadio1)
	ON_BN_CLICKED(IDC_RADIO2, &CDialog2::OnBnClickedRadio2)
	ON_BN_CLICKED(IDC_RADIO3, &CDialog2::OnBnClickedRadio3)
	ON_BN_CLICKED(IDC_RADIO4, &CDialog2::OnBnClickedRadio4)
	ON_BN_CLICKED(IDC_BUTTON1, &CDialog2::OnBnClickedButton1)
END_MESSAGE_MAP()

// CDialog2 消息处理程序

void CDialog2::OnBnClickedButton2()
{
	// TODO: 在此添加控件通知处理程序代码
	InitList1(L1);//建立链表
	CString str, str1;
	PNode p = L1;
	int i = 0;

	while (p->prior != L1) {//遍历链表输出草稿箱内容
		p = p->prior ;
		if (p->Flag == 2)
		{
			str1.Format("%d", ++i);
			str += str1;
			str += " . ";
			str += "收件人:";
			str += p->Mess.Receiver;
			str += "\r\n";
		}
		GetDlgItem(IDC_EDIT1)->SetWindowText(str);	//设置信息框中的内容
	}
	if (!i)
	{
		MessageBox("草稿箱信息为空");
		GetDlgItem(IDC_EDIT1)->SetWindowText("");	//设置信息框中的内容
	}
}

void CDialog2::OnBnClickedRadio1()
{
	// TODO: 在此添加控件通知处理程序代码
	m_nRadio = 1;
}

void CDialog2::OnBnClickedRadio2()
{
	// TODO: 在此添加控件通知处理程序代码
	m_nRadio = 2;
}

void CDialog2::OnBnClickedRadio3()
{
	// TODO: 在此添加控件通知处理程序代码
	m_nRadio = 3;
}

void CDialog2::OnBnClickedRadio4()
{
	// TODO: 在此添加控件通知处理程序代码
	m_nRadio = 4;
}

void CDialog2::OnBnClickedButton1()
{
	// TODO: 在此添加控件通知处理程序代码
	CString str;
	string str1;
	int i;
	if (m_nRadio == 1)
	{
		GetDlgItem(IDC_EDIT2)->GetWindowTextA(str);
		i = _ttoi(str);
		DraftToSendbuff(L1, i);
	}
	else if (m_nRadio == 2)
	{
		GetDlgItem(IDC_EDIT2)->GetWindowTextA(str);
		i = _ttoi(str);
		DelateDraftMessage(L1, i);
	}
	else if (m_nRadio == 3)
	{
		GetDlgItem(IDC_EDIT2)->GetWindowTextA(str);
		i = _ttoi(str);
		str1 = FindDraftMessage(L1, i);
		str = str1.c_str();
		GetDlgItem(IDC_EDIT1)->SetWindowText(str);
	}
}

Dialog1.h

#pragma once

// CDialog1 对话框

class CDialog1 : public CDialog
{
	DECLARE_DYNAMIC(CDialog1)

public:
	CDialog1(CWnd* pParent = NULL);   // 标准构造函数
	virtual ~CDialog1();

	// 对话框数据
#ifdef AFX_DESIGN_TIME
	enum { IDD = IDD_DIALOG1 };
#endif

protected:
	virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV 支持

	DECLARE_MESSAGE_MAP()
public:
	afx_msg void OnBnClickedButton1();
	afx_msg void OnBnClickedButton2();
	afx_msg void OnBnClickedButton3();
};

Dialog1.cpp

// Dialog1.cpp : 实现文件
//

#include "stdafx.h"
#include "手机短信通信系统.h"
#include "Dialog1.h"
#include "afxdialogex.h"
#include"SendMessage.h"

// CDialog1 对话框

IMPLEMENT_DYNAMIC(CDialog1, CDialog)
PNode L;


CDialog1::CDialog1(CWnd* pParent /*=NULL*/)
	: CDialog(IDD_DIALOG1, pParent)
{
	InitList(L);//建立链表
}

CDialog1::~CDialog1()
{
}

void CDialog1::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
}

BEGIN_MESSAGE_MAP(CDialog1, CDialog)
	ON_BN_CLICKED(IDC_BUTTON1, &CDialog1::OnBnClickedButton1)
	ON_BN_CLICKED(IDC_BUTTON2, &CDialog1::OnBnClickedButton2)
	ON_BN_CLICKED(IDC_BUTTON3, &CDialog1::OnBnClickedButton3)
END_MESSAGE_MAP()

// CDialog1 消息处理程序

void CDialog1::OnBnClickedButton1()
{
	// TODO: 在此添加控件通知处理程序代码
	int flag = 0;
	CString str;
	ofstream ofdraft;
	PNode q = (PNode)malloc(sizeof(Node));
	q->Flag = 2;//因为是存入草稿箱,所以默认为2;

	GetDlgItem(IDC_EDIT1)->GetWindowText(str);//写入短信
	if (str != "")
	{
		strcpy_s(q->Mess.News, CStringA(str).GetString());
	}
	else
	{
		flag = 1;
		MessageBox("消息不能为空");
	}

	GetDlgItem(IDC_EDIT2)->GetWindowText(str);//写入发件人
	if (str != "")
	{
		strcpy_s(q->Mess.Sender, CStringA(str).GetString());
	}
	else
	{
		flag = 1;
		MessageBox("发件人不能为空");
	}

	GetDlgItem(IDC_EDIT3)->GetWindowText(str);//写入收件人
	if (str != "")
	{
		strcpy_s(q->Mess.Receiver, CStringA(str).GetString());
	}
	else
	{
		flag = 1;
		MessageBox("收件人不能为空");
	}
	if (flag != 1)
	{
		ofdraft.open("draftbuffer.txt", ios::app);
		ofdraft << q->Mess.Receiver << endl << q->Mess.News << endl << q->Mess.Sender << endl;
		ofdraft.close(); //写入草稿箱

		L->next->prior = q;//插入双向循环链表
		q->next = L->next;
		q->prior = L;
		L->next = q;
	}
	GetDlgItem(IDC_EDIT1)->SetWindowText("");//清空编辑框
	GetDlgItem(IDC_EDIT2)->EnableWindow(false);//锁定发件人
	//GetDlgItem(IDC_EDIT3)->EnableWindow(true);//锁定收件人
}

void CDialog1::OnBnClickedButton2()
{
	// TODO: 在此添加控件通知处理程序代码
	CString str;
	int flag = 0;
	ofstream ofsend, ofreceive;
	PNode q = (PNode)malloc(sizeof(Node));
	q->Flag = 1;//因为是存入发件箱,所以默认为1;

	GetDlgItem(IDC_EDIT1)->GetWindowText(str);//写入短信
	if (str != "")
	{
		strcpy_s(q->Mess.News, CStringA(str).GetString());
	}
	else
	{
		flag = 1;
		MessageBox("消息不能为空");
	}

	GetDlgItem(IDC_EDIT2)->GetWindowText(str);//写入发件人
	if (str != "")
	{
		strcpy_s(q->Mess.Sender, CStringA(str).GetString());
	}
	else
	{
		flag = 1;
		MessageBox("发件人不能为空");
	}

	GetDlgItem(IDC_EDIT3)->GetWindowText(str);//写入收件人
	if (str != "")
	{
		strcpy_s(q->Mess.Receiver, CStringA(str).GetString());
	}
	else
	{
		flag = 1;
		MessageBox("收件人不能为空");
	}
	if (flag != 1) {
		ofsend.open("sendbuffer.txt", ios::app);
		ofsend << q->Mess.Receiver << endl << q->Mess.News << endl << q->Mess.Sender << endl;
		ofsend.close(); //写入发件箱
		ofreceive.open("receivebuffer.txt", ios::app);
		ofreceive << q->Mess.Sender << endl << q->Mess.News << endl << q->Mess.Receiver << endl;
		ofreceive.close();//写入收件箱

		L->next->prior = q;//插入双向循环链表
		q->next = L->next;
		q->prior = L;
		L->next = q;
	}
	GetDlgItem(IDC_EDIT1)->SetWindowText("");//清空编辑框
	GetDlgItem(IDC_EDIT2)->EnableWindow(false);//锁定发件人
	//GetDlgItem(IDC_EDIT3)->EnableWindow(true);//锁定收件人
}

void CDialog1::OnBnClickedButton3()
{
	GetDlgItem(IDC_EDIT3)->SetWindowText("");//清空编辑框
	GetDlgItem(IDC_EDIT2)->EnableWindow(true);//解锁发件人
	// TODO: 在此添加控件通知处理程序代码
}

com_def.h

#pragma once
#include"stdafx.h"
#include<iostream>
#include<fstream>
#include<string>
#include<stdlib.h>
#include<cstdio>
#include<time.h>
#include<ctime>
using namespace std;
typedef struct Message {
	char Receiver[10];
	char News[30];
	char Sender[10];
}Message;
typedef struct Time
{
	int sec;  /*秒,正常范围0-59, 但允许至61*/
	int min;  /*分钟,0-59*/
	int hour; /*小时, 0-23*/
	int mday; /*日,即一个月中的第几天,1-31*/
	int mon;  //月, 从一月算起,0-11 1+p->tm_mon;
	int year;  //年, 从1900至今已经多少年 1900+ p->tm_year;
	int wday; /*星期,一周中的第几天, 从星期日算起,0-6*/
}Time;

typedef struct Node {
	int Flag;	//在发送信息时标志草稿箱或者发件箱的短信,在收件箱标志已读未读
	Message Mess;//短信的结构体
	char ShowTime[30];//从文件读取的时间的字符数组
	struct Time time;//存储时间的结构体
	struct Node *prior;//双向循环链表的前驱指针
	struct Node *next;//后继指针
}Node, *PNode;

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

邪三一

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值