📄 tstdemdlg.cpp
字号:
// TstDemDlg.cpp : implementation file
//
#include "stdafx.h"
#include "TstDem.h"
#include "TstDemDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About
class CAboutDlg : public CDialog
{
public:
CAboutDlg();
// Dialog Data
//{{AFX_DATA(CAboutDlg)
enum { IDD = IDD_ABOUTBOX };
//}}AFX_DATA
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CAboutDlg)
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL
// Implementation
protected:
//{{AFX_MSG(CAboutDlg)
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
//{{AFX_DATA_INIT(CAboutDlg)
//}}AFX_DATA_INIT
}
void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CAboutDlg)
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
//{{AFX_MSG_MAP(CAboutDlg)
// No message handlers
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CTstDemDlg dialog
CTstDemDlg::CTstDemDlg(CWnd* pParent /*=NULL*/)
: CDialog(CTstDemDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CTstDemDlg)
m_iComPort = 0;
m_Phone = _T("1382523");
m_ShortMsg = _T("恭喜发财,测试信息!");
m_Prompt = _T("100: 授权错误(检测软件狗)\r\n101: 授权类型错误(检测软件狗类型)\r\n102: 未初始化,请先初始化\r\n200: 端口号码错\r\n201: 不支持的端口\r\n202: 信息超长\r\n203: 不能发送空信息\r\n204: 手机号码错\r\n205: 设备错\r\n206: 检测中心错\r\n207: 网络登录错\r\n208: 设置格式错\r\n209: 系统忙\r\n210: 发送超时\r\n5xx: xx号端口不存在或被其他程序占用");
m_ModemType = 0;
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CTstDemDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CTstDemDlg)
DDX_CBIndex(pDX, IDC_COM_PORT, m_iComPort);
DDX_Text(pDX, IDC_PHONE, m_Phone);
DDV_MaxChars(pDX, m_Phone, 11);
DDX_Text(pDX, IDC_SMSG, m_ShortMsg);
DDV_MaxChars(pDX, m_ShortMsg, 30);
DDX_Text(pDX, IDC_PROMPT, m_Prompt);
DDX_CBIndex(pDX, IDC_MODEM_TYPE, m_ModemType);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CTstDemDlg, CDialog)
//{{AFX_MSG_MAP(CTstDemDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_BUT_INIT, OnButInit)
ON_BN_CLICKED(IDC_BUT_SEND, OnButSend)
ON_WM_DESTROY()
ON_BN_CLICKED(IDC_BUT_READ, OnButRead)
ON_BN_CLICKED(IDC_BUT_CLOSE, OnButClose)
ON_WM_TIMER()
ON_BN_CLICKED(IDC_BUT_READ_QUE, OnButReadQue)
ON_BN_CLICKED(IDC_BUT_READ_REC, OnButReadRec)
ON_BN_CLICKED(IDC_BUT_CLEAR_QUE, OnButClearQue)
ON_BN_CLICKED(IDC_BUT_CLEAR_REC, OnButClearRec)
ON_BN_CLICKED(IDC_BUT_READ2, OnButRead2)
ON_EN_CHANGE(IDC_SMSG, OnChangeSmsg)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CTstDemDlg message handlers
//====------------------------------------------------
//函数定义
typedef LONG (CALLBACK* LPFNDLLFUNC1)(LONG);
typedef LONG (CALLBACK* LPFNDLLFUNC2)(LONG);
typedef LONG (CALLBACK* LPFNDLLFUNC3)(LONG,CHAR *,CHAR *);
typedef LONG (CALLBACK* LPFNDLLFUNC4)(LONG,CHAR *,CHAR *);
typedef LONG (CALLBACK* LPFNDLLFUNC5)(LONG);
typedef LONG (CALLBACK* LPFNDLLFUNC6)();
typedef LONG (CALLBACK* LPFNDLLFUNC7)(LONG,LONG);
typedef LONG (CALLBACK* LPFNDLLFUNC8)(CHAR *,CHAR *,CHAR *);
HINSTANCE hInsDLL;
LPFNDLLFUNC1 fnInitModem; // Function pointer 1
LPFNDLLFUNC2 fnCloseModem; // Function pointer 2
LPFNDLLFUNC3 fnSendMsg; // Function pointer 3
LPFNDLLFUNC4 fnReadMsgEx; // Function pointer 4
LPFNDLLFUNC4 fnReadMsgExNotDelete; // Function pointer 4
LPFNDLLFUNC5 fnGetStatus; // Function pointer 5
LPFNDLLFUNC5 fnGetSndCount;
LPFNDLLFUNC5 fnGetRecCount;
LPFNDLLFUNC5 fnClrSndBuf;
LPFNDLLFUNC5 fnClrRecBuf;
LPFNDLLFUNC6 fnDogSerial;
LPFNDLLFUNC7 fnDeleteSimMsg;
LPFNDLLFUNC8 fnWapPushCvt;
//long __stdcall fnDeleteSimMsg(long pno,long nSimIdx)
LPFNDLLFUNC7 fnSetModemType;
//====------------------------------------------------
BOOL CTstDemDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// Add "About..." menu item to system menu.
// IDM_ABOUTBOX must be in the system command range.
ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
ASSERT(IDM_ABOUTBOX < 0xF000);
CMenu* pSysMenu = GetSystemMenu(FALSE);
if (pSysMenu != NULL)
{
CString strAboutMenu;
strAboutMenu.LoadString(IDS_ABOUTBOX);
if (!strAboutMenu.IsEmpty())
{
pSysMenu->AppendMenu(MF_SEPARATOR);
pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
}
}
// 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
//====------------------------------------------------
//取得函数地址
hInsDLL=LoadLibrary("MonDem");
if(hInsDLL==NULL) hInsDLL=LoadLibrary("..\\MonDem");
if(hInsDLL==NULL){
MessageBox("装载动态连接库MonDem.dll错误");
} else {
fnInitModem=(LPFNDLLFUNC1)GetProcAddress(hInsDLL,"fnInitModem");
fnCloseModem=(LPFNDLLFUNC2)GetProcAddress(hInsDLL,"fnCloseModem");
fnSendMsg=(LPFNDLLFUNC3)GetProcAddress(hInsDLL,"fnSendMsg");
fnReadMsgEx=(LPFNDLLFUNC4)GetProcAddress(hInsDLL,"fnReadMsgEx");
fnReadMsgExNotDelete=(LPFNDLLFUNC4)GetProcAddress(hInsDLL,"fnReadMsgExNotDelete");
fnGetStatus=(LPFNDLLFUNC5)GetProcAddress(hInsDLL,"fnGetStatus");
fnGetSndCount=(LPFNDLLFUNC5)GetProcAddress(hInsDLL,"fnGetSndCount");
fnGetRecCount=(LPFNDLLFUNC5)GetProcAddress(hInsDLL,"fnGetRecCount");
fnClrSndBuf=(LPFNDLLFUNC5)GetProcAddress(hInsDLL,"fnClrSndBuf");
fnClrRecBuf=(LPFNDLLFUNC5)GetProcAddress(hInsDLL,"fnClrRecBuf");
fnDogSerial=(LPFNDLLFUNC6)GetProcAddress(hInsDLL,"fnDogSerial");
fnSetModemType=(LPFNDLLFUNC7)GetProcAddress(hInsDLL,"fnSetModemType");
fnDeleteSimMsg=(LPFNDLLFUNC7)GetProcAddress(hInsDLL,"fnDeleteSimMsg");
fnWapPushCvt=(LPFNDLLFUNC8)GetProcAddress(hInsDLL,"fnWapPushCvt");
}
//====------------------------------------------------
//====------------------------------------------------
//设置读取状态定时器
SetTimer(1,200,NULL);
//====------------------------------------------------
return TRUE; // return TRUE unless you set the focus to a control
}
void CTstDemDlg::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 CTstDemDlg::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 CTstDemDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CTstDemDlg::OnButInit()
{
// 初始化
UpdateData(TRUE);
for(int i=0;i<10;i++) fnSetModemType(i,m_ModemType);
int nRc;
if(m_iComPort==8) nRc=fnInitModem(-1); //所有端口
else nRc=fnInitModem(m_iComPort); //端口1-8
if(nRc==0) MessageBox("初始化成功");
else {
CString csTmp;
csTmp.Format("初始化失败,错误代码 %d",nRc);
MessageBox(csTmp);
}
}
void CTstDemDlg::OnButSend()
{
char szHeader[1024]={0};
char szMsg[1024]={0};
int PortNo;
CString csTmp;
UpdateData(TRUE);
if(m_iComPort==8) PortNo=-1; //所有端口
else PortNo=m_iComPort; //端口1-8
//目标手机号码+序列号+已发送次数+发送者ID+发送类型+报告类型 (共六项)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -