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

📄 bookfrienddlg.cpp

📁 书友会短信发送系统由基础信息模块、短信管理模块、短信投票模块、系统管理模块等几部分组成。
💻 CPP
字号:
// BookFriendDlg.cpp : implementation file
//

#include "stdafx.h"
#include "BookFriend.h"
#include "BookFriendDlg.h"
#include "NoteSet.h"
#include "Associator.h"
#include "Often.h"
#include "SendNote.h"
#include "QuerySend.h"
#include "RecvNote.h"
#include "Item.h"
#include "Count.h"
#include "User.h"
#include "Iitialize.h"
#include "ADOConn.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
extern CString UserName;
/////////////////////////////////////////////////////////////////////////////
// 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()

/////////////////////////////////////////////////////////////////////////////
// CBookFriendDlg dialog

CBookFriendDlg::CBookFriendDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CBookFriendDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CBookFriendDlg)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void CBookFriendDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CBookFriendDlg)
		// NOTE: the ClassWizard will add DDX and DDV calls here
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CBookFriendDlg, CDialog)
	//{{AFX_MSG_MAP(CBookFriendDlg)
	ON_WM_SYSCOMMAND()
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_WM_TIMER()
	ON_COMMAND(ID_MENUSET, OnMenuset)
	ON_COMMAND(ID_MENUASSOCIATOR, OnMenuassociator)
	ON_COMMAND(ID_MENUOFTEN, OnMenuoften)
	ON_COMMAND(ID_MENUSEND, OnMenusend)
	ON_COMMAND(ID_MENURECV, OnMenurecv)
	ON_COMMAND(ID_MENUITEM, OnMenuitem)
	ON_COMMAND(ID_MENUCOUNT, OnMenucount)
	ON_COMMAND(ID_MENUUSER, OnMenuuser)
	ON_COMMAND(ID_MENUCLEAR, OnMenuclear)
	ON_COMMAND(ID_MENUEXIT, OnMenuexit)
	ON_COMMAND(ID_MENUQUERY, OnMenuquery)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CBookFriendDlg message handlers

BOOL CBookFriendDlg::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_ImageList.Create(32,32,ILC_COLOR24|ILC_MASK,1,1);
	//向图像列表中添加图标
	m_ImageList.Add(AfxGetApp()->LoadIcon(IDI_ICON1));
	m_ImageList.Add(AfxGetApp()->LoadIcon(IDI_ICON2));
	m_ImageList.Add(AfxGetApp()->LoadIcon(IDI_ICON3));
	m_ImageList.Add(AfxGetApp()->LoadIcon(IDI_ICON4));
	m_ImageList.Add(AfxGetApp()->LoadIcon(IDI_ICON5));
	m_ImageList.Add(AfxGetApp()->LoadIcon(IDI_ICON6));
	m_ImageList.Add(AfxGetApp()->LoadIcon(IDI_ICON7));
	m_ToolBar.CreateEx(this, TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE | CBRS_TOP   
		| CBRS_TOOLTIPS |CBRS_FLYBY | CBRS_SIZE_DYNAMIC);
	//关联图像列表
	m_ToolBar.GetToolBarCtrl().SetImageList(&m_ImageList);
	m_ToolBar.SetButtons(NULL, 9); //共9个按钮
	// 设置每个工具按钮文字
	m_ToolBar.SetButtonInfo(0, ID_MENUSET, TBSTYLE_BUTTON, 0);
	m_ToolBar.SetButtonText(0, "短信猫设置");
	m_ToolBar.SetButtonInfo(1, ID_MENUASSOCIATOR, TBSTYLE_BUTTON , 1);
	m_ToolBar.SetButtonText(1, "会员信息");
	m_ToolBar.SetButtonInfo(2, ID_MENUOFTEN, TBSTYLE_BUTTON, 2);
	m_ToolBar.SetButtonText(2, "常用语设置");
	m_ToolBar.SetButtonInfo(3, ID_SEPARATOR, TBBS_SEPARATOR,2);
	m_ToolBar.SetButtonInfo(4, ID_MENUSEND, TBSTYLE_BUTTON , 3);
	m_ToolBar.SetButtonText(4, "发送短信");
	m_ToolBar.SetButtonInfo(5, ID_MENURECV, TBSTYLE_BUTTON , 4);
	m_ToolBar.SetButtonText(5, "接收短信");
	m_ToolBar.SetButtonInfo(6, ID_SEPARATOR, TBBS_SEPARATOR,4);
	m_ToolBar.SetButtonInfo(7, ID_MENUUSER, TBSTYLE_BUTTON, 5);
	m_ToolBar.SetButtonText(7, "用户管理");
	m_ToolBar.SetButtonInfo(8, ID_MENUEXIT, TBSTYLE_BUTTON, 6);
	m_ToolBar.SetButtonText(8, "退出系统");
	m_ToolBar.SetSizes(CSize(70,60), CSize(32,32)); //设置按钮的大小
	
	UINT array[3];
	for(int i=0;i<3;i++)
	{
		array[i] = 1010 + i;
	}
	m_StatusBar.Create(this); //创建状态栏窗口
	m_StatusBar.SetIndicators(array,sizeof(array)/sizeof(UINT)); //添加面板
	CRect rect;
	GetClientRect(rect);
	for(int n=0;n<3;n++)
	{
		m_StatusBar.SetPaneInfo(n,array[n],0,rect.Width()/3); //设置面板宽度
	}
	CTime time = CTime::GetCurrentTime();
	m_StatusBar.SetPaneText(0,"当前用户:"+UserName);//设置面板文本
	m_StatusBar.SetPaneText(1,"当前日期:"+time.Format("%Y-%m-%d"));
	m_StatusBar.SetPaneText(2,"书友会短信发送管理系统  http://www.mrbccd.com ");
	//显示工具栏窗口
	RepositionBars(AFX_IDW_CONTROLBAR_FIRST,AFX_IDW_CONTROLBAR_LAST,0);

	CString port,baud,merid,accredit,isnum;
	char buf[129];
	GetPrivateProfileString("短信猫设置","端口号","default",buf,128,"./NoteSet.ini");
	port.Format("%s",buf);
	GetPrivateProfileString("短信猫设置","波特率","default",buf,128,"./NoteSet.ini");
	baud.Format("%s",buf);
	GetPrivateProfileString("短信猫设置","机器号码","default",buf,128,"./NoteSet.ini");
	merid.Format("%s",buf);
	GetPrivateProfileString("短信猫设置","授权号码","default",buf,128,"./NoteSet.ini");
	accredit.Format("%s",buf);
	GetPrivateProfileString("短信猫设置","是否设置","default",buf,128,"./NoteSet.ini");
	isnum.Format("%s",buf);
	if(isnum == "1")
	{
		if(GSMModemInitNew((char*)(LPCTSTR)port,(char*)(LPCTSTR)baud,
			NULL,NULL,FALSE,(char*)(LPCTSTR)accredit)==FALSE)
		{
			MessageBox((char*)GSMModemGetErrorMsg());

		}
	}

	SetTimer(1,500,NULL); //设置定时器
	return TRUE;  // return TRUE  unless you set the focus to a control
}

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

