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

📄 mobileassistantview.cpp

📁 本源代码完全实现手机短信收发和操作电话本的功能
💻 CPP
📖 第 1 页 / 共 2 页
字号:
// MobileAssistantView.cpp : CMobileAssistantView 类的实现
//

#include "stdafx.h"
#include "MobileAssistant.h"

#include "MobileAssistantDoc.h"
#include "MobileAssistantView.h"
#include "MainFrm.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#endif

LRESULT Proc_ReceivedSMS ( SM_PARAM *pSMRecv, WPARAM wParam, LPARAM lParam )
{
	CMobileAssistantView *pMobileAssistantView = reinterpret_cast<CMobileAssistantView*>(wParam);
	ASSERT ( pMobileAssistantView );
	return pMobileAssistantView->Proc_ReceivedSMS ( pSMRecv );
}

void Proc_IncomingFromGSM ( LPCTSTR lpszCallerID )
{
	Log ( L_NORMAL, _T("New call from [%s]"), GET_SAFE_STRING(lpszCallerID) );
}

// CMobileAssistantView

IMPLEMENT_DYNCREATE(CMobileAssistantView, CFormView)

BEGIN_MESSAGE_MAP(CMobileAssistantView, CFormView)
	ON_COMMAND(ID_BUTTON_SendSMS, OnBUTTONSendSMS)
	ON_WM_DESTROY()
	ON_COMMAND(ID_BUTTON_OpenPort, OnBUTTONOpenPort)
	ON_COMMAND(ID_BUTTON_Clear, OnBUTTONClear)
	ON_COMMAND(ID_BUTTON_Exit, OnBUTTONExit)
	ON_COMMAND(ID_BUTTON_RecvSMS, OnBUTTONRecvSMS)
	ON_COMMAND(ID_BUTTON_ReadSMS, OnBUTTONReadSMS)
	ON_BN_CLICKED(IDC_BUTTON_AddPhoneBook, OnBUTTONAddPhoneBook)
	ON_WM_SIZE()
	ON_WM_TIMER()
	ON_BN_CLICKED(IDC_BUTTON_ReadOnePhoneBook, OnBUTTONReadOnePhoneBook)
	ON_BN_CLICKED(IDC_BUTTON_ReadPhoneBook, OnBUTTONReadPhoneBook)
	ON_MESSAGE(WM_SHOWLOG,OnWM_SHOWLOG)
END_MESSAGE_MAP()

// CMobileAssistantView 构造/析构

CMobileAssistantView::CMobileAssistantView()
	: CFormView(CMobileAssistantView::IDD)
	, m_nComNo ( 1 )
{
	//{{AFX_DATA_INIT(CMobileAssistantView)
	m_csReceiverMobileNO = _T("");
	m_csSMSContent = _T("");
	m_csBaudRate = _T("9600");
	m_csSMSC = _T("");
	m_csLocalCountryCode = _T("");
	m_csLocalAreaCode = _T("");
	//}}AFX_DATA_INIT
	// TODO: add construction code here
	m_MobileControl.m_bMustRegistered = FALSE;

	{	//d
	}	//d
}

CMobileAssistantView::~CMobileAssistantView()
{
}

void CMobileAssistantView::DoDataExchange(CDataExchange* pDX)
{
	CFormView::DoDataExchange(pDX);
	DDX_Text(pDX, IDC_EDIT_ReceiverMobileNO, m_csReceiverMobileNO);
	DDX_Text(pDX, IDC_EDIT_SMSContent, m_csSMSContent);
	DDX_CBString(pDX, IDC_COMBO_BaudRate, m_csBaudRate);
	DDX_Text(pDX, IDC_EDIT_SMSC, m_csSMSC);
	DDX_Text(pDX, IDC_EDIT_LocalCountryCode, m_csLocalCountryCode);
	DDX_Text(pDX, IDC_EDIT_LocalAreaCode, m_csLocalAreaCode);
}

BOOL CMobileAssistantView::PreCreateWindow(CREATESTRUCT& cs)
{
	// TODO: 在此处通过修改
	//  CREATESTRUCT cs 来修改窗口类或样式

	return CFormView::PreCreateWindow(cs);
}

void CMobileAssistantView::OnInitialUpdate()
{
	CFormView::OnInitialUpdate();
	GetParentFrame()->RecalcLayout();
	ResizeParentToFit();

	Set_RecvLogMsgHwnd ( GetSafeHwnd() );
	SetCtrlValue ();
	this->SetForegroundWindow ();
	SetTimer ( 1, 1000, NULL );

	Log ( L_VERBOSE, _T("\r\n%s"), NOTE_HwMobile );
}


// CMobileAssistantView 诊断

#ifdef _DEBUG
void CMobileAssistantView::AssertValid() const
{
	CFormView::AssertValid();
}

void CMobileAssistantView::Dump(CDumpContext& dc) const
{
	CFormView::Dump(dc);
}

CMobileAssistantDoc* CMobileAssistantView::GetDocument() const // 非调试版本是内联的
{
	ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CMobileAssistantDoc)));
	return (CMobileAssistantDoc*)m_pDocument;
}
#endif //_DEBUG


// CMobileAssistantView 消息处理程序

void CMobileAssistantView::Align()
{
	if ( !GetDlgItem(IDC_EDIT_Log) || !::IsWindow ( GetDlgItem(IDC_EDIT_Log)->GetSafeHwnd() ) )
		return;

	CRect rcClient;
	CWnd *pWndParent = GetParent ();
	GetWindowRect ( &rcClient );
	pWndParent->ScreenToClient ( &rcClient );
	MoveWindow ( &rcClient );

	CRect rc;
	GetDlgItem(IDC_EDIT_Log)->GetWindowRect ( &rc );
	ScreenToClient ( &rc );

	GetClientRect ( &rcClient );
	CRect rcLog = ::hwMoveWindow ( this, GetDlgItem(IDC_EDIT_Log),
		0, rc.top, rcClient.right, rcClient.bottom );

}

void CMobileAssistantView::SetCtrlValue()
{
	m_csReceiverMobileNO = AfxGetApp()->GetProfileString ( _T("SMS"), _T("ReceiverMobileNO"), _T("13823310105;13510631301;") );
	m_csLocalCountryCode = AfxGetApp()->GetProfileString ( _T("SMS"), _T("LocalCountryCode"), _T("+86") );
	m_csLocalAreaCode = AfxGetApp()->GetProfileString ( _T("SMS"), _T("LocalAreaCode"), _T("0755") );
	m_csSMSContent = AfxGetApp()->GetProfileString ( _T("SMS"), _T("SMSContent"), _T("hello!") );
	m_csBaudRate = AfxGetApp()->GetProfileString ( _T("SMS"), _T("BaudRate"), _T("9600") );
	m_nComNo = AfxGetApp()->GetProfileInt ( _T("SMS"), _T("COM"), 1 );

	CComboBox *pcombo = (CComboBox*) GetDlgItem(IDC_COMBO_COM);
	ASSERT ( pcombo );
	for ( int i=0; i<16; i++ )
	{
		CString csCOM;
		csCOM.Format ( _T("COM%d"), i+1 );
		pcombo->AddString ( csCOM );
	}
	if ( m_nComNo > 0 )
		pcombo->SetCurSel ( m_nComNo-1 );

	pcombo = (CComboBox*) GetDlgItem(IDC_COMBO_BaudRate);
	ASSERT ( pcombo );
	pcombo->AddString ( _T("1200") );
	pcombo->AddString ( _T("2400") );
	pcombo->AddString ( _T("4800") );
	pcombo->AddString ( _T("9600") );
	pcombo->AddString ( _T("19200") );
	pcombo->AddString ( _T("38400") );
	pcombo->AddString ( _T("57600") );
	pcombo->AddString ( _T("115200") );

	pcombo = (CComboBox*) GetDlgItem(IDC_COMBO_PhoneBook);
	pcombo->AddString ( _T("FD - 固定拨号电话本") );
	pcombo->AddString ( _T("SM - SIM 卡电话本") );
	pcombo->AddString ( _T("ON - 本机电话号码列表") );
	pcombo->AddString ( _T("ME - 手机电话本") );
	pcombo->AddString ( _T("LD - 最近已拨电话(SIM)") );
	pcombo->AddString ( _T("MC - 最近来电未接电话本") );
	pcombo->AddString ( _T("RC - 最近来电已接电话本") );
	pcombo->AddString ( _T("DC - 最近拨号电话本") );
	pcombo->SetCurSel ( 0 );

	UpdateData ( FALSE );
}

void CMobileAssistantView::GetCtrlValue()
{
	UpdateData ( TRUE );
	CComboBox *pcombo = (CComboBox*) GetDlgItem(IDC_COMBO_COM);
	ASSERT ( pcombo );
	m_nComNo = pcombo->GetCurSel () + 1;
	m_csReceiverMobileNO.TrimLeft(); m_csReceiverMobileNO.TrimRight();
	m_csSMSContent.TrimLeft(); m_csSMSContent.TrimRight();
}

void CMobileAssistantView::OnDestroy()
{
	GetCtrlValue ();
	AfxGetApp()->WriteProfileString ( _T("SMS"), _T("ReceiverMobileNO"), m_csReceiverMobileNO );
	AfxGetApp()->WriteProfileString ( _T("SMS"), _T("LocalCountryCode"), m_csLocalCountryCode );
	AfxGetApp()->WriteProfileString ( _T("SMS"), _T("LocalAreaCode"), m_csLocalAreaCode );
	AfxGetApp()->WriteProfileString ( _T("SMS"), _T("SMSContent"), m_csSMSContent );
	AfxGetApp()->WriteProfileString ( _T("SMS"), _T("BaudRate"), m_csBaudRate );
	AfxGetApp()->WriteProfileInt ( _T("SMS"), _T("COM"), m_nComNo );

	CFormView::OnDestroy();
}

void CMobileAssistantView::SetMobileParameter ()
{
	GetCtrlValue ();

	g_MobileParameter.bRecvSMSEnable = TRUE;
	g_MobileParameter.bSendSMSEnable = TRUE;
	g_MobileParameter.bAllowEchoSMS = TRUE;
	lstrcpyn(g_MobileParameter.szLocalCountryCode, m_csLocalCountryCode, COUNT(g_MobileParameter.szLocalCountryCode) );
	lstrcpyn(g_MobileParameter.szLocalAreaCode, m_csLocalAreaCode, COUNT(g_MobileParameter.szLocalAreaCode) );

	m_MobileControl.SetParameter ( &g_MobileParameter, ::Proc_ReceivedSMS, WPARAM(this), NULL,
		_T("HAHA:\n"), _T("\nSent by BiKe") );
	m_MobileControl.m_Proc_IncomingFromGSM = ::Proc_IncomingFromGSM;
}

void CMobileAssistantView::OnBUTTONOpenPort() 
{
	if ( ( (CMobileAssistantApp*)AfxGetApp() )->m_bMustTerminate )
	{
		PostQuitMessage (0);
		return;
	}
	ToolBarEnableButton ( ID_BUTTON_OpenPort, FALSE );
	Log ( L_NORMAL, _T("Connect to SMS module. Please wait for a moment ...") );
	

⌨️ 快捷键说明

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