?? dlgsendmes.cpp.bak
字號:
// DlgSendMes.cpp : implementation file
//
#include "stdafx.h"
#include "AdoDataGrid.h"
#include "DlgSendMes.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
extern BOOL ReadReg(char *subkey, char *itemname, BYTE *buf);
extern BOOL SaveReg(char *subkey, char *itemname, BYTE *buf,DWORD type=REG_SZ);
/////////////////////////////////////////////////////////////////////////////
// CDlgSendMes dialog
char s_AllContext[151]={'\0'};
char Name[33]={'\0'};
char PassWord[65]={'\0'};
char Ip[51]={'\0'};
UINT Port=0;
const char filter[]="0123456789";
CDlgSendMes::CDlgSendMes(CWnd* pParent /*=NULL*/)
: CDialog(CDlgSendMes::IDD, pParent)
{
//{{AFX_DATA_INIT(CDlgSendMes)
m_EditMes = _T("");
m_ports = _T("");
m_ip = _T("");
m_name = _T("");
m_password = _T("");
//}}AFX_DATA_INIT
}
void CDlgSendMes::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CDlgSendMes)
DDX_Control(pDX, IDC_EDIT_PORT, m_portctr);
DDX_Control(pDX, IDCANCEL, m_Cancel);
DDX_Control(pDX, IDC_DELETE, m_BDelete);
DDX_Control(pDX, IDC_BUTTON_OUT, m_BOut);
DDX_Control(pDX, IDC_BUTTON_IN, m_BIn);
DDX_Control(pDX, IDC_EDIT_MES, m_EditContrl);
DDX_Control(pDX, IDC_CHOOSE, m_Choose);
DDX_Text(pDX, IDC_EDIT_MES, m_EditMes);
DDX_Text(pDX, IDC_EDIT_PORT, m_ports);
DDV_MaxChars(pDX, m_ports, 8);
DDX_Text(pDX, IDC_EDIT_IP, m_ip);
DDV_MaxChars(pDX, m_ip, 50);
DDX_Text(pDX, IDC_EDIT_USERNAME, m_name);
DDV_MaxChars(pDX, m_name, 32);
DDX_Text(pDX, IDC_EDIT_PASSWORD, m_password);
DDV_MaxChars(pDX, m_password, 64);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CDlgSendMes, CDialog)
//{{AFX_MSG_MAP(CDlgSendMes)
ON_LBN_SELCHANGE(IDC_CHOOSE, OnSelchangeChoose)
ON_LBN_DBLCLK(IDC_CHOOSE, OnDblclkChoose)
ON_EN_CHANGE(IDC_EDIT_MES, OnChangeEditMes)
ON_BN_CLICKED(IDC_BUTTON_OUT, OnButtonOut)
ON_BN_CLICKED(IDC_BUTTON_IN, OnButtonIn)
ON_BN_CLICKED(IDC_DELETE, OnDelete)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CDlgSendMes message handlers
void CDlgSendMes::OnSelchangeChoose()
{
// TODO: Add your control notification handler code here
int index;
index=m_Choose.GetCurSel();
if(index==LB_ERR )
return;
if(m_Choose.GetText(index,s_ListContext)==LB_ERR)
return;
m_BOut.EnableWindow(TRUE);
m_BDelete.EnableWindow(TRUE);
}
void CDlgSendMes::OnDblclkChoose()
{
// TODO: Add your control notification handler code here
OnButtonOut();
}
void CDlgSendMes::OnChangeEditMes()
{
// TODO: If this is a RICHEDIT control, the control will not
// send this notification unless you override the CDialog::OnInitDialog()
// function and call CRichEditCtrl().SetEventMask()
// with the ENM_CHANGE flag ORed into the mask.
// TODO: Add your control notification handler code here
m_BIn.EnableWindow(TRUE);
}
void CDlgSendMes::OnButtonOut()
{
// TODO: Add your control notification handler code here
UpdateData(TRUE);
m_EditMes.Format("%s",s_ListContext);
UpdateData(FALSE);
}
void CDlgSendMes::OnButtonIn()
{
// TODO: Add your control notification handler code here
UpdateData(TRUE);
if(m_EditMes.GetLength()<1)
return;
m_Choose.AddString(m_EditMes);
UpdateData(FALSE);
try
{
f_MesFile.Open(pFileName,
CFile::modeNoTruncate|CFile::modeCreate|CFile::modeReadWrite|CFile::typeText );
f_MesFile.SeekToEnd( );
f_MesFile.WriteString(m_EditMes);
f_MesFile.WriteString("\n");
f_MesFile.Close();
}
catch(CFileException e )
{
AfxMessageBox( "File could not be opened ");
}
}
void CDlgSendMes::OnDelete()
{
// TODO: Add your control notification handler code here
int index,count;
index=m_Choose.GetCurSel();
if(index==LB_ERR )
return;
count=m_Choose.DeleteString(index);
if(count==LB_ERR)
return;
UpdateData(FALSE);
try
{
f_MesFile.Open(pFileName,
CFile::modeNoTruncate|CFile::modeCreate|CFile::modeReadWrite|CFile::typeText );
for(int i=count;i>0;i--)
{
if(m_Choose.GetText(i-1,s_ListContext)==LB_ERR)
return;
f_MesFile.WriteString(s_ListContext);
f_MesFile.WriteString("\n");
}
f_MesFile.Close();
}
catch(CFileException e )
{
AfxMessageBox( "File could not be opened ");
}
}
BOOL CDlgSendMes::OnInitDialog()
{
CDialog::OnInitDialog();
s_ListContext[0]='\0';
CString temp;
char buf[51]={'\0'};
char* subkey = "software\\GSL_XCSC";
char messagefile[50]="";
if(ReadReg(subkey,"serverip",(BYTE *)messagefile))
{
pFileName.Format("%s",messagefile);
}
else
{
pFileName.Format("%s",".\\messagefile.txt");
}
if(ReadReg(subkey,"serverip",(BYTE *)buf))
{
m_ip.Format("%s",buf);
}
else
m_ip.Format("%s","sms.pdainfo.com.cn");
if(ReadReg(subkey,"serverport",(BYTE *)buf))
{
if(strlen(buf)<9 && strlen(buf)>0 && !(strspn(buf,filter)<strlen(buf)) )
{
m_ports.Format("%s",buf);
}
else
m_ports.Format("%s","13013");
}
else
m_ports.Format("%s","13013");
UpdateData(FALSE);
try
{
f_MesFile.Open(pFileName,
CFile::modeNoTruncate|CFile::modeCreate|CFile::modeReadWrite|CFile::typeText );
while(f_MesFile.ReadString(temp)!=FALSE)
{
m_Choose.AddString(temp);
}
f_MesFile.Close();
}
catch(CFileException e )
{
AfxMessageBox( "File could not be opened ");
}
// TODO: Add extra initialization here
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
void CDlgSendMes::OnOK()
{
// TODO: Add extra validation here
char* subkey = "software\\GSL_XCSC";
char buf[50] = {'\0'};
UpdateData(TRUE);
strcpy(s_AllContext,m_EditMes);
if(strlen(s_AllContext)==0)
{
MessageBox("發(fā)送的內(nèi)容不能為空!\n請輸入發(fā)送內(nèi)容!","發(fā)送信息",MB_ICONWARNING);
return;
}
if( m_name.IsEmpty() || m_password.IsEmpty() )
{
MessageBox("用戶名、密碼為空!\n請輸入用戶名、密碼!","發(fā)送信息",MB_ICONWARNING);
return;
}
if(!m_ip.IsEmpty())
{
strcpy(buf,m_ip);
SaveReg(subkey,"serverip",(BYTE *)buf);
}
else
{
MessageBox("服務器IP為空!\n請輸入服務器IP!","發(fā)送信息",MB_ICONWARNING);
return;
}
if(!m_ports.IsEmpty())
{
if( strspn(m_ports,filter)<(size_t)m_ports.GetLength() )
{
MessageBox("錯誤的服務器端口!\n請輸入正確的服務器端口!","發(fā)送信息",MB_ICONWARNING);
return;
}
strcpy(buf,m_ports);
SaveReg(subkey,"serverport",(BYTE *)buf);
}
else
{
MessageBox("服務器端口為空!\n請輸入服務器端口!","發(fā)送信息",MB_ICONWARNING);
return;
}
strcpy(Name,m_name);
strcpy(PassWord,m_password);
strcpy(Ip,m_ip);
Port=atoi(m_ports);
CDialog::OnOK();
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -