📄 duanxindlg.cpp
字号:
// DuanXinDlg.cpp : implementation file
//
#include "stdafx.h"
#include "DuanXin.h"
#include "DuanXinDlg.h"
#include "stdio.h"
#include "string.h"
#include "trim.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
#define TRIM(P) bases_TrimBoth(P)
/////////////////////////////////////////////////////////////////////////////
// CDuanXinDlg dialog
CDuanXinDlg::CDuanXinDlg(CWnd* pParent /*=NULL*/)
: CDialog(CDuanXinDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CDuanXinDlg)
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CDuanXinDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CDuanXinDlg)
DDX_Control(pDX, IDC_CONNECT, m_Button);
DDX_Control(pDX, IDC_LIST1, m_LIST);
DDX_Control(pDX, IDC_PORT, m_PORT);
DDX_Control(pDX, IDC_INFORMATION, m_INFORMATON);
DDX_Control(pDX, IDC_ADDRESS, m_ADDRESS);
DDX_Control(pDX, IDC_MOBILE, m_MOBILE);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CDuanXinDlg, CDialog)
//{{AFX_MSG_MAP(CDuanXinDlg)
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_ADD_MOBILE, OnAddMobile)
ON_BN_CLICKED(IDC_REVER_MOBILE, OnReverMobile)
ON_BN_CLICKED(IDC_CONNECT, OnConnect)
ON_BN_CLICKED(IDC_OPEN_FILE_DIALOG, OnOpenFileDialog)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CDuanXinDlg message handlers
/************************************************************************************
* 功能描述: 数据的初始化
输入参数: 无
返回值: 无
编写: 张明
日期: 20060407
************************************************************************************/
BOOL CDuanXinDlg::OnInitDialog()
{
CDialog::OnInitDialog();
char m_filename [128], m_tmp[100];
// 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
memset(m_filename, 0, 128) ;
memset(m_tmp, 0, 100) ;
strcpy(m_filename, ".\\chat.ini") ;
GetPrivateProfileString("INIT", "INIT_IP", " ", m_tmp, 100, m_filename);
m_ADDRESS.SetWindowText(m_tmp) ;
GetPrivateProfileString("INIT", "INIT_PORT", " ", m_tmp, 100, m_filename);
m_PORT.SetWindowText(m_tmp) ;
p_head = new MOBILE;
memset(p_head,0,sizeof(MOBILE));
p_head->next =NULL;
// TODO: Add extra initialization here
return TRUE; // return TRUE unless you set the focus to a control
}
// 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 CDuanXinDlg::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 CDuanXinDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
/************************************************************************************
* 功能描述: 添加手机号码
数据结构: 链表
输入参数: 无
返回值: 无
编写: 张明
日期: 20060407
************************************************************************************/
void CDuanXinDlg::OnAddMobile()
{
/*
int i =0 ;
MOBILE *p_mobile=NULL; //MOBILE为结构体
memset(mobile,0,21);
MOBILE *p_head1 = p_head;
// char sztmp[21] ="\0";
*/
CDuanXinApp *pApp=(CDuanXinApp *)AfxGetApp();
CDuanXinDlg *pDlg=(CDuanXinDlg *)pApp->m_pMainWnd;
pDlg->m_MOBILE.GetLine(0,mobile,16);
Add_Mobile(mobile);
}
/************************************************************************************
* 功能描述: 删除手机号码
数据结构: 链表
输入参数: 无
返回值: 无
编写: 张明
日期: 20060407
************************************************************************************/
void CDuanXinDlg::OnReverMobile()
{
// TODO: Add your control notification handler code here
int i=0;
i = AfxMessageBox("Are you sure delete y/n ",MB_YESNO,0);
if(i == IDYES)
{
i = 0;
}
else
{
i=0;
return ;
}
MOBILE * p_list_mobile , * p_privete;
char number[21]= "\0";
i = m_LIST.GetCurSel( );
if(m_LIST.GetText(i,number) == LB_ERR)
{
AfxMessageBox(" get you select is error");
return ;
}
p_list_mobile = p_head;
m_LIST.DeleteString(i);
while((strlen(p_list_mobile->sz_mobile)!=0)||(p_list_mobile->next !=NULL))
{
if(strcmp(p_list_mobile->sz_mobile,number)==0)
{
if((p_list_mobile->next) == NULL)
{
delete p_list_mobile;
p_privete->next =NULL;
//AfxMessageBox(" delete success",MB_OK|MB_NO,0);
}
else
{
p_privete->next = p_list_mobile->next;
delete p_list_mobile;
// AfxMessageBox(" delete success");
}
break;
}
p_privete = p_list_mobile;
p_list_mobile = p_list_mobile->next;
}
}
/************************************************************************************
* 功能描述: 函数实现与银信通的 数据连接
输入参数: 无
返回值: 无
编写: 张明
************************************************************************************/
void CDuanXinDlg::OnConnect()
{
char m_addr[21], m_port[8], m_tmp[128] ;
char information[502] = "\0";
int sock ,ret;
// int i , line_num ,b=0;
char send_message[MAX_LEN] ;
// char *p_line ;
char *p_message;
char recv_message[100] ="\0";
char sz_judge[4] ="\0";
MOBILE * head1 = NULL ;
/*
head1 = p_head;
while((strlen(head1->sz_mobile)!=0||head1->next !=NULL))
{
sprintf(information,"%s",head1->sz_mobile);
AfxMessageBox(information);
head1 = head1->next;
if(head1->next==NULL)
break;
}
*/
struct STSMSInfo
{
char m_szAccount[21];
char m_szAccName[21];
char m_szMobile[16];
char m_szSend[2];
char m_szPay[2];
char m_szCod[5];
char m_szMess[501];
char m_szOther[21];
char m_szClient[2];
};
STSMSInfo stSMSInfo;
CDuanXinApp *pApp=(CDuanXinApp *)AfxGetApp();
CDuanXinDlg *pDlg=(CDuanXinDlg *)pApp->m_pMainWnd;
m_Button.ShowWindow(SW_HIDE);
/*
line_num = m_INFORMATON.GetLineCount();
p_line = information ;
for( i=0 ; i<line_num ;i++)
{
m_INFORMATON.GetLine(i, p_line,22);
//p_line = p_line + strlen(p_line);
b = b+strlen(p_line);
if(b>502-22)
break;
}
p_line = NULL;
*/
m_INFORMATON.GetWindowText(information,500);
if(p_head->next!=NULL)
{
head1 = p_head->next;
}
else
{
AfxMessageBox(" you did not write mobile number ");
m_Button.ShowWindow(SW_SHOW);
return;
}
while((strlen(head1->sz_mobile)!=0)||head1->next != NULL)
{
p_message = send_message;
memset(send_message, 0, sizeof(send_message));
memset(&stSMSInfo, 0 , sizeof(stSMSInfo));
strcpy(stSMSInfo.m_szAccount, "60142810570185701");
strcpy(stSMSInfo.m_szSend, "0");
strcpy(stSMSInfo.m_szPay, "2");
strcpy(stSMSInfo.m_szOther,"0000000"); //"00010000000000000000");
strcpy(stSMSInfo.m_szClient, "0");
strcpy(stSMSInfo.m_szAccName, "Ming");
/* 移动 */
strcpy(stSMSInfo.m_szMobile, head1->sz_mobile);
strcpy(stSMSInfo.m_szMess,information);
//strcpy(stSMSInfo.m_szOther," ");
strncpy(sz_judge,head1->sz_mobile,3);
if(strcmp(sz_judge,"130")==0||strcmp(sz_judge,"131")==0
||strcmp(sz_judge,"132")==0
||strcmp(sz_judge,"133")==0 )
{
strcpy(stSMSInfo.m_szCod, "0002");
}
else
{
strcpy(stSMSInfo.m_szCod, "0001");
}
/* 联通 */
//strcpy(stSMSInfo.m_szMobile, "13070415621");
// strcpy(stSMSInfo.m_szCod, "0002");
strcpy(p_message,stSMSInfo.m_szAccount);
strcpy(p_message=p_message+sizeof(stSMSInfo.m_szAccount),stSMSInfo.m_szAccName);
strcpy(p_message=p_message+sizeof(stSMSInfo.m_szAccName),stSMSInfo.m_szMobile);
strcpy(p_message=p_message+sizeof(stSMSInfo.m_szMobile), stSMSInfo.m_szSend);
strcpy(p_message=p_message+sizeof(stSMSInfo.m_szSend), stSMSInfo.m_szPay);
strcpy(p_message=p_message+sizeof(stSMSInfo.m_szPay), stSMSInfo.m_szCod);
strcpy(p_message=p_message+sizeof(stSMSInfo.m_szCod),stSMSInfo.m_szMess);
strcpy(p_message=p_message+sizeof(stSMSInfo.m_szMess), stSMSInfo.m_szOther);
strcpy(p_message =p_message+sizeof(stSMSInfo.m_szOther), stSMSInfo.m_szClient);
p_message = NULL;
/*
sprintf(send_message,"%21s",stSMSInfo.m_szAccount);
sprintf(send_message+strlen(send_message),"%21s",stSMSInfo.m_szAccName);
sprintf(send_message+strlen(send_message),"%16s",stSMSInfo.m_szMobile);
sprintf(send_message+strlen(send_message),"%2s",stSMSInfo.m_szSend);
sprintf(send_message+strlen(send_message),"%2s", stSMSInfo.m_szPay);
sprintf(send_message+strlen(send_message),"%5s" , stSMSInfo.m_szCod);
sprintf(send_message+strlen(send_message),"%501s", stSMSInfo.m_szMess);
sprintf(send_message+strlen(send_message), "%21s" , stSMSInfo.m_szOther);
sprintf(send_message+strlen(send_message),"%2s", stSMSInfo.m_szClient);
*/
memset(m_addr, 0, sizeof(m_addr)) ;
memset(m_port, 0, sizeof(m_port)) ;
memset(m_tmp, 0, sizeof(m_tmp)) ;
pDlg->m_ADDRESS.GetLine(0,m_addr, 20);
pDlg->m_PORT.GetLine(0,m_port, 7);
struct sockaddr_in addr;
memset(&addr, 0, sizeof(addr));
sock = socket(AF_INET, SOCK_STREAM, 0);
if(sock==SOCKET_ERROR)
{
AfxMessageBox("Create socket error!") ;
goto ERROR_PROC ;
}
addr.sin_family =AF_INET;
addr.sin_port =htons(atoi(m_port));
addr.sin_addr.s_addr = inet_addr(m_addr);
ret = connect( sock,(struct sockaddr*) &addr,(int)sizeof(addr));
if(ret == SOCKET_ERROR)
{
AfxMessageBox("connect error " );
closesocket(sock);
goto ERROR_PROC;
}
else
{
if( send(sock,send_message,sizeof(send_message),0)==SOCKET_ERROR)
//if( send(sock,(char *)&stSMSInfo,sizeof(stSMSInfo),0)==SOCKET_ERROR)
{
AfxMessageBox("send Error ");
closesocket(sock);
goto ERROR_PROC;
}
}
if(recv(sock, recv_message, sizeof(recv_message), 0) == SOCKET_ERROR)
{
AfxMessageBox(" 未接收到返回消息 出错 message is error" );
closesocket(sock);
goto ERROR_PROC;
}
else
{
if(strcmp(recv_message , "0001")==0)
{
}
else
{
sprintf(m_tmp,"接收alink 返回消息出错[%s] 手机号是[%s]",recv_message,stSMSInfo.m_szMobile);
AfxMessageBox(m_tmp) ;
closesocket(sock);
goto ERROR_PROC;
}
}
/**
ret = co_sock.Create() ;
// ret = co_sock.Create(0,SOCK_STREAM, FD_CONNECT|FD_CLOSE, (LPCTSTR)m_addr ) ;
if(!ret)
{
ret = co_sock.GetLastError() ;
sprintf(m_tmp,"1.建立sock错误码[%d]",ret) ;
AfxMessageBox(m_tmp) ;
return ;
}
AfxMessageBox(m_addr);
AfxMessageBox(m_port);
ret = co_sock.Connect(m_addr, (UINT)(atoi(m_port))) ;
if(!ret)
{
ret = co_sock.GetLastError() ;
sprintf(m_tmp,"2.连接sock错误码[%d]",ret) ;
AfxMessageBox(m_tmp) ;
}
**/
if(head1->next == NULL)
{
closesocket(sock);
break;
}
closesocket(sock);
head1 = head1->next;
}
AfxMessageBox("Connect ,send Success " );
ERROR_PROC:
if(p_head->next==NULL)
{
}
else
{
head1 = p_head->next;
MOBILE * lose_list;
while(head1->next!= NULL)
{
lose_list =head1->next;
delete head1 ;
head1 =lose_list;
}
delete head1;
}
p_head->next=NULL;
m_LIST.ResetContent();
m_Button.ShowWindow(SW_SHOW);
}
/*************************************************************************************
* 函数名:OnOpenFileDialog
实现功能:读取文件并将其送到链表中
参数: 无
返回值: 无
*
*
*
*
***************************************************************************************/
void CDuanXinDlg::OnOpenFileDialog()
{
// TODO: Add your control notification handler code here
FILE *fp = NULL;
char File_Path[1024] = "\0" ;
char Read_Txt[1024] ="\0" ;
CFileDialog Read_File_Dialog(TRUE,NULL,NULL,OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,NULL);
if(Read_File_Dialog.DoModal()==IDOK )
{
strcpy(File_Path,(LPCTSTR) Read_File_Dialog.GetFileName());
if(strlen(File_Path)==0)
{
AfxMessageBox("File name is null ");
return ;
}
if((fp=fopen(File_Path,"r"))<0)
{
AfxMessageBox("File Open is error ");
fclose(fp);
return;
}
else
{
while(fgets(Read_Txt,1024,fp) != NULL)
{
TRIM(Read_Txt);
Add_Mobile(Read_Txt);
}
}
}
}
void CDuanXinDlg::Add_Mobile(char *mobile)
{
int i =0 ;
MOBILE *p_mobile=NULL; //MOBILE为结构体
//memset(mobile,0,21);
MOBILE *p_head1 = p_head;
if(strlen(mobile)==0)
{
AfxMessageBox(" you mobile number is NULL");
return;
}
else
{
while(1) //链表操作
{
i++;
if(p_head1->next == NULL)
{
p_head1->next = new MOBILE;
//memset(p_head1->next,0,sizeof(MOBILE));
p_mobile = p_head1->next;
memset((p_mobile->sz_mobile),0 ,21);
p_mobile->next = NULL;
break ;
}
else
{
p_head1=p_head1->next;
/*
sprintf(sztmp,"%s",p_head1->sz_mobile);
AfxMessageBox(sztmp);
*/
}
}
strcpy(p_mobile->sz_mobile,mobile);
if((m_LIST.AddString(p_mobile->sz_mobile))==LB_ERR )
{
AfxMessageBox(" you insert message is error");
}
m_MOBILE.SetSel(0, -1);
m_MOBILE.Clear();
}
return;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -