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

📄 senddlg.cpp

📁 网络短息平台的开发与设计
💻 CPP
📖 第 1 页 / 共 2 页
字号:
{
    char TxData[500];
	int i;
	int Count=m_strS.GetLength ();
	for(i=0;i<Count;i++)
	{
	   TxData[i]=m_strS.GetAt (i);
	}
	CByteArray array;
	array.RemoveAll ();
	array.SetSize (Count);
	for(i=0;i<Count;i++)
	{
	   array.SetAt(i,TxData[i]);
	}
	m_Com.SetOutput (COleVariant(array));
}

CString CSendDlg::EncodeTPDU(CString phone, CString content)
{  
   CString strTPDU;
   int meslength,m,n;
   CString str1,str2,str3,str4,str5;
   str1="11000D9168";
   str2=NumberEncode(phone);
   str3="000800";
   str5=ContentEncode(content);
   meslength=str5.GetLength()/2;
   m=meslength>>4;
   n=meslength&0x0f;
   if(m>9) m+=7;
   if(n>9) n+=7;
   str4+=m+48;
   str4+=n+48;
   strTPDU=str1;
   strTPDU+=str2;
   strTPDU+=str3;
   strTPDU+=str4;
   strTPDU+=str5;
   return strTPDU;
}

char * CSendDlg::ReadString()
{    
	  VARIANT vResponse;
      char *str;
      char *str1;
      int k,i;
      k=m_Com.GetInBufferCount ();
	  if(k>0)
	  {
	     vResponse=m_Com.GetInput ();
		 str=(char *)(unsigned char *)vResponse.parray ->pvData;
	  }
	  i=0;
	  str1=str;
	  while(i<k)
	  {
	    i++;
		str1++;
	  }
  	  *str1='\0';
      return str;
}

CString CSendDlg::NumberEncode(CString phone)
{
    CString strphone;
    char ch;
	int i;
	phone+='F';
    for(i=0;i<phone.GetLength();i+=2)
	{
	   ch=phone.GetAt(i);
	   strphone+=phone.GetAt(i+1);
       strphone+=ch;
	}
    return strphone;
}

CString CSendDlg::ContentEncode(CString content)
{  
    CString strcontent;
	WCHAR wchar[128]; 
    int nDstLength;
	int j,k,m,n;
	nDstLength=::MultiByteToWideChar(CP_ACP, 0,content,content.GetLength(), wchar, 128);
    for(int i=0; i<nDstLength; i++)
    {
        j=wchar[i] >> 8;
		k=j&0x0f;
		j=j>>4;
		m=wchar[i] & 0xff;
		n=m&0x0f;
		m=m>>4;
		if(j>9) j+=7;
		if(k>9) k+=7;
		if(m>9) m+=7;
		if(n>9) n+=7;
        strcontent+=j+48;
        strcontent+=k+48;
		strcontent+=m+48;
		strcontent+=n+48;
    }
	return strcontent;
}

BOOL CSendDlg::SendInf(CString Phone, CString Content)
{

	int length_TPDU;
	CString strPDU,str_SMSC,str_TPDU;
	CString str_Send;
	str_SMSC="0891683108301105F0";
	str_TPDU=EncodeTPDU(Phone,Content);
	length_TPDU=str_TPDU.GetLength();
	str_Send.Format("AT+CMGS=%d\r",length_TPDU/2);
	SendString(str_Send);
    Sleep(100);
    if(strstr(ReadString(),"\r\n>"))
	{   strPDU=str_SMSC;
	    strPDU+=str_TPDU;
        strPDU+='\32';
	}
    SendString(strPDU);
	Sleep(100);
	if(m_Com.GetInBufferCount()) m_Com.SetInBufferCount(0); 
    for(int i=0;i<500;i++)
	{  Sleep(10);
	   if(m_Com.GetInBufferCount()) break;
	}
    Sleep(100);
    if(strstr(ReadString(),"+CMGS:"))
	   {
	     return TRUE;
	   }

     return FALSE;
}

void CSendDlg::OnButLiulan() 
{
  CFileDialog MyFileDlg(TRUE,NULL,NULL,0,"文本文件(*.txt)|*.txt||");
  if(MyFileDlg.DoModal()==IDOK)
  {
    m_strPhone=MyFileDlg.GetPathName();
    flag=1;
	UpdateData(FALSE);
  }

}

void CSendDlg::OnButReceive() 
{
    SendString("AT+CMGL=4\r");
	while(TRUE) 
	{
	
		int Count1=m_Com.GetInBufferCount();
		Sleep(500);
		int Count2=m_Com.GetInBufferCount();
		if(Count1==Count2)  break;
	
	} 
    CReceive receive;
	receive.Rpdu=ReadString();
	receive.DoModal();
}

void CSendDlg::OnCheck1() 
{
	UpdateData();
	if(m_isSetTime)
	{
		CWnd *pWndCtl;
  		pWndCtl=GetDlgItem(IDC_DATETIMEPICKER1);
		pWndCtl->EnableWindow();	
		pWndCtl=GetDlgItem(IDC_DATETIMEPICKER2);
		pWndCtl->EnableWindow();
	}
	else
	{
			CWnd *pWndCtl;
			pWndCtl=GetDlgItem(IDC_DATETIMEPICKER1);
			pWndCtl->EnableWindow(FALSE);
	    	pWndCtl=GetDlgItem(IDC_DATETIMEPICKER2);
			pWndCtl->EnableWindow(FALSE);
	
	
	}
}

