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

📄 ascend_smsdlg.cpp

📁 GSM 模块软件开发包 开发包说明 开发包基于GSM模块开发
💻 CPP
📖 第 1 页 / 共 2 页
字号:
/*
 * Ascend_SMSDlg.cpp 
 *
 * VC++ Example constructed upon AscendSMS.dll
 *
 * Hangzhou Ascend Wireless Team
 *
 * Copyright (c) 2001-2003 Ascend Software Technology, Co.,Ltd.
 *
 * Main procedure File , Version 1.0.
 *
 * The Initial Developer of the Original Code is Ascend Software Technology, Co.,Ltd.
 *
 * Revision 1.0 , 01/07/2001 YaleYe
 *
 * Note: The code added or modified by Ascend is started with "//Ascend Begin" and 
 *       ended by "//Ascend End".
 */

#include "stdafx.h"
//Ascend Begin
#include "Ascend_SMS.h"
#include "Ascend_SMSDlg.h"
//Ascend End
#include "Ascend_SMS_Interface.h"

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

//Ascend Begin
extern CAscend_SMSDlg * pDlg;

char NewMsg[100];int IRtn;
int PortNum=1; int OpenPortNum=0; int CodeMode=0;
bool PortIsOpened=false;
HANDLE hMutex ;
//Ascend End

/////////////////////////////////////////////////////////////////////////////
// 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()

/////////////////////////////////////////////////////////////////////////////
// CAscend_SMSDlg dialog

CAscend_SMSDlg::CAscend_SMSDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CAscend_SMSDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CAscend_SMSDlg)
	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void CAscend_SMSDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CAscend_SMSDlg)
	DDX_Control(pDX, IDC_LIST_Receive, m_ReceiveList);
	DDX_Control(pDX, IDC_CmbCodeMode, m_CodeMode);
	DDX_Control(pDX, IDC_STATIC_Status, m_Status);
	DDX_Control(pDX, IDC_EdtNextMsg, m_NextMsg);
	DDX_Control(pDX, IDC_EdtCenterNum, m_CenterNum);
	DDX_Control(pDX, IDC_Edt_Number, m_Num);
	DDX_Control(pDX, IDC_CmbSerial, m_PortNum);
	DDX_Control(pDX, IDC_EdtMessage, m_Msg);
	DDX_Control(pDX, IDC_EdtPhone, m_Phone);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CAscend_SMSDlg, CDialog)
	//{{AFX_MSG_MAP(CAscend_SMSDlg)
	ON_WM_SYSCOMMAND()
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_BN_CLICKED(IDC_BtnOpen, OnBtnOpen)
	ON_BN_CLICKED(IDC_BtnClose, OnBtnClose)
	ON_CBN_EDITCHANGE(IDC_CmbSerial, OnEditchangeCmbSerial)
	ON_CBN_SELCHANGE(IDC_CmbSerial, OnSelchangeCmbSerial)
	ON_BN_CLICKED(IDC_Btn_Test, OnBtnTest)
	ON_BN_CLICKED(IDC_Btn_Set, OnBtnSet)
	ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
	ON_CBN_SELCHANGE(IDC_CmbCodeMode, OnSelchangeCmbCodeMode)
	ON_BN_CLICKED(IDC_BUTTON3, OnButton3)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CAscend_SMSDlg message handlers

BOOL CAscend_SMSDlg::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
	
	//Ascend Begin
	hMutex =  CreateMutex(NULL,FALSE,"MutexStop");
	m_PortNum.SetCurSel(0);
	m_CodeMode.SetCurSel(0);
	m_Status.SetWindowText("http://www.ascend-tech.com.cn");
	Display();
	//Ascend End
	return TRUE;  // return TRUE  unless you set the focus to a control
}

void CAscend_SMSDlg::Display()
{
	m_ReceiveList.InsertColumn(1,"时间",0,120,0);
	m_ReceiveList.InsertColumn(2,"来电号码",0,78,1);
	m_ReceiveList.InsertColumn(3,"短信内容",0,600,2);
}

void CAscend_SMSDlg::AddtoReceiveList(char* SMSStr)
{
	static int ItemIndex=0;		
	char DateStr[20];	char SourceStr[21];	char MsgContent[160];
	memset(DateStr,0x00,20);memset(SourceStr,0x00,21);
	int SubStrLen=0;
	memset(MsgContent,0x00,160);
	int  ch = '|';	char *pdest;

	pdest = strchr( SMSStr, ch );
	SubStrLen = pdest-SMSStr;
	strncpy(SourceStr,SMSStr,SubStrLen);
	SMSStr=pdest+1;

	pdest = strchr( SMSStr, ch );
	SubStrLen = pdest-SMSStr;
	strncpy(DateStr,SMSStr,SubStrLen);
	SMSStr=pdest+1;

	sprintf(MsgContent,SMSStr);

	m_ReceiveList.InsertItem(ItemIndex,DateStr,0);
	m_ReceiveList.SetItemText(ItemIndex,1,SourceStr);
	m_ReceiveList.SetItemText(ItemIndex,2,MsgContent);
}

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

//Ascend Begin
//Thread function RcvMsg. Functions:Receiving SMS, retreive the unsend Message number.
UINT RcvMsg(LPVOID)
{
	int UnSendNum=0; 
	DWORD dwWaitResult ;
	char TmpStr[64];memset(TmpStr,0x00,64);

	char Tmp[256]; memset(Tmp,0x00,256);
	
	Sleep(200);
	while(true){
		dwWaitResult = WaitForSingleObject(hMutex ,100);
		switch(dwWaitResult){
			case WAIT_OBJECT_0:{
				ReleaseMutex(hMutex);
				AfxEndThread(1);		//Terminate the Receiving Thread
				return 0;
			}
			case WAIT_TIMEOUT:{
				memset(Tmp,0x00,256);
				bool rtn = GetNewMsg(OpenPortNum,Tmp);		//Receive SMS
				if(rtn&(strcmp(Tmp,"")!=0)){
				   pDlg->AddtoReceiveList(Tmp);
				}
				else if((!rtn)&(strcmp(Tmp,"Module Error")==0)){	//Module Error
					PortIsOpened=false;
					OpenPortNum=0; 					
					pDlg->m_Status.SetWindowText("Module Error! Check the power or data connect line!");
					ReleaseMutex(hMutex);
					AfxEndThread(1);		//Terminate the Receiving Thread
					return 0;
				}
				memset(Tmp,0x00,256);
				if( GetNextSendMsg(OpenPortNum,Tmp,false) )	//Retreive the next message in message list.
				{
					pDlg->m_NextMsg.SetWindowText(Tmp);
				}
				else{
					pDlg->m_NextMsg.SetWindowText("");
				}
				memset(Tmp,0x00,256);
				if( GetFailedMsg(OpenPortNum,Tmp) )		//Retreive the fail SMS
				{

⌨️ 快捷键说明

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