📄 mainfrm.cpp
字号:
sprintf(buf,"%s 丢弃用户数据",dr.m_userid);
else
sprintf(buf,"%s",dr.m_userid);
this->m_wndStatusBar.SetPaneText(1,buf,TRUE);
}
}
}
void CMainFrame::AddTextToEditView(char * szContent,bool newline)
{
if (szContent)
{
CString text;
CEdit &ce=this->GetBottompane()->GetEditCtrl();
if (ce.GetLineCount()>100)
ce.SetWindowText("");
ce.GetWindowText(text);
if (newline)
ce.SetWindowText(text+"\r\n"+szContent);
else
ce.SetWindowText(text+szContent);
ce.LineScroll(ce.GetLineCount());
}
}
void CMainFrame::AddTextToEditView(int iContent,bool newline)
{
CString text;
char buf[32];
sprintf(buf,"%d",iContent);
CEdit &ce=this->GetBottompane()->GetEditCtrl();
if (ce.GetLineCount()>100)
ce.SetWindowText("");
ce.GetWindowText(text);
if (newline)
ce.SetWindowText(text+"\r\n"+buf);
else
ce.SetWindowText(text+buf);
ce.LineScroll(ce.GetLineCount());
}
void CMainFrame::RefreshUserTable(int flag)
{
int i,iMaxDTUAmount;
user_info ui;
bool bShow;
time_t t_now,t_update;
this->GetRightPane()->ClearAllItem();
this->GetLeftPane()->ClearAllItem();
iMaxDTUAmount=get_max_user_amount();
for (i=0;i<iMaxDTUAmount;i++)
{
ui.m_status=0;
get_user_at(i,&ui);
if (1==ui.m_status)
{
bShow=true;
//flag=1 means refresh usertable , 0 means not
if ((m_option.m_bSysAutoPoll) && (1==flag))
{
/* if type of update time is ulong then use */
/* the following code */
t_now=time(NULL);
t_update=*((time_t *)ui.m_update_time);
if ((t_now-t_update)>=m_option.m_iOffLineTime)
{
do_close_one_user((unsigned char *)ui.m_userid,NULL);
bShow=false;
}
/* if type of update time is char * then use */
/* following code */
/*
if (this->CompareDateTimeAndNow(ui.m_update_time)>=m_option.m_iOffLineTime)
{
do_close_one_user((unsigned char *)ui.m_userid,NULL);
bShow=false;
}
*/
}
if (bShow)
{
//add to ListView of right top
this->GetRightPane()->InsertUserItem(
ui.m_userid,ui.m_logon_date,
ui.m_update_time,ui.m_local_addr,
ui.m_local_port,ui.m_sin_addr,ui.m_sin_port);
//add to TreeView of left
this->GetLeftPane()->InsertUserItem(ui.m_userid);
}
}
}
this->GetLeftPane()->GetTreeCtrl().Expand(
this->GetLeftPane()->GetTreeCtrl().GetFirstVisibleItem(),TVE_EXPAND);
}
void CMainFrame::OnMianswer()
{
m_bAnswer=!m_bAnswer;
}
void CMainFrame::OnMiserversetting()
{
this->GetPara(0);
}
void CMainFrame::OnMishowdata()
{
this->GetPara(1);
}
void CMainFrame::OnShowmenu()
{
ShowControlBar(&m_wndMenuBar,!m_wndMenuBar.IsWindowVisible(),FALSE);
m_wndToolBar.SetButtonStyle(6,TBSTYLE_BUTTON);
}
void CMainFrame::OnHelpcontent()
{
MessageBox("深圳市宏电技术开发有限公司");
}
void CMainFrame::SetStatusBarStyle()
{
m_wndStatusBar.SetPaneInfo(0,ID_SEPARATOR,SBPS_STRETCH,100);
m_wndStatusBar.SetPaneText(1,"",TRUE);
//m_wndStatusBar.SetPaneText(2,"GPRS VC DEMO 3.0 宏电技术",TRUE);
m_wndStatusBar.SetPaneText(2,"DSC API演示程序 2.1 版(VC++6.0)",TRUE);
}
void CMainFrame::OnTimer(UINT nIDEvent)
{
// TODO: Add your message handler code here and/or call default
if (1==nIDEvent)
this->RefreshUserTable(1);
CFrameWnd::OnTimer(nIDEvent);
}
void CMainFrame::PrintData(char *szData, int datalen)
{
char buf[128];
int i,j,len,totallen;
totallen=datalen;//strlen(szData); 原来的错误
for (i=0;i<totallen;i+=16)
{
len=(totallen-i)>16?16:(totallen-i);
sprintf(buf,"%04X : ",i);
for (j=0;j<len;j++)
{
sprintf(buf+9+j*3,"%02X ",szData[i+j]&0xFF);
buf[64+j]=szData[i+j];
}
memset(buf+len*3+9,' ',64-len*3-9);
buf[64+len]='\0';
this->AddTextToEditView(buf);
}
}
void CMainFrame::OnUpdateMistartservice(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
pCmdUI->Enable(!m_bServerRunning);
}
void CMainFrame::OnUpdateMistopservice(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
pCmdUI->Enable(m_bServerRunning);
}
void CMainFrame::OnUpdateMianswer(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
pCmdUI->SetCheck(m_bAnswer);
}
void CMainFrame::init_option(LPOPTION pOption)
{
pOption->m_bSaveToLog=FALSE;
pOption->m_iLogItemCount=200;
pOption->m_bShowDataHead=TRUE;
pOption->m_iServerPort=30243;
pOption->m_bSysAutoPoll=TRUE;
pOption->m_iPollTimeInterval=30;
pOption->m_iOffLineTime=120;
pOption->m_bShowHead=TRUE;
pOption->m_bHexShow=TRUE;
}
void CMainFrame::GetPara(int tabindex)
{
CSettingDlg sdlg(NULL,tabindex,!m_bServerRunning);
sdlg.m_bSaveToLog=m_option.m_bSaveToLog;
sdlg.m_iLogItemCount.Format("%d",m_option.m_iLogItemCount);
sdlg.m_iOffLineTime.Format("%d",m_option.m_iOffLineTime);
sdlg.m_iPollTime.Format("%d",m_option.m_iPollTimeInterval);
sdlg.m_iServerPort.Format("%d",m_option.m_iServerPort);
sdlg.m_bSysAutoPoll=m_option.m_bSysAutoPoll;
sdlg.m_bShowHead=m_option.m_bShowHead;
sdlg.m_bHexShow=m_option.m_bHexShow;
if (IDOK==sdlg.DoModal())
{
m_option.m_bSaveToLog=sdlg.m_bSaveToLog;
m_option.m_iLogItemCount=atoi(sdlg.m_iLogItemCount.GetBuffer(0));
m_option.m_iOffLineTime=atoi(sdlg.m_iOffLineTime.GetBuffer(0));
m_option.m_iPollTimeInterval=atoi(sdlg.m_iPollTime.GetBuffer(0));
m_option.m_iServerPort=atoi(sdlg.m_iServerPort.GetBuffer(0));
m_option.m_bSysAutoPoll=sdlg.m_bSysAutoPoll;
m_option.m_bShowHead=sdlg.m_bShowHead;
m_option.m_bHexShow=sdlg.m_bHexShow;
}
}
void CMainFrame::SetUserId(char *szUserId)
{
strncpy(this->m_userid,szUserId,11);
this->m_userid[11]='\0';
}
void CMainFrame::OnUpdateShowmenu(CCmdUI* pCmdUI)
{
pCmdUI->SetCheck(m_wndMenuBar.IsWindowVisible());
}
void CMainFrame::OnMiofflineall()
{
do_close_all_user(NULL);
this->RefreshUserTable();
}
void CMainFrame::OnMiviewword()
{
// TODO: Add your command handler code here
if (!IsWindowVisible())
return;
CRect rect;
m_viewword=!m_viewword;
m_wndToolBar.SetShowWord(m_viewword);
m_wndToolBar.GetItemRect(0,&rect);
if (m_viewword)
{
m_wndToolBar.SetSizes(CSize(SHOWTEXTLEN,rect.Size().cy),CSize(32,32));
}
else
{
m_wndToolBar.SetSizes(CSize(NOTEXTLEN,rect.Size().cy),CSize(32,32));
}
ShowControlBar(&m_wndToolBar,TRUE,FALSE);
}
void CMainFrame::OnUpdateMiviewword(CCmdUI* pCmdUI)
{
pCmdUI->Enable(m_wndToolBar.IsWindowVisible());
pCmdUI->SetCheck(m_viewword);
}
BOOL CMainFrame::IsShowToolBarWord()
{
return m_viewword;
}
int CMainFrame::CompareDateTimeAndNow(char * szDateTime)
{
int nYear,nMonth,nDay,nHour,nMin,nSec;
char temp[20];
memset(temp,0,20);
strncpy(temp,szDateTime,4);
nYear = atoi(temp);
memset(temp,0,20);
strncpy(temp,&(szDateTime[5]),2);
nMonth = atoi(temp);
memset(temp,0,20);
strncpy(temp,&(szDateTime[8]),2);
nDay = atoi(temp);
memset(temp,0,20);
strncpy(temp,&(szDateTime[11]),2);
nHour = atoi(temp);
memset(temp,0,20);
strncpy(temp,&(szDateTime[14]),2);
nMin = atoi(temp);
memset(temp,0,20);
strncpy(temp,&(szDateTime[17]),4);
nSec = atoi(temp);
CTime updatetime(nYear,nMonth,nDay,nHour,nMin,nSec);
time_t stUpdatetime = updatetime.GetTime();
CTime currenttime = CTime::GetCurrentTime();
return (currenttime.GetTime()-stUpdatetime);
}
void CMainFrame::AddToSysMenu()
{
CMenu *pMenu;
pMenu=this->GetSystemMenu(FALSE);
ASSERT(pMenu);
pMenu->AppendMenu(MF_SEPARATOR);
//pMenu->AppendMenu(MF_STRING,NEWMENUITEM,"显示工具栏");
pMenu->AppendMenu(MF_STRING,ID_SHOWMENU,"显示/隐藏菜单栏(&U)");
pMenu->AppendMenu(MF_STRING,ID_VIEW_TOOLBAR,"显示/隐藏工具栏(&T)");
}
LRESULT CMainFrame::WindowProc(UINT message, WPARAM wParam, LPARAM lParam)
{
// TODO: Add your specialized code here and/or call the base class
if (WM_SYSCOMMAND==message)
{
if (ID_VIEW_TOOLBAR==wParam)
{
ShowControlBar(&m_wndToolBar,!m_wndToolBar.IsWindowVisible(),FALSE);
return 0;
}
else if (ID_SHOWMENU==wParam)
{
ShowControlBar(&m_wndMenuBar,!m_wndMenuBar.IsWindowVisible(),FALSE);
return 0;
}
}
return CFrameWnd::WindowProc(message, wParam, lParam);
}
void CMainFrame::OnUserinfoin()
{
int i;
int nMaxUser;
user_info UserInfo;
FILE *fp;
int nBytesRead;
fp = fopen("UserInfo.dat", "r");
if (NULL == fp)
{
return;
}
DeleteAllUser();
nMaxUser = get_max_user_amount();
for (i=0; i<nMaxUser; i++)
{
nBytesRead = fread((char *)&UserInfo, 1, sizeof(user_info), fp);
*((time_t *)UserInfo.m_update_time) = time(NULL);
if (nBytesRead < sizeof(user_info))
{
break;
}
AddOneUser(&UserInfo);
}
fclose(fp);
RefreshUserTable(0);
}
void CMainFrame::OnUserinfoout()
{
int i;
int nMaxUser;
user_info UserInfo;
FILE *fp;
fp = fopen("UserInfo.dat", "w");
if (NULL == fp)
{
return;
}
nMaxUser = get_max_user_amount();
for (i=0; i<nMaxUser; i++)
{
get_user_at(i, &UserInfo);
if (1 == UserInfo.m_status)
{
fwrite((char *)&UserInfo, 1, sizeof(user_info), fp);
}
}
fclose(fp);
}
void CMainFrame::OnMenusmsstart()
{
// TODO: Add your command handler code here
//需要配置波特率、数据位、停止位、校验码,其余不需配置;
/*Test SMM call
*Add by sea on sep 16,2003"*/
int iResult = 0;
DCB dcb;
dcb.BaudRate = 115200;
dcb.ByteSize = 8;
dcb.StopBits = 0;//ONESTOPBITS;
dcb.Parity = 0 ;
iResult = SMMInit("202.96.134.133",5001,
"COM5", &dcb,
"13800755500","13510006407",1);
if(iResult<0)
AddTextToEditView("smm error",false);
SMMSetting("10.0.0.1",5002);
SetModemType(1);
iResult = MakeDTUOnLine(1,"13902944285");
// AfxBeginThread(pfnReadData,this,THREAD_PRIORITY_NORMAL);
}
void CMainFrame::OnMenusmsexit()
{
// TODO: Add your command handler code here
// g_nCount = 200;
SMMFree();
}
void CMainFrame::OnAdduser()
{
// TODO: Add your command handler code here
if(!m_IsAdduserDlg)
{
m_IsAdduserDlg=TRUE;
CAddUserDlg * adduserdlg=new CAddUserDlg;
adduserdlg->Create (IDD_AddUser,this);
adduserdlg->ShowWindow (SW_SHOW);
}
return;
}
void CMainFrame::OnDeleteUser()
{
// TODO: Add your command handler code here
if (11==strlen(m_userid))
{
delete_one_user((unsigned char *)m_userid,NULL);
this->RefreshUserTable();
}
}
void CMainFrame::OnUpdateAdduser(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
pCmdUI->Enable(m_bServerRunning);
}
void CMainFrame::OnUpdateDeleteUser(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
pCmdUI->Enable(m_bServerRunning);
}
void CMainFrame::OnUpdateUserinfoin(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
pCmdUI->Enable(m_bServerRunning);
}
void CMainFrame::OnUpdateUserinfoout(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
pCmdUI->Enable(m_bServerRunning);
}
void CMainFrame::OnDisconnectPpp()
{
// TODO: Add your command handler code here
if (11==strlen(m_userid))
{
do_disconnect_ppp_link((unsigned char *)m_userid,NULL);
}
}
void CMainFrame::OnUpdateDisconnectPpp(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
pCmdUI->Enable(m_bServerRunning);
}
void CMainFrame::OnStopToSend()
{
// TODO: Add your command handler code here
if (11==strlen(m_userid))
{
do_stop_send_data((unsigned char *)m_userid,NULL);
}
}
void CMainFrame::OnUpdateStopToSend(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
pCmdUI->Enable(m_bServerRunning);
}
void CMainFrame::OnStartToSend()
{
// TODO: Add your command handler code here
if (11==strlen(m_userid))
{
do_start_send_data((unsigned char *)m_userid,NULL);
}
}
void CMainFrame::OnUpdateStartToSend(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
pCmdUI->Enable(m_bServerRunning);
}
void CMainFrame::OnDiscardData()
{
// TODO: Add your command handler code here
if (11==strlen(m_userid))
{
do_flush_cache_data((unsigned char *)m_userid,NULL);
}
}
void CMainFrame::OnUpdateDiscardData(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
pCmdUI->Enable(m_bServerRunning);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -