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

📄 mymodemdlg.cpp

📁 有gsm打电话功能.可以做图象处理.还有unicode的转化函数
💻 CPP
📖 第 1 页 / 共 2 页
字号:
// MyModemDlg.cpp : implementation file
//

#include "stdafx.h"
#include "MyModem.h"
#include "MyModemDlg.h"
#include "DBFEngine.h"

#include "caminc.hpp"
#include "camio.hpp"
#include "camlink.hpp"

#include "ShowBMP.h"
#include "Show.h"

#include "TCPClientDlg.h"

#pragma comment(lib,"camlink.lib")

CDbFile g_dbf;
HANDLE hCommDev;
int g_nFirst=0;
BYTE g_sFirst=0;
char c[2];
TCHAR cc[120];


int w=0;

CTCPClient_CE m_tcpClient;

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

/////////////////////////////////////////////////////////////////////////////
// CMyModemDlg dialog

CMyModemDlg::CMyModemDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CMyModemDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CMyModemDlg)
	m_sCommand = _T("");
	m_sText = _T("");
	m_sReceive = _T("");

	m_remoteHost = _T("");
	m_remotePort = 0;
	m_recvData = _T("");
	m_sendData = _T("");

	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void CMyModemDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CMyModemDlg)
	DDX_Text(pDX, IDC_EDIT1, m_sCommand);
	DDX_Text(pDX, IDC_EDIT2, m_sText);
	DDX_Text(pDX, IDC_EDIT3, m_sReceive);

	DDX_Control(pDX, IDC_ShowBMP, m_ShowBMP);

	DDX_Text(pDX, IDC_EDTREMOTEHOST, m_remoteHost);
	DDX_Text(pDX, IDC_EDTREMOTEPORT, m_remotePort);
	DDX_Text(pDX, IDC_EDTRECV, m_recvData);
	DDX_Text(pDX, IDC_EDTSENDDATA, m_sendData);

	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CMyModemDlg, CDialog)
	//{{AFX_MSG_MAP(CMyModemDlg)
	ON_BN_CLICKED(IDC_SEND, OnSend)
	ON_BN_CLICKED(IDC_PICKUP, OnPickup)
	ON_BN_CLICKED(ID_SENDTEXT, OnSendtext)
	ON_BN_CLICKED(ID_SENDTEXT2, OnSendtext2)
	ON_EN_SETFOCUS(IDC_EDIT1, OnSetfocusEdit1)
	ON_EN_SETFOCUS(IDC_EDIT2, OnSetfocusEdit2)
	ON_WM_CHAR()
	ON_WM_TIMER()
	ON_WM_DESTROY()

	ON_BN_CLICKED(IDC_STOP, OnStop)

	ON_BN_CLICKED(IDC_BTNCONN, OnBtnconn)
    ON_BN_CLICKED(IDC_BTNDISCONN, OnBtndisconn)
    ON_BN_CLICKED(IDC_BTNSENDDATA, OnBtnsenddata)
//	ON_EN_CHANGE(IDC_EDTSENDDATA, OnChangeEdtsenddata)

	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CMyModemDlg message handlers

BOOL CMyModemDlg::OnInitDialog()
{
	m_bFullScreen = FALSE;
	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
	
	CenterWindow(GetDesktopWindow());	// center to the hpc screen

	hCommDev=CreateFile(_T("COM1:"),GENERIC_READ | GENERIC_WRITE,
						0,
						NULL,
						OPEN_EXISTING,
						0,
						NULL);
	if(hCommDev==(HANDLE)-1)
		{
		::MessageBox(NULL,_T("对不起,程序好象打开拉:)"),_T("出错拉"),MB_ICONEXCLAMATION);
		
		return 0;
		}
	DCB PortDCB;
	PortDCB.DCBlength = sizeof (DCB);     

  // Get the default port setting information.
  GetCommState (hCommDev, &PortDCB);

  // Change the DCB structure settings.
  PortDCB.BaudRate = 9600;              // Current baud 
  PortDCB.fBinary = TRUE;               // Binary mode; no EOF check 
  PortDCB.fParity = TRUE;               // Enable parity checking 
  PortDCB.fOutxCtsFlow = FALSE;         // No CTS output flow control 
  PortDCB.fOutxDsrFlow = FALSE;         // No DSR output flow control 
  PortDCB.fDtrControl = DTR_CONTROL_ENABLE; 
                                        // DTR flow control type 
  PortDCB.fDsrSensitivity = FALSE;      // DSR sensitivity 
  PortDCB.fTXContinueOnXoff = TRUE;     // XOFF continues Tx 
  PortDCB.fOutX = FALSE;                // No XON/XOFF out flow control 
  PortDCB.fInX = FALSE;                 // No XON/XOFF in flow control 
  PortDCB.fErrorChar = FALSE;           // Disable error replacement 
  PortDCB.fNull = FALSE;                // Disable null stripping 
  PortDCB.fRtsControl = RTS_CONTROL_ENABLE; 
                                        // RTS flow control 
  PortDCB.fAbortOnError = FALSE;        // Do not abort reads/writes on 
                                        // error
  PortDCB.ByteSize = 8;                 // Number of bits/byte, 4-8 
  PortDCB.Parity = NOPARITY;            // 0-4=no,odd,even,mark,space 
  PortDCB.StopBits = ONESTOPBIT;        // 0,1,2 = 1, 1.5, 2 

  // Configure the port according to the specifications of the DCB 
  // structure.
  if (!SetCommState (hCommDev, &PortDCB))
  {
    // Could not create the read thread.
	  ::MessageBox (NULL, TEXT("不能配置串行口"), 
                TEXT("出错拉"), MB_OK);
    return FALSE;
  }

COMMTIMEOUTS CommTimeouts;
  CommTimeouts.ReadIntervalTimeout = MAXDWORD;  
  CommTimeouts.ReadTotalTimeoutMultiplier = 0;  
  CommTimeouts.ReadTotalTimeoutConstant = 0;    
  CommTimeouts.WriteTotalTimeoutMultiplier = 0;  
  CommTimeouts.WriteTotalTimeoutConstant = 1000;    

  if (!SetCommTimeouts (hCommDev, &CommTimeouts))
  {
    // Could not create the read thread.
	  ::MessageBox (NULL,TEXT("不能设置超时参数"), 
                TEXT("出错拉"), MB_OK);
    return 0;
  }
  PurgeComm(hCommDev,PURGE_TXCLEAR);
  PurgeComm(hCommDev,PURGE_RXCLEAR);
  DWORD dw;
  char sc[60];
  g_dbf.WideCharToChar(_T("AT\r"),sc);
  WriteFile(hCommDev,(BYTE*)sc,strlen(sc)*2,&dw,NULL);

  SetTimer(1,55,NULL);

	

	m_ShowBMP.InitBmpCtrl();
	m_ShowBMP.OnStartTimer();

		//初始化输入值
	//m_remoteHost = GetLocalIP();
	m_remoteHost = _T("192.168.0.3");
	m_remotePort = 5000;
	UpdateData(FALSE);

	return TRUE;  // return TRUE  unless you set the focus to a control
	
}




void CMyModemDlg::OnSend() //拨号
{
UpdateData(1);
if(m_sCommand==_T(""))return;
DWORD dw;
m_sCommand=_T("ATDT")+m_sCommand+_T("\r");
char sc[60];
g_dbf.WideCharToChar(m_sCommand,sc);
WriteFile(hCommDev,(BYTE*)sc,strlen(sc)*2,&dw,NULL);
}



void CMyModemDlg::OnPickup() //启动程序
{
		m_ShowBMP.OnStartTimer();
		CMyModemDlg::OnSend();


	
}

//add lvk
void CMyModemDlg::Strgsm() //报警代码
{
	::MessageBeep(0xFFFFFFFF);  // Beep
	::MessageBeep(0xFFFFFFFF);  // Beep		
	::MessageBeep(0xFFFFFFFF);  // Beep
	::MessageBeep(0xFFFFFFFF);  // Beep
	::MessageBeep(0xFFFFFFFF);  // Beep		
	::MessageBeep(0xFFFFFFFF);  // Beep


	CString	m_sCommand1;			//下面这段代码是直接将号码嵌入程序的
	DWORD dw;
	m_sCommand1=_T("ATD +8613761020225;\r\n");
	char sc[60];
	g_dbf.WideCharToChar(m_sCommand1,sc);
	WriteFile(hCommDev,(BYTE*)sc,strlen(sc)*2,&dw,NULL);


	//add 7.6
	if(w>=1)
	{
		w=0;
		CString	m_sCommand2;			//下面这段代码是直接将号码嵌入程序的
		DWORD dw2;
		m_sCommand2=_T("ATH\r\n");
		char sc1[60];
		g_dbf.WideCharToChar(m_sCommand2,sc1);
		WriteFile(hCommDev,(BYTE*)sc1,strlen(sc1)*2,&dw2,NULL);			

	}
	else
	{
		w++;
	}
	//add 7.6
	
	//CMyModemDlg::OnSend();

	//add lvk
	CString m_sendData1;
	m_sendData1=L"+++Attention Fire Alarming+++";
	char * sendBuf1;
	int sendLen1=0;
	//UpdateData(TRUE);	
	sendLen1 = m_sendData1.GetLength();
	sendBuf1 = new char[sendLen1*2];
	wcstombs(sendBuf1,m_sendData1,sendLen1);
	if (!m_tcpClient.SendData(sendBuf1,sendLen1))
	{
		AfxMessageBox(_T("发送失败"));
	}
	delete[] sendBuf1;
	sendBuf1 = NULL;
	::MessageBeep(0xFFFFFFFF);  // Beep
	::MessageBeep(0xFFFFFFFF);  // Beep
	::MessageBeep(0xFFFFFFFF);  // Beep
	::MessageBeep(0xFFFFFFFF);  // Beep
	::MessageBeep(0xFFFFFFFF);  // Beep		
	::MessageBeep(0xFFFFFFFF);  // Beep
}




void CMyModemDlg::OnSendtext() //实时发送
{
UpdateData(1);
if(m_sText==_T(""))return;
DWORD dw;
char sc[60];
g_dbf.WideCharToChar(m_sText,sc);
WriteFile(hCommDev,(BYTE*)sc,strlen(sc)*2,&dw,NULL);
}

void CMyModemDlg::OnSendtext2() //发送文件
{
	
}

void CMyModemDlg::OnCancel() //退出
{

EndDialog(0);
m_ShowBMP.OnStopTimer();	

//	CDialog::OnCancel();
}



//DEL void CMyModemDlg::OnStart() //显示画面
//DEL {
//DEL 	// TODO: Add your control notification handler code here
//DEL 	//根据文件名,加载位图
//DEL 	m_ShowBMP.OnStartTimer();

⌨️ 快捷键说明

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