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

📄 sendmms.cpp

📁 用于电脑发送手机彩信的好东西啊
💻 CPP
字号:
// SendMMS.cpp : implementation file
//

#include "stdafx.h"
#include "TestSMS.h"
#include "SendMMS.h"

#include <comdef.h>
#include <atlbase.h>
#include <windows.h>



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

/////////////////////////////////////////////////////////////////////////////
// CSendMMS dialog


CSendMMS::CSendMMS(CWnd* pParent /*=NULL*/)
	: CDialog(CSendMMS::IDD, pParent)
{
	//{{AFX_DATA_INIT(CSendMMS)
	m_strPathname = _T("");
	m_strPhonenum = _T("13648058271");
	m_strTitle = _T("海南三基");
	m_strText = _T("彩信测试");
	//}}AFX_DATA_INIT
}


void CSendMMS::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CSendMMS)
	DDX_Text(pDX, IDC_EDIT_CONTENT, m_strPathname);
	DDX_Text(pDX, IDC_EDIT_PHONENUM, m_strPhonenum);
	DDX_Text(pDX, IDC_EDIT_TITLE, m_strTitle);
	DDX_Text(pDX, IDC_EDIT_TEXT, m_strText);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CSendMMS, CDialog)
	//{{AFX_MSG_MAP(CSendMMS)
	ON_BN_CLICKED(IDC_BUTTON_CHOOLE, OnButtonChoole)
	ON_BN_CLICKED(IDC_BUTTON_SENDMMS, OnButtonSendmms)
//	ON_BN_CLICKED(IDC_BUTTON_DISCONNECT, OnButtonDisconnect)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CSendMMS message handlers

void CSendMMS::OnButtonChoole() 
{
	// TODO: Add your control notification handler code here
	CFileDialog dialog(TRUE,NULL,NULL,OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT,\
		"All Files(*.*)|*.*|");
	dialog.DoModal();
	m_strPathname = dialog.GetPathName();
	UpdateData(FALSE);
	
}

void CSendMMS::OnButtonSendmms() 
{
	// TODO: Add your control notification handler code here
	UpdateData(TRUE);
	
	IMmsProtocolMm1 *pMMSProtocol = NULL;
	IMmsConstants *pMMSConstants = NULL;
	IMmsMessage *pMMSMessage = NULL;
	//幻灯片
	IMmsSlide *pMMSSlide = NULL;

	m_strPhonenum = "+86" + m_strPhonenum;
	_bstr_t bstrRecipient(m_strPhonenum);

	_bstr_t bstrTiTle(m_strTitle);
	_bstr_t bstrText(m_strText);

	_bstr_t bstrLogFile = "c:\\mmslog.txt";

	_bstr_t bstrDevice = "COM1";



	HRESULT hr = ::CoInitialize(NULL);

	//实例化
	CoCreateInstance(CLSID_MmsProtocolMm1,
		             NULL, 
					 CLSCTX_INPROC_SERVER,
					 IID_IMmsProtocolMm1,
					 (void**)&pMMSProtocol);
	CoCreateInstance(CLSID_MmsConstants,
		             NULL,
					 CLSCTX_INPROC_SERVER,
					 IID_IMmsConstants,
					 (void**)&pMMSConstants);
	CoCreateInstance(CLSID_MmsMessage,
		             NULL,
					 CLSCTX_INPROC_SERVER,
					 IID_IMmsMessage,
					 (void**)&pMMSMessage);
	CoCreateInstance(CLSID_MmsSlide,
		             NULL,
					 CLSCTX_INPROC_SERVER,
					 IID_IMmsSlide,
					 (void**)&pMMSSlide);

	pMMSSlide->Clear();
	pMMSSlide->put_Duration(10);
	_bstr_t bstrFilename(m_strPathname);
	//添加幻灯片
	pMMSSlide->AddAttachment(bstrFilename);
	//增加文本信息
	pMMSSlide->AddText(bstrText);

	pMMSMessage->Clear();
	pMMSMessage->put_Subject(bstrTiTle);
	pMMSMessage->AddRecipient(bstrRecipient);
	pMMSMessage->AddSlide(&_variant_t ( ( IDispatch*) pMMSSlide ));

	//加载配置文件
	char strPath[500];
	GetModuleFileName(AfxGetApp()->m_hInstance,strPath,500);
	CString FileName = strPath;
	FileName = FileName.Left(FileName.ReverseFind('\\')+1);
	FileName = FileName + "中国移动.mm1";
	_bstr_t bstrConfigFile(FileName);
	pMMSProtocol->ProviderLoadConfig(bstrConfigFile);

	//加载设备
	pMMSProtocol->put_Device(bstrDevice);
	pMMSProtocol->put_LogFile(bstrLogFile );

// 	if (pMMSProtocol->Connect() != 0)
// 	{
// 		AfxMessageBox("连接失败");
//	}
	pMMSProtocol->Connect();
	
	AfxMessageBox("正在发送...");
// 	if (pMMSProtocol->Send(&_variant_t ( ( IDispatch*) pMMSMessage )) != S_OK)
// 	{
// 		AfxMessageBox("发送失败");
//	}
	pMMSProtocol->Send(&_variant_t ( ( IDispatch*) pMMSMessage ));
	LONG lLastError = 0;
	pMMSProtocol->get_LastError( &lLastError );
	CString strError;
	strError.Format("发送完毕: %ld\n" ,lLastError );
	AfxMessageBox(strError);
	pMMSProtocol->Disconnect();
	pMMSConstants->Release();
	pMMSMessage->Release();
	pMMSProtocol->Release();
	pMMSSlide->Release();
}

// void CSendMMS::OnButtonDisconnect() 
// {
// 	// TODO: Add your control notification handler code her
//}

⌨️ 快捷键说明

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