?? demodlg.cpp
字號(hào):
// DemoDlg.cpp : implementation file
//
#include "stdafx.h"
#include "Demo.h"
#include "DemoDlg.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()
/////////////////////////////////////////////////////////////////////////////
// CDemoDlg dialog
CString _timestamp( )
{
CTime tm = CTime::GetCurrentTime();
CString strtime = tm.Format("%y%m%d%H%M%S");
strtime += "032+";
return strtime;
}
CDemoDlg::CDemoDlg(CWnd* pParent /*=NULL*/)
: CDialog(CDemoDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CDemoDlg)
m_ip = _T("10.245.74.162");//_T("10.245.73.2");////_T("127.0.0.1");///
m_ip = _T("127.0.0.1");
m_port = _T("7890");
m_passwd = _T("hcww");// _T("szbc");
m_id =_T("wwch");// _T("szbc")
m_time = _T("1");
m_dest = _T("13424395236");
m_content = _T("深圳移動(dòng)CMPP短信動(dòng)態(tài)庫(kù)(api)測(cè)試");
m_btime = FALSE;
m_feecode = _T("000000");
m_feenumber = _T("");//_T("13544164060");
m_feetype = _T("01");
m_serviceid = _T("999999");//_T("test");//_T("-YXQC");
m_src = _T("0444211");//_T("05001");
m_attime = _timestamp();//_T("050921092330032+");
m_strSpid = _T("999999");
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CDemoDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CDemoDlg)
DDX_Text(pDX, IDC_EDIT_IP, m_ip);
DDX_Text(pDX, IDC_EDIT_PORT, m_port);
DDX_Text(pDX, IDC_EDIT_PASSWD, m_passwd);
DDX_Text(pDX, IDC_EDIT_ID, m_id);
DDX_Text(pDX, IDC_EDIT_DEST, m_dest);
DDX_Text(pDX, IDC_EDIT_CONTENT, m_content);
DDX_Text(pDX, IDC_EDIT_FEECODE, m_feecode);
DDX_Text(pDX, IDC_EDIT_FEENUMBER, m_feenumber);
DDX_Text(pDX, IDC_EDIT_FEETYPE, m_feetype);
DDX_Text(pDX, IDC_EDIT_SERVICEID, m_serviceid);
DDX_Text(pDX, IDC_EDIT_SRC, m_src);
DDX_Text(pDX, IDC_EDIT_ATTIME, m_attime);
DDX_Text(pDX, IDC_EDIT_SPID, m_strSpid);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CDemoDlg, CDialog)
//{{AFX_MSG_MAP(CDemoDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_BTN_LOGIN, OnBtnLogin)
ON_BN_CLICKED(IDC_BTN_LOGOUT, OnBtnLogout)
ON_BN_CLICKED(IDC_BTN_SUBMIT, OnBtnSubmit)
ON_BN_CLICKED(IDC_BTN_QUERY, OnBtnQuery)
ON_BN_CLICKED(IDC_BTN_CHECK_DELIVER, OnBtnCheckDeliver)
ON_BN_CLICKED(IDC_BTN_GET_DELIVER, OnBtnGetDeliver)
ON_EN_CHANGE(IDC_EDIT_CONTENT, OnChangeEditContent)
ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
ON_BN_CLICKED(IDC_BTN_LONG_SUB, OnBtnLongSub)
ON_BN_CLICKED(IDC_BTN_CANCEL, OnBtnCancel)
ON_BN_CLICKED(IDC_BTN_LONG_CANCEL, OnBtnLongCancel)
ON_BN_CLICKED(IDC_BTN_LONG_QUERY, OnBtnLongQuery)
ON_BN_CLICKED(IDC_BUTTON_RESEND, OnButtonResend)
ON_WM_CLOSE()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CDemoDlg message handlers
BOOL CDemoDlg::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
// TODO: Add extra initialization here
ret = new CMSGResult();
OnChangeEditContent();
return TRUE; // return TRUE unless you set the focus to a control
}
void CDemoDlg::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 CDemoDlg::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 CDemoDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
#include <afxsock.h> // MFC socket extensions
void CDemoDlg::OnBtnLogin()
{
// TODO: Add your control notification handler code here
UpdateData();
char ip[20];
char id[7];
char pwd[7];
memset(ip,0,20);
memset(id,0,7);
memset(pwd,0,7);
sprintf(ip,"%s",m_ip);
sprintf(id,"%s",m_id);
sprintf(pwd,"%s",m_passwd);
// int err = Init_connection_mo(ip,atoi(m_port));
int err = Init_connection(ip,atoi(m_port));
if (err)
{
AfxMessageBox("Init_connection() error");
return;
}
//err = Login_ismg_mo(id,pwd);
err = Login_ismg(id,pwd);
if (err)
{
AfxMessageBox("Login() error");
return;
}
AfxMessageBox("Login() ok");
}
void CDemoDlg::OnBtnLogout()
{
// TODO: Add your control notification handler code here
Logout_ismg();
Exit_connection();
}
void writeString(char *filename,char *pdata, int len)
{
CFile file;
file.Open(filename,CFile::modeCreate|CFile::modeWrite);
file.Write(pdata,len);
file.Write("\n\r",2);
file.Close();
}
void CDemoDlg::OnBtnSubmit()
{
// TODO: Add your control notification handler code here
UpdateData();
int err;
CMPP_SUBMIT sb; //短信發(fā)送體
//CMSGResult ret; //短信回應(yīng)信息
CString str;
int msglen =m_content.GetLength();
if(msglen>eCMPP_CONTENT_LEN)
{
AfxMessageBox("短信長(zhǎng)度超長(zhǎng)");
return;
}
sb.cMsgLen = msglen; //內(nèi)容長(zhǎng)度
sb.cRegisteredDelivery = 1; //返回狀態(tài)報(bào)告
strcpy((char*)sb.sSrcId , m_src); //業(yè)務(wù)ID
strcpy((char*)sb.sMsgSrc ,m_strSpid ); //服務(wù)ID
strcpy((char*)sb.sMsgContent , m_content); //信息內(nèi)容
strcpy((char*)sb.sServiceId,m_serviceid); //SERVICE_ID
strcpy((char*)sb.sFeeType , m_feetype); //收費(fèi)類型
strcpy((char*)sb.sFeeCode , m_feecode); //收費(fèi)代碼
strcpy((char*)sb.nFeeTerminaleId , m_feenumber);
strcpy((char*)sb.sAtTime, m_attime);
strcpy((char*)sb.sDestTerminalId , m_dest); //終端號(hào)碼
//err = Cmpp_submit(&sb,ret,&count);
int msgcount = Cmpp_submit_sub(&sb,ret);
if(msgcount <=0)
{
AfxMessageBox("發(fā)送失敗");
return;
}
CString errStr =""; //錯(cuò)誤字符串
err = Cmpp_query(ret,&errStr);
if(err<0)
{
AfxMessageBox("尚未接收到返回信息");
return ;
}
if(ret->SENDERR!=0||ret->UNGETRESP!=0)
{
str.Format("發(fā)送錯(cuò)誤\n錯(cuò)誤個(gè)數(shù) :%d\n 沒有回應(yīng)個(gè)數(shù): %d\n sp接收到信息總數(shù):%d\n",ret->SENDERR,ret->UNGETRESP);
AfxMessageBox(str+errStr);
}
else
{
AfxMessageBox("OK");
}
}
/*2005-12-17 zx
void CDemoDlg::OnBtnLongSub()
{
// TODO: Add your control notification handler code here
int err;
UpdateData();
ret_l.release();
CMPP_SUBMIT sb_l; //長(zhǎng)短信
strcpy((char*)sb_l.sSrcId , m_src);
strcpy((char*)sb_l.sDestTerminalId , m_dest);
strcpy((char*)sb_l.sMsgSrc , m_strSpid);//
strcpy((char*)sb_l.sServiceId,m_serviceid);
strcpy((char*)sb_l.sFeeType , m_feetype);
strcpy((char*)sb_l.sFeeCode , m_feecode);
strcpy((char*)sb_l.nFeeTerminaleId , m_feenumber);
strcpy((char*)sb_l.sAtTime,m_attime);
strcpy((char*)sb_l.sDestTerminalId , m_dest);
sb_l.cRegisteredDelivery = 1; //返回狀態(tài)報(bào)告,非1則沒有任何狀態(tài)返回
sb_l.cMsgFmt = 0x08;
sb_l.cTpUdhi = 1;
int err_c = 0;
ConfigTimeLSubmitTime(200);
int count = Cmpp_long_submit(&sb_l,m_content.GetBuffer(0),
m_content.GetLength(),&ret_l);
//int count = ret_l.getCount();
CString strTmp;
strTmp.Format("%d",count);
AfxMessageBox(strTmp);
Sleep(1000);
err = Cmpp_long_query(&ret_l);
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -