www.pudn.com > smssend4vc.zip > smssend4vcDlg.cpp


// smssend4vcDlg.cpp : implementation file 
// 
 
#include "stdafx.h" 
#include "smssend4vc.h" 
#include "smssend4vcDlg.h" 
 
#ifdef _DEBUG 
#define new DEBUG_NEW 
#undef THIS_FILE 
static char THIS_FILE[] = __FILE__; 
#endif 
 
typedef struct  struct_sms 
{ 
}; 
 
///////////////////////////////////////////////////////////////////////////// 
// CSmssend4vcDlg dialog 
 
CSmssend4vcDlg::CSmssend4vcDlg(CWnd* pParent /*=NULL*/) 
	: CDialog(CSmssend4vcDlg::IDD, pParent) 
{ 
	//{{AFX_DATA_INIT(CSmssend4vcDlg) 
	m_NUM = _T("1861"); 
	m_MSG = _T("YECX"); 
	m_COM = _T("1"); 
	//}}AFX_DATA_INIT 
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32 
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME); 
} 
 
void CSmssend4vcDlg::DoDataExchange(CDataExchange* pDX) 
{ 
	CDialog::DoDataExchange(pDX); 
	//{{AFX_DATA_MAP(CSmssend4vcDlg) 
	DDX_Control(pDX, IDC_SMS1, m_GSM); 
	DDX_Text(pDX, IDC_EDIT1, m_NUM); 
	DDX_Text(pDX, IDC_EDIT2, m_MSG); 
	DDX_Text(pDX, IDC_EDIT3, m_COM); 
	//}}AFX_DATA_MAP 
} 
 
BEGIN_MESSAGE_MAP(CSmssend4vcDlg, CDialog) 
	//{{AFX_MSG_MAP(CSmssend4vcDlg) 
	ON_WM_PAINT() 
	ON_WM_QUERYDRAGICON() 
	ON_BN_CLICKED(IDC_BUTTON1, OnButton1) 
	ON_BN_CLICKED(IDC_BUTTONSEND, OnButtonsend) 
	//}}AFX_MSG_MAP 
END_MESSAGE_MAP() 
 
///////////////////////////////////////////////////////////////////////////// 
// CSmssend4vcDlg message handlers 
 
BOOL CSmssend4vcDlg::OnInitDialog() 
{ 
	CDialog::OnInitDialog(); 
 
	// 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 
	 
	return TRUE;  // return TRUE  unless you set the focus to a control 
} 
 
// 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 CSmssend4vcDlg::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 CSmssend4vcDlg::OnQueryDragIcon() 
{ 
	return (HCURSOR) m_hIcon; 
} 
 
void CSmssend4vcDlg::OnButton1()  
{ 
	// TODO: Add your control notification handler code here 
	m_GSM.SetSerialNumber("Jv}<@(\`p53(!}/");   //序列号。请与供应商联系 
	bool ret=m_GSM.InitComm(); 
	if (ret)  
	{	 
	   	GetDlgItem(IDC_BUTTONSEND)->EnableWindow(true);  
		AfxMessageBox("OK"); 
	} 
	else 
	{ 
		GetDlgItem(IDC_BUTTONSEND)->EnableWindow(true);  
		AfxMessageBox("ERROR"); 
	} 
 
} 
 
void CSmssend4vcDlg::OnCancel()  
{ 
	// TODO: Add extra cleanup here 
	m_GSM.EndComm(); 
	CDialog::OnCancel(); 
} 
 
void CSmssend4vcDlg::OnButtonsend()  
{ 
	// TODO: Add your control notification handler code here 
	bool ret; 
	UpdateData(true); 
	 ret=m_GSM.SendSMSWithoutRet(m_NUM,m_MSG,1); 
} 
 
BEGIN_EVENTSINK_MAP(CSmssend4vcDlg, CDialog) 
    //{{AFX_EVENTSINK_MAP(CSmssend4vcDlg) 
	ON_EVENT(CSmssend4vcDlg, IDC_SMS1, 9 /* OnComm */, OnOnCommSms1, VTS_NONE) 
	//}}AFX_EVENTSINK_MAP 
END_EVENTSINK_MAP() 
 
void CSmssend4vcDlg::OnOnCommSms1()  
{ 
CString s; 
 int i; 
 char ss[10]; 
int itime=0,istart=0; 
 i=m_GSM.GetCommEvent().iVal; 
  sprintf(ss,"消息号%d",i); 
   
  
  switch (i	) 
 
  { 
	  /* 
	case 9999: 
	s=m_GSM.GetNewSMS(); 
	s= "收到短消息" + s ; 
	GetDlgItem(IDC_STATIC)->SetWindowText(s+ "  " +ss); 
	MessageBox(s,"接收到新的短消息!",MB_ICONINFORMATION); 
	break; 
	case 9998: 
	s=m_GSM.GetNewSMS(); 
	s= "收到状态报告" + s; 
	GetDlgItem(IDC_STATIC)->SetWindowText(s+ "  " +ss); 
	MessageBox(s,"收到状态报告!",MB_ICONINFORMATION); 
	break; 
	*/ 
  case 8888: 
	s=m_GSM.GetNewSMS(); 
	s= "发送成功" + s; 
	GetDlgItem(IDC_STATIC)->SetWindowText(s+ "  " +ss); 
	MessageBox(s,"发送成功!",MB_ICONINFORMATION); 
	break; 
  case 7777: 
	  //MessageBox("发送错误"); 
	  break; 
  case 6666: 
      MessageBox("发送可能出错,指定延时内 没有接收到OK或ERROR回音"); 
	  break; 
  case 5555: 
     s= m_GSM.GetInputInfo() ; 
	 s= "其他字符" + s; 
	 break; 
 
  case 9888: //' 读取SIM卡中所有短消息完成通知 
       
		  GetDlgItem(IDC_STATIC)->SetWindowText( "读取短消息完成" ); 
		  s=m_GSM.GetNewSMS(); 
		   
	   s= "读取所有短消息成功" + s; 
	    GetDlgItem(IDC_STATIC)->SetWindowText(s+ "  " +ss); 
		  break; 
  case 9777:  //  '读取SIM卡中一条短消息完成通知 
         
	  /*  
	  s=m_GSM.GetNewSMS(); 
	   s= "读取1条短消息成功" + s; 
	    GetDlgItem(IDC_STATIC)->SetWindowText(s+ "  " +ss); 
       break; 
	  case 9666:  // 
       // ' 
       // '读短消息  出错 
       
      break; 
      */ 
      case 4000: 
		  //在这里读取短消息 并处理 
		tagVARIANT  SSS; 
 
		SSS=m_GSM.Read_SMS(4,1);  
		  
		s=	SSS.bstrVal  ; 
		//索引:05|状态:1|时间(有效期):04-06-22 16:36:43|电话号码:+8613805898176|挂一把艾蒿在你门前,愿你平安;斟一杯雄黄酒,望你安康;送一声祝福, 祝你端午节快乐! 
		//状态为99为状态报告。否则为接收到的短消息 
		 	 
 
		GetDlgItem(IDC_EDIT4)->SetWindowText(s  );  //IDC_EDIT3 
		   
       //sim卡中短消息数目内容提示 
      //  Debug.Print "Sim卡中短消息数目" & GSMGPS1.NewSMS 
      break; 
  default: 
	  ; 
 
 
        
  }		 
}