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

📄 smscomdlg.cpp

📁 sms sender 察到布局图全貌
💻 CPP
📖 第 1 页 / 共 4 页
字号:
	{
		CString idgetstr,szcap;
		idgetstr.LoadString(IDS_READDB_ERROR);
		szcap.LoadString(IDS_READDB_CAPTION_SMSETTING);
		MessageBox(idgetstr,szcap,MB_OK | MB_ICONWARNING);
	}
*****/
	m_ctrlCenterName.EnableWindow(FALSE);
	((CEdit *)GetDlgItem(IDC_SMSC_CODE_EDIT))->EnableWindow(FALSE);
	((CEdit *)GetDlgItem(IDC_INTER_AREA_SMCCODE_EDIT))->EnableWindow(FALSE);
	((CEdit *)GetDlgItem(IDC_INTER_AREA_MTCODE_EDIT))->EnableWindow(FALSE);

	m_ctrlGsmSms.GetSMSCCode(m_szSMSCCode);
    m_ctrlGsmSms.GetCalledPhoneCode(m_szPhoneCode);
	m_ctrlGsmSms.GetShortMessageContext(m_szSMText);
	m_ctrlGsmSms.GetSMCInterAreaCode(m_szInterAreaSMCCode);
	m_ctrlGsmSms.GetMTInterAreaCode(m_szInterAreaMTCode);

//	m_ctrlGsmSms.GetDialedPhoneCode(m_szDialedPhoneCode);
    UpdateData(FALSE);


	int nCom;
	CString temp,szSetting,fmt;
	szSetting.Empty();

    m_ctrlSMSCom.SetCommPort(m_nCurComSel);
	temp.Format("%d,n,8,1",m_nCurBaud);
	m_ctrlSMSCom.SetSettings((LPCTSTR)temp);
	m_ctrlSMSCom.SetInputLen(0);
	m_ctrlSMSCom.SetRThreshold(1);
	m_ctrlSMSCom.SetInputMode(1);   //0-Text,1-Binary
    m_ctrlSMSCom.SetOutBufferSize(1024);
    m_ctrlSMSCom.SetInBufferSize(1024);

	temp.Empty();
	if(m_ctrlSMSCom.GetPortOpen()==false)
		m_ctrlSMSCom.SetPortOpen(true);
	if(m_ctrlSMSCom.GetPortOpen())
	{
		nCom=m_ctrlSMSCom.GetCommPort();
		szSetting=m_ctrlSMSCom.GetSettings();
		fmt.LoadString(IDS_PROMT_COMOPEN_OK);
    	temp.Format(fmt,nCom);
    	//temp.Format("成功打开了串口%d!其设置为:\n",nCom);
		temp+=szSetting;
		DispMsg(temp);
        //m_szCurSettingPrompt=temp;
#ifdef MY_DEBUG_MSG
	    //MessageBox(temp,"串口初始化",MB_OK | MB_ICONINFORMATION );
#else
#ifdef _DEBUG
	    TRACE("串口初始化::"+temp);
#endif
#endif

	}
	else
	{
		nCom=m_ctrlSMSCom.GetCommPort();
		szSetting=m_ctrlSMSCom.GetSettings();
		fmt.LoadString(IDS_PROMT_COMOPEN_FAIL);
		temp.Format(fmt,nCom);
    	//temp.Format("串口%d初始化失败!其设置为:\n",nCom);
		temp+=szSetting;
		//m_szCurSettingPrompt=temp;
		DispMsg(temp);
#ifdef MY_DEBUG_MSG
	   //MessageBox(temp,"串口初始化",MB_OK | MB_ICONQUESTION );
#else
#ifdef _DEBUG
	    TRACE("串口初始化::"+temp);
#endif
#endif
	}
	fmt.LoadString(IDS_PROMT_MTLIST_CNT);
	szSetting.Format(fmt,nCnt);
	//szSetting.Format("; MT个数%d",nCnt);
	temp+=_T(";  ");
	temp+=szSetting;
	fmt.LoadString(IDS_PROMT_IAC);
	temp+=fmt;
	temp+=_T("SMC:");
	temp+=m_szInterAreaSMCCode;
	temp+=_T(";MT:");
	temp+=m_szInterAreaMTCode;
	temp+=_T("  SMSCA:");
	temp+=m_szSMSCCode;
	m_szCurSettingPrompt=temp;
    UpdateData(FALSE);

	ShowWindow(SW_MINIMIZE);
	return TRUE;  // return TRUE  unless you set the focus to a control
}

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

// Automation servers should not exit when a user closes the UI
//  if a controller still holds on to one of its objects.  These
//  message handlers make sure that if the proxy is still in use,
//  then the UI is hidden but the dialog remains around if it
//  is dismissed.

void CSmsComDlg::OnClose() 
{
	UpdateData(TRUE);
	if(m_ctrlSMSCom.GetPortOpen())
		m_ctrlSMSCom.SetPortOpen(false);
	
	CString temp,fmt;
	if( m_ctrlCenterName.GetCount()>0 && m_szInterAreaSMCCode.IsEmpty() )
	{
		fmt.LoadString(IDS_WARNING_SMCIAC);
		temp.LoadString(IDS_HEADER_INITIAL);
        MessageBox(fmt,temp,MB_ICONSTOP | MB_OK);
		((CEdit *)GetDlgItem(IDC_INTER_AREA_SMCCODE_EDIT))->SetFocus();
		return;
	}
	if( m_ctrlCenterName.GetCount()>0 && m_szSMSCCode.IsEmpty() )
	{
		fmt.LoadString(IDS_WARNING_SMCCODE);
		temp.LoadString(IDS_HEADER_INITIAL);
        MessageBox(fmt,temp,MB_ICONSTOP | MB_OK);
		((CEdit *)GetDlgItem(IDC_SMSC_CODE_EDIT))->SetFocus();
		return;
	}
	if(m_ctrlCenterName.GetCount()>0)
	{
		CReadDB db;
		CString szMoniUnitName;
		m_ctrlCenterName.GetWindowText(szMoniUnitName);
		szMoniUnitName.TrimLeft();
		szMoniUnitName.TrimRight();
		CString szMoniUnitID;
		if(db.GetMoniUnitIDByMoniUnitName(szMoniUnitName,szMoniUnitID)==TRUE)
		{
			if(db.SaveSmsSettingMsgToDB(szMoniUnitID,m_szInterAreaSMCCode,m_szSMSCCode,m_szInterAreaMTCode,m_szPhoneCode)==FALSE)
			{
			    CString idgetstr,szcap;
				idgetstr.LoadString(IDS_DBCONNECT_SAVE_ERROR);
				szcap.LoadString(IDS_SAVEDB_CAPTION);
				MessageBox(idgetstr,szcap,MB_OK | MB_ICONWARNING);
			}
			else
				AfxGetApp()->WriteProfileString(s_profileHeading,s_profileMoniUnitName,szMoniUnitName);
		}
	}
	if (CanExit())
		CDialog::OnClose();
}

void CSmsComDlg::OnOK() 
{

}

BOOL CSmsComDlg::CanExit()
{
	// If the proxy object is still around, then the automation
	//  controller is still holding on to this application.  Leave
	//  the dialog around, but hide its UI.
	if (m_pAutoProxy != NULL)
	{
		ShowWindow(SW_HIDE);
		return FALSE;
	}

	return TRUE;
}

void CSmsComDlg::OnCloseComButton() 
{
	// TODO: Add your control notification handler code here
   /****   
   UpdateData(TRUE);

   CString fmt,temp;
   	if(m_szInterAreaSMCCode.IsEmpty())
	{
		fmt.LoadString(IDS_WARNING_SMCIAC);
		temp.LoadString(IDS_HEADER_INITIAL);
        MessageBox(fmt,temp,MB_ICONSTOP | MB_OK);
		((CEdit *)GetDlgItem(IDC_INTER_AREA_SMCCODE_EDIT))->SetFocus();
		return;
	}
	if(m_szSMSCCode.IsEmpty())
	{
		fmt.LoadString(IDS_WARNING_SMCCODE);
		temp.LoadString(IDS_HEADER_INITIAL);
        MessageBox(fmt,temp,MB_ICONSTOP | MB_OK);
		((CEdit *)GetDlgItem(IDC_SMSC_CODE_EDIT))->SetFocus();
		return;
	}
   m_ctrlGsmSms.SetSMSCCode(m_szSMSCCode);
   m_ctrlGsmSms.SetSMCInterAreaCode(m_szInterAreaSMCCode);
   m_ctrlGsmSms.SetMTInterAreaCode(m_szInterAreaMTCode);
   ****/
   if(m_ctrlSMSCom.GetPortOpen())
   {
	   int nCom;
	   CString szComCloseMsg,temp,szSetting,fmt;

       szSetting.Empty();
	   nCom=m_ctrlSMSCom.GetCommPort();
	   szSetting=m_ctrlSMSCom.GetSettings();
	   m_ctrlSMSCom.SetPortOpen(false);	
       if(m_ctrlSMSCom.GetPortOpen()==false)
	   {
		  szComCloseMsg.Empty();
		  szComCloseMsg.Format("关闭串口%d成功!",nCom);
#ifdef MY_DEBUG_MSG
          MessageBox(szComCloseMsg,"关闭串口",MB_ICONSTOP | MB_OK);
#else
#ifdef _DEBUG
	      TRACE("关闭串口::"+szComCloseMsg);
#endif
#endif

		  temp.Empty();
		  fmt.LoadString(IDS_PROMT_COMCLOSE_OK);
		  temp.Format(fmt,nCom);
		  //temp.Format("串口%d已关闭!其先前设置为:\n",nCom);
		  temp+=szSetting;
		  DispMsg(temp);

          m_ctrlGsmSms.AddToMTCodeList(szSetting,1);//清空
		  fmt.LoadString(IDS_PROMT_MTLIST_CNT);
		  szSetting.Format(fmt,0);
          //szSetting.Format("; MT个数0");
		  temp+=_T(";  ");
          temp+=szSetting;

          fmt.LoadString(IDS_PROMT_IAC );
	      temp+=fmt;
	      temp+=m_szInterAreaSMCCode;
		  temp+=_T(";MT:");
	      temp+=m_szInterAreaMTCode;
		  temp+=_T("   SMSCA:");
	      temp+=m_szSMSCCode;	      
	      m_szCurSettingPrompt=temp;
          UpdateData(FALSE);
	   }
   }
}

void CSmsComDlg::OnInitComButton() 
{
	// TODO: Add your control notification handler code here
	int nCom;
	//long nBode;
	CString temp,szSetting;
	CString fmt;

	UpdateData(TRUE);
	if(m_szInterAreaSMCCode.IsEmpty())
	{
		fmt.LoadString(IDS_WARNING_SMCIAC);
		temp.LoadString(IDS_HEADER_INITIAL);
        MessageBox(fmt,temp,MB_ICONSTOP | MB_OK);
		((CEdit *)GetDlgItem(IDC_INTER_AREA_SMCCODE_EDIT))->SetFocus();
		return;
	}
	if(m_szSMSCCode.IsEmpty())
	{
		fmt.LoadString(IDS_WARNING_SMCCODE);
		temp.LoadString(IDS_HEADER_INITIAL);
        MessageBox(fmt,temp,MB_ICONSTOP | MB_OK);
		((CEdit *)GetDlgItem(IDC_SMSC_CODE_EDIT))->SetFocus();
		return;
	}
    m_ctrlGsmSms.SetSMSCCode(m_szSMSCCode);
	m_ctrlGsmSms.SetCalledPhoneCode(m_szPhoneCode);
	m_ctrlGsmSms.SetSMCInterAreaCode(m_szInterAreaSMCCode);
	m_ctrlGsmSms.SetMTInterAreaCode(m_szInterAreaMTCode);

	int ncomboCurItem;
    ncomboCurItem=m_ctrlComSel.GetCurSel();
	m_nCurComSel=ncomboCurItem+1;
	ncomboCurItem=m_ctrlBaudSel.GetCurSel();
	m_nCurBaud=m_nBaudList[ncomboCurItem];

	szSetting.Empty();

	if(m_ctrlSMSCom.GetPortOpen())
	{
		nCom=m_ctrlSMSCom.GetCommPort();
		fmt.LoadString(IDS_PROMT_QUESTION);
		szSetting.Format(fmt,nCom,m_nCurComSel);
		//szSetting.Format("关闭已打开的串口%d,重新选择初始化串口%d吗?",nCom,m_nCurComSel);
		if(AfxMessageBox(szSetting,MB_YESNO|MB_ICONQUESTION)==IDYES)
			m_ctrlSMSCom.SetPortOpen(false);
		else
			return;
		szSetting.Empty();
	}

    m_ctrlSMSCom.SetCommPort(m_nCurComSel);
	
	temp.Empty();
	temp.Format("%d,n,8,1",m_nCurBaud);
	m_ctrlSMSCom.SetSettings((LPCTSTR)temp);
	m_ctrlSMSCom.SetInputLen(0);
	m_ctrlSMSCom.SetRThreshold(1);
	m_ctrlSMSCom.SetInputMode(1);   //0-Text,1-Binary
    m_ctrlSMSCom.SetOutBufferSize(1024);
    m_ctrlSMSCom.SetInBufferSize(1024);

	if(m_ctrlSMSCom.GetPortOpen()==false)
		m_ctrlSMSCom.SetPortOpen(true);
	if(m_ctrlSMSCom.GetPortOpen())
	{
		nCom=m_ctrlSMSCom.GetCommPort();
		szSetting=m_ctrlSMSCom.GetSettings();
    	temp.Format("串口%d初始化成功!\n",nCom);
		temp+=szSetting;
#ifdef MY_DEBUG_MSG
	    MessageBox(temp,"串口初始化",MB_OK | MB_ICONINFORMATION );
#else
#ifdef _DEBUG
	    TRACE("串口初始化::"+temp);
#endif
#endif

		temp.Empty();
		fmt.LoadString(IDS_PROMT_COMOPEN_OK);
		temp.Format(fmt,nCom);
		//temp.Format("成功打开了串口%d!其设置为:\n",nCom);
        temp+=szSetting;
	}
	else
	{
		nCom=m_ctrlSMSCom.GetCommPort();
		szSetting=m_ctrlSMSCom.GetSettings();
    	temp.Format("串口%d初始化成功!\n",nCom);
		temp+=szSetting;
    	temp.Format("串口%d初始化失败!\n",nCom);
#ifdef MY_DEBUG_MSG
	    MessageBox(temp,"串口初始化",MB_OK | MB_ICONWARNING );
#else
#ifdef _DEBUG
	    TRACE("串口初始化::"+temp);
#endif
#endif

		temp.Empty();
		fmt.LoadString(IDS_PROMT_COMOPEN_FAIL);
		temp.Format(fmt,nCom);
		//temp.Format("串口%d初始化失败!其设置为:\n",nCom);
		temp+=szSetting;
	}

	int nCnt=0;
	m_ctrlGsmSms.AddToMTCodeList(szSetting,1);//清空
	if(m_ctrlGsmSms.ReadMTCodeFromDBSet(nCnt)==FALSE)
	{
	     CString idgetstr,szcap;
		idgetstr.LoadString(IDS_READDB_ERROR);
		szcap.LoadString(IDS_READDB_CAPTION_SMMTLIST);
		MessageBox(idgetstr,szcap,MB_OK | MB_ICONWARNING);
	}
	fmt.LoadString(IDS_PROMT_MTLIST_CNT);
	szSetting.Format(fmt,nCnt);
    //szSetting.Format("; MT个数%d",nCnt);
	temp+=_T(";  ");
	temp+=szSetting;

	fmt.LoadString(IDS_PROMT_IAC);
	temp+=fmt;
	temp+=_T("SMC:");
	temp+=m_szInterAreaSMCCode;
	temp+=_T(";MT:");
	temp+=m_szInterAreaMTCode;
	temp+=_T("  SMSCA:");
	temp+=m_szSMSCCode;
	m_szCurSettingPrompt=temp;
	UpdateData(false);
}

/****
void CSmsComDlg::OnDialButton() 
{
	// TODO: Add your control notification handler code here
	char * pmsg;
	UpdateData(TRUE);
	pmsg=new char[m_szDialedPhoneCode.GetLength()+1];
	lstrcpy(pmsg,m_szDialedPhoneCode);
#ifdef MY_DEBUG_MSG
//	MessageBox(m_szDialedPhoneCode);
#else
#ifdef _DEBUG
	    TRACE(m_szDialedPhoneCode);
#endif
#endif
	PostMessage(MYMSG_GSMSMS_SENDMSG,DIAL_MSG_CLASS,(LPARAM)pmsg);

}
****/

void CSmsComDlg::OnSndsmsButton() 
{
	// TODO: Add your control notification handler code here
	int nblank;
	CString szSMMsg;
    char * pmsg;

	UpdateData(TRUE);
	CString temp,fmt;
	if(m_szSMText.IsEmpty())
	{
		fmt.LoadString(IDS_SNDSM_TEXT);
		temp.LoadString(IDS_SNDSM_HEADER);
        MessageBox(fmt,temp,MB_ICONSTOP | MB_OK);
		((CEdit *)GetDlgItem(IDC_SM_TEXT_EDIT))->SetFocus();
		return;
	}
	if(m_szPhoneCode.IsEmpty())
	{

⌨️ 快捷键说明

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