void CSendDlg::OnButTime() 
{
	CTimeToSend timetosend;
	timetosend.DoModal();

	
}

void CSendDlg::OnTimer(UINT nIDEvent) 
{
		KillTimer(1);
		CDatabase db;
		CSendDb *pSendSet=NULL;
        if(db.Open("SendMessage"))
		{		
			pSendSet=new CSendDb();
			CString strSQL;
			strSQL="select * from MessageSend where isSend=";
            strSQL+="FALSE ORDER BY Time";
			pSendSet->Open(AFX_DB_USE_DEFAULT_TYPE,strSQL);
            while(!pSendSet->IsEOF())
			{
				CTime time=CTime::GetCurrentTime();
				if(pSendSet->m_Time<time)
				{
					SendInf(pSendSet->m_Phone,pSendSet->m_Content);
					pSendSet->Edit();
					pSendSet->m_isSend=TRUE;
					pSendSet->Update();
				
				}
				else break;
				pSendSet->MoveNext();
			
			}
			pSendSet->Close();
			delete pSendSet;
		}
		db.Close();
		SetTimer(1,1000,NULL);
	CDialog::OnTimer(nIDEvent);
}
BOOL CSendDlg::MyTaskBarAddIcon()
{
	BOOL res;
	HICON hicon;
	hicon=LoadIcon(AfxGetApp()->m_hInstance,MAKEINTRESOURCE(m_bCapture?IDI_CAPTURE1:IDI_CAPTURE2));
	tnid.cbSize=sizeof(NOTIFYICONDATA);
	tnid.hWnd=m_hWnd;
	tnid.uID=MYICON;
	tnid.uFlags=NIF_MESSAGE|NIF_ICON|NIF_TIP;
	tnid.uCallbackMessage=MYWM_NOTIFYICON;
	tnid.hIcon=hicon;
	lstrcpyn(tnid.szTip,MYTIP,sizeof(MYTIP));
	res=Shell_NotifyIcon(NIM_ADD,&tnid);
	if(hicon)
		DestroyIcon(hicon);
	return res;

}
BOOL CSendDlg::MyTaskBarDeleteIcon()
{
	BOOL res;
	tnid.cbSize=sizeof(NOTIFYICONDATA);
	tnid.hWnd=m_hWnd;
	tnid.uID=MYICON;
	res=Shell_NotifyIcon(NIM_DELETE,&tnid);
	return res;
}

BOOL CSendDlg::MyTaskBarChangeIcon()
{
	BOOL res;
	HICON hicon;
	m_bCapture=!m_bCapture;
	hicon=LoadIcon(AfxGetApp()->m_hInstance,MAKEINTRESOURCE(m_bCapture?IDI_CAPTURE1:IDI_CAPTURE2));
	tnid.cbSize=sizeof(NOTIFYICONDATA);
	tnid.hWnd=m_hWnd;
	tnid.uID=MYICON;
	tnid.uFlags=NIF_MESSAGE|NIF_ICON|NIF_TIP;
	tnid.uCallbackMessage=MYWM_NOTIFYICON;
	tnid.hIcon=hicon;
	lstrcpyn(tnid.szTip,m_bCapture?MYTIP:MYTIPX,sizeof(MYTIPX));
	res=Shell_NotifyIcon(NIM_MODIFY,&tnid);
	if(hicon)
		DestroyIcon(hicon);
	if(m_bCapture)
        SetTimer(1,1000,NULL);
	else 
		KillTimer(1);
	return res;
}

LRESULT CSendDlg::OnMyNotifyIcon(WPARAM wParam,LPARAM lParam)
{
	switch(lParam)
	{
	case WM_LBUTTONDOWN:
		if(wParam=MYICON)
			MyTaskBarChangeIcon();
		break;
	case WM_LBUTTONDBLCLK:
		if(wParam=MYICON)
			ShowWindow(SW_SHOW);
		SetForegroundWindow();
		break;
	case WM_RBUTTONDOWN:
		if(wParam=MYICON)
		{
			CMenu *pt,t;
			CPoint pp;
			GetCursorPos(&pp);
			t.LoadMenu(IDR_TRAYMENU);
			pt=t.GetSubMenu(0);
			::SetForegroundWindow(tnid.hWnd);
			::TrackPopupMenu(pt->m_hMenu,0,pp.x,pp.y,0,tnid.hWnd,NULL);
			::PostMessage(tnid.hWnd,WM_NULL,0,0);
			t.DestroyMenu();
		
		
		}
		break;
	default:
		break;

	
	}
	
	return 0L;

}

void CSendDlg::OnDestroy() 
{
	CDialog::OnDestroy();
	MyTaskBarDeleteIcon();
//	::GlobalDeleteAtom(::GlobalFindAtom("unique_Send"));
	
 	
}


void CSendDlg::OnExit() 
{
	EndDialog(TRUE);
}

void CSendDlg::OnHelp() 
{
	MessageBox("网络短信平台,能实现短信群发,定时发等功能!");
	// TODO: Add your command handler code here
	
}

void CSendDlg::OnAbout() 
{
	ShowWindow(SW_SHOW);
	SetForegroundWindow();

	
}

⌨️ 快捷键说明

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