void CBookFriendDlg::OnTimer(UINT nIDEvent) 
{
	// TODO: Add your message handler code here and/or call default
	CString sText,sleft,sright;
	int len;
	sText  = m_StatusBar.GetPaneText(2); //获得状态栏第3个面板的显示字符
	len    = sText.GetLength();			
	sright = sText.Left(2);
	sleft  = sText.Right(len-2);
	sText  = sleft + sright;
	m_StatusBar.SetPaneText(2,sText); //设置状态栏第3个面板的显示字符

	CString port,baud,merid,accredit,isnum;
	char buf[129];
/*	GetPrivateProfileString("短信猫设置","端口号","default",buf,128,"./NoteSet.ini");
	port.Format("%s",buf);
	GetPrivateProfileString("短信猫设置","波特率","default",buf,128,"./NoteSet.ini");
	baud.Format("%s",buf);
	GetPrivateProfileString("短信猫设置","机器号码","default",buf,128,"./NoteSet.ini");
	merid.Format("%s",buf);
	GetPrivateProfileString("短信猫设置","授权号码","default",buf,128,"./NoteSet.ini");
	accredit.Format("%s",buf);*/
	GetPrivateProfileString("短信猫设置","是否设置","default",buf,128,"./NoteSet.ini");
	isnum.Format("%s",buf);
	if(isnum == "1")
	{
/*		if(GSMModemInitNew((char*)(LPCTSTR)port,(char*)(LPCTSTR)baud,
			NULL,NULL,FALSE,(char*)(LPCTSTR)accredit)==FALSE)
		{
			MessageBox((char*)GSMModemGetErrorMsg());
			return; 
		}*/
		char* reData;
		char number[30],msgContent[512]; //电话号码,短信内容
		//获取接收的所有数据
		reData = (char*)GSMModemSMSReadAll(0);
		if (reData != NULL)
		{
			//获取所有短信内容的总长度
			int allDataLen = strlen(reData);
			int num = 0,content = 0;
			int once = 0 ; //接收完一个电话号码和一条短信
			for(int i=0;i<allDataLen;i++)
			{
				if(reData[i] == '|')
				{
					once+=1;
				}
				if(once == 0)
				{
					number[num] = reData[i];
					num++;
				}
				else if(once==1 && reData[i]!='|')
				{
					msgContent[content] = reData[i];
					content++;
				}
				if(once==3 && reData[i-1]=='|')
				{
					number[num]         = '\0';
					msgContent[content] = '\0';
					CString strPhone,strNote;
					strPhone.Format("%s",number);
					strNote.Format("%s",msgContent);
					CString phone = strPhone.Right(11);
					CString note  = strNote;
					CTime time = CTime::GetCurrentTime();
					if(note.Left(2) == "TP")
					{
						CString sql,item,result;
						item   = note.Mid(3,7);
						result = note.Right(1);
						sql.Format("insert into tb_ballot(手机号码,项目编号,\
							项目回复,投票时间) values ('%s','%s','%s','%s')",phone,
							item,result,time.Format("%y-%m-%d %H:%M:%S"));
						ADOConn m_ADOConn;
						m_ADOConn.OnInitADOConn();
						m_ADOConn.ExecuteSQL((_bstr_t)sql);
						m_ADOConn.ExitConnect();
					}
					else
					{
						CString sql;
						sql.Format("insert into tb_recv (接收电话,短信内容,\
							接收时间) values ('%s','%s','%s')",phone,note,
							time.Format("%y-%m-%d %H:%M:%S"));
						ADOConn m_ADOConn;
						m_ADOConn.OnInitADOConn();
						m_ADOConn.ExecuteSQL((_bstr_t)sql);
						m_ADOConn.ExitConnect();
					}
					break;
				}
			}
//		GSMModemRelease();
		}
	}
	CDialog::OnTimer(nIDEvent);
}

void CBookFriendDlg::OnMenuset() 
{
	// TODO: Add your command handler code here
	CNoteSet dlg;
	dlg.DoModal();
}

void CBookFriendDlg::OnMenuassociator() 
{
	// TODO: Add your command handler code here
	CAssociator dlg;
	dlg.DoModal();
}

void CBookFriendDlg::OnMenuoften() 
{
	// TODO: Add your command handler code here
	COften dlg;
	dlg.DoModal();
}

void CBookFriendDlg::OnMenusend() 
{
	// TODO: Add your command handler code here
	CSendNote dlg;
	dlg.DoModal();
}

void CBookFriendDlg::OnMenurecv() 
{
	// TODO: Add your command handler code here
	CRecvNote dlg;
	dlg.DoModal();
}

void CBookFriendDlg::OnMenuitem() 
{
	// TODO: Add your command handler code here
	CItem dlg;
	dlg.DoModal();
}

void CBookFriendDlg::OnMenucount() 
{
	// TODO: Add your command handler code here
	CCount dlg;
	dlg.DoModal();
}

void CBookFriendDlg::OnMenuuser() 
{
	// TODO: Add your command handler code here
	CUser dlg;
	dlg.DoModal();
}

void CBookFriendDlg::OnMenuclear() 
{
	// TODO: Add your command handler code here
	CIitialize dlg;
	dlg.DoModal();
}

void CBookFriendDlg::OnMenuexit() 
{
	// TODO: Add your command handler code here
	CDialog::OnCancel();
}

void CBookFriendDlg::OnMenuquery() 
{
	// TODO: Add your command handler code here
	CQuerySend dlg;
	dlg.DoModal();
}

⌨️ 快捷键说明

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