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

📄 dlgtel.cpp

📁 通过GSM模块接收和发送短信的代码。在eVC4.0下编译通过
💻 CPP
字号:
// DlgTel.cpp : implementation file
//

#include "stdafx.h"
#include "PortPe.h"
#include "DlgTel.h"
extern CPortPeApp theApp;
#include "ComPort.h"
extern CComPort port;

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CDlgTel dialog


CDlgTel::CDlgTel(CWnd* pParent /*=NULL*/)
	: CDialog(CDlgTel::IDD, pParent)
{
	//{{AFX_DATA_INIT(CDlgTel)
	m_tel = _T("");
	m_tel1 = _T("");
	m_tel2 = _T("");
	//}}AFX_DATA_INIT
}


void CDlgTel::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CDlgTel)
	DDX_Control(pDX, IDC_EDIT1, m_edit);
	DDX_Control(pDX, IDC_PICTURE, m_pic);
	DDX_Text(pDX, IDC_EDIT1, m_tel);
	DDX_Text(pDX, IDC_EDIT2, m_tel1);
	DDX_Text(pDX, IDC_EDIT3, m_tel2);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CDlgTel, CDialog)
	//{{AFX_MSG_MAP(CDlgTel)
	ON_WM_CTLCOLOR()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CDlgTel message handlers

int CDlgTel::OnSendTalk() 
{
	// TODO: Add extra validation here
	try
	{
		UpdateData ();
		switch(iLocal)
		{
			case 1://手动拨号
				m_code=m_tel;
				bVTel=TRUE;
				break;
			case 2://常用号码1
				m_code=m_tel1;
				bVTel=FALSE;
				break;
			case 3://常用号码2
				m_code=m_tel2;
				bVTel=FALSE;
				break;
			default:
				MessageBox(TEXT("电话号码"),TEXT("系统提示信息"),MB_OK);
				return 0;
		}
		char s[128]="ATD\0";
		char temp[64]="\0";
		WideCharToMultiByte (CP_ACP,0,m_code,-1,temp,256,NULL,NULL);
		strcat(s,temp);
		strcat(s,";\r\0");
		port.LocalVoice (1);
		port.SetList (1,s);	
		
		return 0;
	}
	catch(...)
	{
		MessageBox(TEXT("你输入的电话号码非法"),TEXT("系统提示信息"),MB_OK);
		return 0;
	}
}

BOOL CDlgTel::OnInitDialog() 
{
	CDialog::OnInitDialog();
	
	// TODO: Add extra initialization here
	HBITMAP	hBk	=(HBITMAP)::LoadImage(AfxGetInstanceHandle(),MAKEINTRESOURCE(MAIN11),IMAGE_BITMAP, 0, 0, 0);	
	
	if(hBk!=NULL)
	{
		m_pic.SetBitmap(hBk);
	}

	iLocal=1;
	TCHAR str[64]=TEXT("\0");

	CEdit* pBoxOne;
	pBoxOne = (CEdit*) GetDlgItem (IDC_EDIT1);
	pBoxOne->SetWindowPos(NULL,0,0,150,20,SWP_NOMOVE|SWP_NOZORDER|SWP_NOOWNERZORDER);
	
	m_tel1=theApp.AppSetup.FIRST;
	pBoxOne = (CEdit*) GetDlgItem (IDC_EDIT2);
	pBoxOne->SetWindowPos(NULL,0,0,150,20,SWP_NOMOVE|SWP_NOZORDER|SWP_NOOWNERZORDER);

	m_tel2=theApp.AppSetup.SECOND;
	pBoxOne = (CEdit*) GetDlgItem (IDC_EDIT3);
	pBoxOne->SetWindowPos(NULL,0,0,150,20,SWP_NOMOVE|SWP_NOZORDER|SWP_NOOWNERZORDER);

	UpdateData (FALSE);

	bVTel=FALSE;
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

BOOL CDlgTel::PreTranslateMessage(MSG* pMsg) 
{
	if(WM_KEYDOWN == pMsg->message)
	{
		char temp[64]="\0";
		TCHAR swave[256]=TEXT("\0");
		switch((int) pMsg->wParam)
		{
			case 124://拨打电话
			case 13://回车
				OnSendTalk();
				//CDialog::OnOK ();
				return TRUE;
			case 9://Tab键
			case 40://向下箭头
				if (iLocal == 3)
					iLocal=0;
				SelectModule(++iLocal);
				return TRUE;
			case 38://向上箭头
				if(iLocal == 1)
				{
					iLocal=4;
				}
				SelectModule(--iLocal);
				return TRUE;
			case 27://ESC键:退出
				CDialog::OnCancel ();
				return TRUE;
			case 125://挂电话
				port.LocalVoice (0);
				port.SetList (1,"ATH\r");
				return TRUE;
			case 12://清除键
				if(iLocal == 1)
				{
					GetDlgItem(IDC_EDIT1)->PostMessage(WM_KEYDOWN,(WPARAM)8,0);
				}
				return TRUE;
			case 8://清除键
				if(iLocal == 1)
				{
					break;//m_edit.Undo ();
				}
				return TRUE;
			case 48:
			case 49:
			case 50:
			case 51:
			case 52:
			case 53:
			case 54:
			case 55:
			case 56:
			case 57:
			case 42://*
			case 35://#
				if(iLocal == 1)
				{
					port.LocalVoice (0);
					swprintf(swave,TEXT("\\Storage Card\\Media\\%c.wav"),(int) pMsg->wParam);
					sndPlaySound(swave,SND_FILENAME|SND_SYNC);
					if (bVTel)
					{
						sprintf(temp,"AT+VTS=%c\r",(int) pMsg->wParam);
						SetEvent(port.m_CmdFinish);
						port.SetList (1,temp);
						port.LocalVoice (1);
						break;//m_edit.Undo ();
					}
					else
					{
						port.LocalVoice (1);
						break;
					}
				}
				return TRUE;
			default:
				return TRUE;
		}
	}
	if ( WM_KEYUP == pMsg->message)
	{
		return TRUE;
	}
	return CDialog::PreTranslateMessage(pMsg);
}


HBRUSH CDlgTel::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) 
{
	HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
	
	// TODO: Change any attributes of the DC here
	if(nCtlColor== CTLCOLOR_EDIT)
	{
		pDC->SetTextColor(RGB(0, 0, 255));
		pDC->SetBkColor(RGB(250,241,241));
		HBRUSH h = ::CreateSolidBrush(RGB(250,241,241));
		return h;
	}
	else
	   return CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
	// TODO: Return a different brush if the default is not desired
	return hbr;
}

void CDlgTel::SelectModule(int iLocal)
{
	CEdit* pBoxOne;
	switch(iLocal)
	{
		case 1://手动
			pBoxOne = (CEdit*) GetDlgItem (IDC_EDIT1);
			break;
		case 2://常用号码1
			pBoxOne = (CEdit*) GetDlgItem (IDC_EDIT2);
			break;
		case 3://常用号码2
			pBoxOne = (CEdit*) GetDlgItem (IDC_EDIT3);
			break;
		default:
			return;
	}
	pBoxOne->SetFocus ();
	pBoxOne->SetSel (0,-1);
}

⌨️ 快捷键说明

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