MainFrm.cpp
上传用户:zcy791212
上传日期:2013-03-06
资源大小:196k
文件大小:19k
源码类别:

Modem编程

开发平台:

Visual C++

  1. // MainFrm.cpp : implementation of the CMainFrame class
  2. //
  3. #include "stdafx.h"
  4. #include "vc_demo.h"
  5. #include "time.h"
  6. #include "SettingDlg.h"
  7. #include "senddatadlg.h"
  8. #include "WordThread.h"
  9. #include "MainFrm.h"
  10. #include "gprsdll.h"
  11. #include "vc_demoView.h"
  12. #include "gprsdll.h"
  13. #ifdef _DEBUG
  14. #define new DEBUG_NEW
  15. #undef THIS_FILE
  16. static char THIS_FILE[] = __FILE__;
  17. #endif
  18. /////////////////////////////////////////////////////////////////////////////
  19. // CMainFrame
  20. IMPLEMENT_DYNCREATE(CMainFrame, CFrameWnd)
  21. BEGIN_MESSAGE_MAP(CMainFrame, CFrameWnd)
  22. //{{AFX_MSG_MAP(CMainFrame)
  23. ON_WM_CREATE()
  24. ON_COMMAND(ID_MICLEAR, OnMiclear)
  25. ON_COMMAND(ID_MIOFFLINE, OnMioffline)
  26. ON_COMMAND(ID_MIREFRESHTABLE, OnMirefreshtable)
  27. ON_COMMAND(ID_MISENDDATA, OnMisenddata)
  28. ON_COMMAND(ID_MISTARTSERVICE, OnMistartservice)
  29. ON_COMMAND(ID_MISTOPSERVICE, OnMistopservice)
  30. ON_COMMAND(ID_QUIT, OnQuit)
  31. ON_WM_CLOSE()
  32. ON_COMMAND(ID_MIANSWER, OnMianswer)
  33. ON_COMMAND(ID_MISHOWDATA, OnMishowdata)
  34. ON_COMMAND(ID_SHOWMENU, OnShowmenu)
  35. ON_COMMAND(ID_HELPCONTENT, OnHelpcontent)
  36. ON_WM_TIMER()
  37. ON_UPDATE_COMMAND_UI(ID_MISTARTSERVICE, OnUpdateMistartservice)
  38. ON_UPDATE_COMMAND_UI(ID_MIOFFLINE, OnUpdateMistopservice)
  39. ON_UPDATE_COMMAND_UI(ID_MIANSWER, OnUpdateMianswer)
  40. ON_COMMAND(ID_MISERVERSETTING, OnMiserversetting)
  41. ON_UPDATE_COMMAND_UI(ID_SHOWMENU, OnUpdateShowmenu)
  42. ON_COMMAND(ID_MIOFFLINEALL, OnMiofflineall)
  43. ON_COMMAND(ID_MIVIEWWORD, OnMiviewword)
  44. ON_UPDATE_COMMAND_UI(ID_MIVIEWWORD, OnUpdateMiviewword)
  45. ON_UPDATE_COMMAND_UI(ID_MIREFRESHTABLE, OnUpdateMistopservice)
  46. ON_UPDATE_COMMAND_UI(ID_MISENDDATA, OnUpdateMistopservice)
  47. ON_UPDATE_COMMAND_UI(ID_MISTOPSERVICE, OnUpdateMistopservice)
  48. ON_UPDATE_COMMAND_UI(ID_MIOFFLINEALL, OnUpdateMistopservice)
  49. //}}AFX_MSG_MAP
  50. ON_UPDATE_COMMAND_UI_RANGE(AFX_ID_VIEW_MINIMUM, AFX_ID_VIEW_MAXIMUM, OnUpdateViewStyles)
  51. ON_COMMAND_RANGE(AFX_ID_VIEW_MINIMUM, AFX_ID_VIEW_MAXIMUM, OnViewStyle)
  52. ON_MESSAGE(ID_MISENDDATA,OnMisenddata)
  53. END_MESSAGE_MAP()
  54. static UINT indicators[] =
  55. {
  56. ID_SEPARATOR, 
  57. ID_SEPARATOR, 
  58.     ID_SEPARATOR 
  59. // status line indicator
  60. //ID_INDICATOR_CAPS,
  61. //ID_INDICATOR_NUM,
  62. //ID_INDICATOR_SCRL,
  63. //0x1234
  64. };
  65. /////////////////////////////////////////////////////////////////////////////
  66. // CMainFrame construction/destruction
  67. CMainFrame::CMainFrame()
  68. {
  69. // TODO: add member initialization code here
  70. m_bAutoMenuEnable=false;
  71. this->m_bServerRunning=false;
  72.     this->m_bAnswer=FALSE;
  73. this->m_viewword=TRUE;
  74. memset(this->m_userid,0x00,12);
  75. init_option(&m_option);
  76. }
  77. CMainFrame::~CMainFrame()
  78. {
  79. }
  80. int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
  81. {
  82. if (CFrameWnd::OnCreate(lpCreateStruct) == -1)
  83. return -1;
  84. if (!m_wndMenuBar.Create(this) ||
  85. !m_wndMenuBar.LoadMenuBar(IDR_MAINFRAME))
  86. {
  87. TRACE0("Failed to create toolbarn");
  88. return -1;      // faile to create
  89. }
  90. if (!m_wndToolBar.CreateEx(this, 
  91. TBSTYLE_FLAT | TBSTYLE_TRANSPARENT | TBSTYLE_LIST,
  92. WS_CHILD | WS_VISIBLE | CBRS_TOP
  93. | CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY 
  94. | CBRS_SIZE_DYNAMIC
  95. )
  96. || !m_wndToolBar.LoadToolBar(IDR_MAINFRAME))
  97. {
  98. TRACE0("Failed to create toolbarn");
  99. return -1;      // fail to create
  100. }
  101. if (!m_wndStatusBar.Create(this) ||
  102. !m_wndStatusBar.SetIndicators(indicators,
  103.   sizeof(indicators)/sizeof(UINT)))
  104. {
  105. TRACE0("Failed to create status barn");
  106. return -1;      // fail to create
  107. }
  108. // TODO: Delete these three lines if you don't want the toolbar to
  109. //  be dockable
  110. m_wndToolBar.EnableDocking(CBRS_ALIGN_ANY);
  111. m_wndMenuBar.EnableDocking(CBRS_ALIGN_ANY);
  112. EnableDocking(CBRS_ALIGN_ANY);
  113. DockControlBar(&m_wndMenuBar);
  114. DockControlBar(&m_wndToolBar);
  115. this->SetToolBarStyle();
  116. this->SetStatusBarStyle();
  117. return 0;
  118. }
  119. BOOL CMainFrame::OnCreateClient(LPCREATESTRUCT /*lpcs*/,
  120. CCreateContext* pContext)
  121. {
  122. // create splitter window
  123. if (!m_wndSplitter.CreateStatic(this, 1, 2))
  124. return FALSE;
  125. if (!m_wndSplitter.CreateView(0, 0, RUNTIME_CLASS(CLeftView), CSize(130, 100), pContext))
  126. {
  127. m_wndSplitter.DestroyWindow();
  128. return FALSE;
  129. }
  130. if (!m_wndSplitter2.CreateStatic(&m_wndSplitter,2,1,WS_VISIBLE | WS_CHILD | WS_BORDER,m_wndSplitter.IdFromRowCol(0,1)))
  131. return FALSE;
  132. if (!m_wndSplitter2.CreateView(0, 0, RUNTIME_CLASS(CVc_demoView), CSize(100, 200), pContext) ||
  133. !m_wndSplitter2.CreateView(1, 0, RUNTIME_CLASS(CBottomEditView), CSize(100, 100), pContext))
  134. {
  135. m_wndSplitter2.DestroyWindow();
  136. return FALSE;
  137. }
  138. return TRUE;
  139. }
  140. BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
  141. {
  142. if( !CFrameWnd::PreCreateWindow(cs) )
  143. return FALSE;
  144. // TODO: Modify the Window class or styles here by modifying
  145. //  the CREATESTRUCT cs
  146. return TRUE;
  147. }
  148. /////////////////////////////////////////////////////////////////////////////
  149. // CMainFrame diagnostics
  150. #ifdef _DEBUG
  151. void CMainFrame::AssertValid() const
  152. {
  153. CFrameWnd::AssertValid();
  154. }
  155. void CMainFrame::Dump(CDumpContext& dc) const
  156. {
  157. CFrameWnd::Dump(dc);
  158. }
  159. #endif //_DEBUG
  160. /////////////////////////////////////////////////////////////////////////////
  161. // CMainFrame message handlers
  162. CVc_demoView* CMainFrame::GetRightPane()
  163. {
  164. CWnd* pWnd = m_wndSplitter2.GetPane(0, 0);
  165. CVc_demoView* pView = DYNAMIC_DOWNCAST(CVc_demoView, pWnd);
  166. return pView;
  167. }
  168. CLeftView* CMainFrame::GetLeftPane()
  169. {
  170. CWnd* pWnd = m_wndSplitter.GetPane(0, 0);
  171. CLeftView* pView = DYNAMIC_DOWNCAST(CLeftView, pWnd);
  172. return pView;
  173. }
  174. CBottomEditView* CMainFrame::GetBottompane()
  175. {
  176. CWnd* pWnd = m_wndSplitter2.GetPane(1, 0);
  177. CBottomEditView* pView = DYNAMIC_DOWNCAST(CBottomEditView, pWnd);
  178. return pView;
  179. }
  180. void CMainFrame::OnUpdateViewStyles(CCmdUI* pCmdUI)
  181. {
  182. // TODO: customize or extend this code to handle choices on the
  183. // View menu.
  184. CVc_demoView* pView = GetRightPane(); 
  185. // if the right-hand pane hasn't been created or isn't a view,
  186. // disable commands in our range
  187. if (pView == NULL)
  188. pCmdUI->Enable(FALSE);
  189. else
  190. {
  191. DWORD dwStyle = pView->GetStyle() & LVS_TYPEMASK;
  192. // if the command is ID_VIEW_LINEUP, only enable command
  193. // when we're in LVS_ICON or LVS_SMALLICON mode
  194. if (pCmdUI->m_nID == ID_VIEW_LINEUP)
  195. {
  196. if (dwStyle == LVS_ICON || dwStyle == LVS_SMALLICON)
  197. pCmdUI->Enable();
  198. else
  199. pCmdUI->Enable(FALSE);
  200. }
  201. else
  202. {
  203. // otherwise, use dots to reflect the style of the view
  204. pCmdUI->Enable();
  205. BOOL bChecked = FALSE;
  206. switch (pCmdUI->m_nID)
  207. {
  208. case ID_VIEW_DETAILS:
  209. bChecked = (dwStyle == LVS_REPORT);
  210. break;
  211. case ID_VIEW_SMALLICON:
  212. bChecked = (dwStyle == LVS_SMALLICON);
  213. break;
  214. case ID_VIEW_LARGEICON:
  215. bChecked = (dwStyle == LVS_ICON);
  216. break;
  217. case ID_VIEW_LIST:
  218. bChecked = (dwStyle == LVS_LIST);
  219. break;
  220. default:
  221. bChecked = FALSE;
  222. break;
  223. }
  224. pCmdUI->SetRadio(bChecked ? 1 : 0);
  225. }
  226. }
  227. }
  228. void CMainFrame::OnViewStyle(UINT nCommandID)
  229. {
  230. // TODO: customize or extend this code to handle choices on the
  231. // View menu.
  232. CVc_demoView* pView = GetRightPane();
  233. // if the right-hand pane has been created and is a CVc_demoView,
  234. // process the menu commands...
  235. if (pView != NULL)
  236. {
  237. DWORD dwStyle = -1;
  238. switch (nCommandID)
  239. {
  240. case ID_VIEW_LINEUP:
  241. {
  242. // ask the list control to snap to grid
  243. CListCtrl& refListCtrl = pView->GetListCtrl();
  244. refListCtrl.Arrange(LVA_SNAPTOGRID);
  245. }
  246. break;
  247. // other commands change the style on the list control
  248. case ID_VIEW_DETAILS:
  249. dwStyle = LVS_REPORT;
  250. break;
  251. case ID_VIEW_SMALLICON:
  252. dwStyle = LVS_SMALLICON;
  253. break;
  254. case ID_VIEW_LARGEICON:
  255. dwStyle = LVS_ICON;
  256. break;
  257. case ID_VIEW_LIST:
  258. dwStyle = LVS_LIST;
  259. break;
  260. }
  261. // change the style; window will repaint automatically
  262. if (dwStyle != -1)
  263. pView->ModifyStyle(LVS_TYPEMASK, dwStyle);
  264. }
  265. }
  266. void CMainFrame::SetToolBarStyle()
  267. {
  268. CImageList img;
  269. m_wndToolBar.GetToolBarCtrl().SetButtonWidth(40, 100);
  270. m_wndToolBar.GetToolBarCtrl().SetExtendedStyle(TBSTYLE_EX_DRAWDDARROWS);
  271.     //m_wndToolBar.SetButtonStyle(8,TBSTYLE_CHECK);
  272. //m_wndToolBar.SetButtonStyle(4,m_wndToolBar.GetButtonStyle(4) 
  273. //                            | TBSTYLE_DROPDOWN);
  274. img.Create(IDB_HOTTOOLBAR, 32, 0, RGB(244, 247, 14));
  275. m_wndToolBar.GetToolBarCtrl().SetHotImageList(&img);
  276. img.Detach();
  277. img.Create(IDB_COLDTOOLBAR, 32, 0, RGB(244, 247, 14));
  278. m_wndToolBar.GetToolBarCtrl().SetImageList(&img);
  279. img.Detach();
  280. for(int i = 0; i < m_wndToolBar.GetCount(); i++) 
  281. UINT id = m_wndToolBar.GetItemID(i); 
  282. CString s;
  283.     if (!s.LoadString(id)) 
  284. continue;
  285.     int j = s.Find(_T('n')); 
  286.     if(j < 0) continue;
  287.     s = s.Right(s.GetLength() - j - 1); 
  288.     m_wndToolBar.SetButtonText(i,s); 
  289. }
  290. CRect rect; 
  291. m_wndToolBar.GetItemRect(0,&rect); 
  292. m_wndToolBar.SetSizes(rect.Size(),CSize(32,32));
  293. }
  294. void CMainFrame::OnMiclear() 
  295. {
  296. // TODO: Add your command handler code here
  297. CEdit &ce=this->GetBottompane()->GetEditCtrl();
  298. ce.SetWindowText("");
  299. }
  300. void CMainFrame::OnMioffline() 
  301. {
  302. /*
  303. char buf[64];
  304. if (11==strlen(m_userid))
  305. {
  306. sprintf(buf,"确认使  %s 下线吗?",this->m_userid);
  307.     if (IDYES==MessageBox(buf,"确认",MB_YESNO | MB_ICONINFORMATION))
  308. {
  309. do_close_one_user((unsigned char *)m_userid,NULL);
  310. this->RefreshUserTable();
  311. }
  312. }
  313. */
  314. }
  315. void CMainFrame::OnMirefreshtable() 
  316. {
  317. this->RefreshUserTable();
  318. }
  319. void CMainFrame::OnMisenddata() 
  320. {
  321. CTreeCtrl &tc=this->GetLeftPane()->GetTreeCtrl();
  322. CSendDataDlg sdd(NULL,&tc);
  323. sdd.SetUserId(this->m_userid);
  324. sdd.DoModal();
  325. }
  326. void CMainFrame::OnMistartservice() 
  327. {
  328. char mess[512];
  329. BOOL bResult;
  330. bResult=DSStartService(m_option.m_iServerPort);
  331. if (bResult)
  332. {    
  333. sprintf(mess,"厦门桑荣科技数据服务中心启动,侦听端口为%drn",m_option.m_iServerPort);
  334. if ((m_option.m_bSysAutoPoll) && (m_option.m_iPollTimeInterval>0) && (m_option.m_iOffLineTime>0))
  335.             this->SetTimer(1,(m_option.m_iPollTimeInterval)*1000,NULL);
  336. this->AddTextToEditView(mess,false);
  337. if (!StartRecv())
  338. {
  339. DSStopService();
  340. sprintf(mess,"启动接收线程失败,关闭数据中心服务rn");
  341. this->AddTextToEditView(mess,false);
  342. }
  343. else
  344. {
  345. sprintf(mess,"启动接收线程成功,系统就绪。rn");
  346. AddTextToEditView(mess,false);
  347.     this->m_bServerRunning=true;
  348. }
  349. }
  350. else
  351. {
  352. sprintf(mess,"数据中心服务启动失败!rn");
  353. this->AddTextToEditView(mess,false);
  354. }
  355. }
  356. void CMainFrame::OnMistopservice() 
  357. {
  358. // TODO: Add your command handler code here
  359. char mess[512];
  360. if (m_option.m_bSysAutoPoll)
  361. this->KillTimer(1);
  362. //this->AddTextToEditView(mess);
  363. if(!DSStopService())
  364. {
  365. DSGetLastError(mess,sizeof(mess));
  366. }
  367. else
  368. {
  369. sprintf(mess,"停止数据中心服务成功!rn");
  370. }
  371. this->AddTextToEditView(mess,false);
  372. StopRecvThread();
  373. this->m_bServerRunning=false;
  374. this->GetRightPane()->ClearAllItem();
  375. this->GetLeftPane()->ClearAllItem();
  376. }
  377. void CMainFrame::OnQuit() 
  378. {
  379. // TODO: Add your command handler code here
  380. this->OnClose();
  381. }
  382. void CMainFrame::OnClose() 
  383. {
  384. // TODO: Add your message handler code here and/or call default
  385. if (IDYES==MessageBox("确定要退出吗?","退出",MB_YESNO | MB_ICONINFORMATION))
  386. {
  387. if (m_bServerRunning)
  388. {
  389. this->OnMistopservice();
  390. }
  391. CFrameWnd::OnClose();
  392. }
  393. }
  394. UINT CMainFrame::ProcessRvData(LPVOID lparam)
  395. {
  396. CMainFrame* pMainFrm=(CMainFrame*)lparam;
  397. ModemDataStruct modemdata;
  398. static char buf[2048];
  399. while(1)
  400. {
  401. if (DSGetNextData(&modemdata,0)!=FALSE)
  402. {
  403. if (modemdata.m_data_len>0)
  404. {
  405. //whether show head
  406. if (pMainFrm->m_option.m_bShowHead)
  407. {
  408. struct tm when;
  409. when = *localtime((time_t*)&modemdata.m_recv_time);
  410. // sprintf(buf,"rnuserid:%s,time:%s,len:%d",
  411. // modemdata.m_modemId,asctime(&when),modemdata.m_data_len);
  412. sprintf(buf,"rnuserid:%8.8x,time:%s,len:%d",
  413. modemdata.m_modemId,asctime(&when),modemdata.m_data_len);
  414. pMainFrm->AddTextToEditView(buf);
  415. }
  416. //Hex or not to show data
  417. modemdata.m_data_buf[modemdata.m_data_len]=0;
  418. if (pMainFrm->m_option.m_bHexShow)
  419. {
  420. pMainFrm->PrintData((char*)modemdata.m_data_buf);
  421. }
  422. else
  423. {
  424. pMainFrm->AddTextToEditView((char*)modemdata.m_data_buf);
  425. }
  426. }
  427. }
  428. else
  429. {
  430. break;
  431. }
  432. } //endof while(1)
  433. return 1;
  434. }
  435. void CMainFrame::AddTextToEditView(char * szContent,bool newline)
  436. {
  437. if (szContent)
  438. {
  439.     CString text;
  440.     CEdit &ce=GetBottompane()->GetEditCtrl();
  441.     if (ce.GetLineCount()>100)
  442.     ce.SetWindowText("");
  443. ce.GetWindowText(text);
  444. if (newline)
  445. ce.SetWindowText(text+"rn"+szContent);
  446. else
  447. ce.SetWindowText(text+szContent);
  448. ce.LineScroll(ce.GetLineCount());
  449. }
  450. }
  451. void CMainFrame::AddTextToEditView(int iContent,bool newline)
  452. {
  453. CString text;
  454. char buf[32];
  455. sprintf(buf,"%d",iContent);
  456.     CEdit &ce=this->GetBottompane()->GetEditCtrl();
  457. if (ce.GetLineCount()>100)
  458. ce.SetWindowText("");
  459. ce.GetWindowText(text);
  460. if (newline)
  461. ce.SetWindowText(text+"rn"+buf);
  462. else
  463. ce.SetWindowText(text+buf);
  464. ce.LineScroll(ce.GetLineCount());
  465. }
  466. void CMainFrame::RefreshUserTable(int flag)
  467. //flag=1 means refresh usertable , 0 means not
  468. //flag==1:called by timer
  469. //flag==0:called by manual
  470. {
  471. int i,iMaxDTUAmount;
  472. ModemInfoStruct mi;
  473. bool   bShow;
  474. time_t t_now,t_update;
  475. this->GetRightPane()->ClearAllItem();
  476. this->GetLeftPane()->ClearAllItem();
  477. iMaxDTUAmount=DSGetModemCount();
  478. TRACE("TIMER:MAX MODEM COUNT = %d.n",iMaxDTUAmount);
  479. for (i=0;i<iMaxDTUAmount;i++)
  480. {
  481. DSGetModemByPosition(i,&mi);
  482. bShow=true;
  483. if ((m_option.m_bSysAutoPoll) && (1==flag))
  484. {
  485. /* if type of update time is ulong then use */
  486. /* the following code                       */
  487. t_now=time(NULL);
  488. t_update=mi.m_refresh_time;
  489. if ((t_now-t_update)>=m_option.m_iOffLineTime)
  490. {
  491. bShow=false;
  492. }                
  493. }
  494. if (bShow)
  495. {
  496. //add to ListView of right top
  497. this->GetRightPane()->InsertUserItem(
  498. &mi);
  499. //add to TreeView of left
  500. CString str;
  501. str.Format("%8.8x",mi.m_modemId);
  502. GetLeftPane()->InsertUserItem(str.GetBuffer(1));
  503. }
  504. }
  505. this->GetLeftPane()->GetTreeCtrl().Expand(
  506. this->GetLeftPane()->GetTreeCtrl().GetFirstVisibleItem(),TVE_EXPAND);
  507. }
  508. void CMainFrame::OnMianswer() 
  509. {
  510.     m_bAnswer=!m_bAnswer;
  511. }
  512. void CMainFrame::OnMiserversetting() 
  513. {
  514. this->GetPara(0);
  515. }
  516. void CMainFrame::OnMishowdata() 
  517. {
  518. this->GetPara(1);
  519. }
  520. void CMainFrame::OnShowmenu() 
  521. {
  522.     ShowControlBar(&m_wndMenuBar,!m_wndMenuBar.IsWindowVisible(),FALSE);
  523. m_wndToolBar.SetButtonStyle(5,TBSTYLE_BUTTON);
  524. }
  525. void CMainFrame::OnHelpcontent() 
  526. {
  527. MessageBox("厦门桑荣科技技术部");
  528. }
  529. void CMainFrame::SetStatusBarStyle()
  530. {
  531. m_wndStatusBar.SetPaneInfo(0,ID_SEPARATOR,SBPS_STRETCH,100);  
  532. m_wndStatusBar.SetPaneText(1,"",TRUE);
  533. m_wndStatusBar.SetPaneText(2,"数据中心软件DEMO软件",TRUE);
  534. }
  535. void CMainFrame::OnTimer(UINT nIDEvent) 
  536. {
  537. // TODO: Add your message handler code here and/or call default
  538. if (1==nIDEvent)
  539. this->RefreshUserTable(1);
  540. if (3==nIDEvent)
  541. ProcessRvData(this);
  542. CFrameWnd::OnTimer(nIDEvent);
  543. }
  544. void CMainFrame::PrintData(char *szData)
  545. {
  546. char buf[128];
  547. int i,j,len,totallen;
  548. totallen=strlen(szData);
  549. for (i=0;i<totallen;i+=16)
  550. {
  551. len=(totallen-i)>16?16:(totallen-i);
  552. sprintf(buf,"%04X  :  ",i);
  553. for (j=0;j<len;j++)
  554. {
  555. sprintf(buf+9+j*3,"%02X ",szData[i+j]&0xFF);
  556. buf[64+j]=szData[i+j];
  557. }
  558.         memset(buf+len*3+9,' ',64-len*3-9);
  559. buf[64+len]='';
  560. this->AddTextToEditView(buf);
  561. }
  562. }
  563. void CMainFrame::OnUpdateMistartservice(CCmdUI* pCmdUI) 
  564. {
  565. // TODO: Add your command update UI handler code here
  566. pCmdUI->Enable(!m_bServerRunning);
  567. }
  568. void CMainFrame::OnUpdateMistopservice(CCmdUI* pCmdUI) 
  569. {
  570. // TODO: Add your command update UI handler code here
  571. pCmdUI->Enable(m_bServerRunning);
  572. }
  573. void CMainFrame::OnUpdateMianswer(CCmdUI* pCmdUI) 
  574. {
  575. // TODO: Add your command update UI handler code here
  576. pCmdUI->SetCheck(m_bAnswer);
  577. }
  578. void CMainFrame::init_option(LPOPTION pOption)
  579. {
  580. pOption->m_bSaveToLog=FALSE;
  581. pOption->m_iLogItemCount=200;
  582. pOption->m_bShowDataHead=TRUE;
  583. pOption->m_iServerPort=5001;
  584. pOption->m_bSysAutoPoll=TRUE;
  585. pOption->m_iPollTimeInterval=5;
  586. pOption->m_iOffLineTime=120;
  587. pOption->m_bShowHead=TRUE;
  588. pOption->m_bHexShow=TRUE;
  589. }
  590. void CMainFrame::GetPara(int tabindex)
  591. {
  592. CSettingDlg sdlg(NULL,tabindex,!m_bServerRunning);
  593. sdlg.m_bSaveToLog=m_option.m_bSaveToLog;
  594. sdlg.m_iLogItemCount.Format("%d",m_option.m_iLogItemCount);
  595. sdlg.m_iOffLineTime.Format("%d",m_option.m_iOffLineTime);
  596. sdlg.m_iPollTime.Format("%d",m_option.m_iPollTimeInterval);
  597. sdlg.m_iServerPort.Format("%d",m_option.m_iServerPort);
  598. sdlg.m_bSysAutoPoll=m_option.m_bSysAutoPoll;
  599. sdlg.m_bShowHead=m_option.m_bShowHead;
  600. sdlg.m_bHexShow=m_option.m_bHexShow;
  601. if (IDOK==sdlg.DoModal())
  602. {
  603. m_option.m_bSaveToLog=sdlg.m_bSaveToLog;
  604. m_option.m_iLogItemCount=atoi(sdlg.m_iLogItemCount.GetBuffer(0));
  605. m_option.m_iOffLineTime=atoi(sdlg.m_iOffLineTime.GetBuffer(0));
  606. m_option.m_iPollTimeInterval=atoi(sdlg.m_iPollTime.GetBuffer(0));
  607. m_option.m_iServerPort=atoi(sdlg.m_iServerPort.GetBuffer(0));
  608. m_option.m_bSysAutoPoll=sdlg.m_bSysAutoPoll;
  609.     m_option.m_bShowHead=sdlg.m_bShowHead;
  610.     m_option.m_bHexShow=sdlg.m_bHexShow;
  611. }
  612. }
  613. void CMainFrame::SetUserId(char *szUserId)
  614. {
  615. strncpy(this->m_userid,szUserId,11);
  616. this->m_userid[11]='';
  617. }
  618. void CMainFrame::OnUpdateShowmenu(CCmdUI* pCmdUI) 
  619. {
  620.     pCmdUI->SetCheck(m_wndMenuBar.IsWindowVisible());
  621. }
  622. void CMainFrame::OnMiofflineall() 
  623. {
  624. /*
  625.     do_close_all_user(NULL);
  626. this->RefreshUserTable();
  627. */
  628. }
  629. void CMainFrame::OnMiviewword() 
  630. {
  631. // TODO: Add your command handler code here
  632.     if (!IsWindowVisible()) 
  633. return;
  634. CRect rect; 
  635. m_viewword=!m_viewword;
  636.     m_wndToolBar.SetShowWord(m_viewword);
  637.     m_wndToolBar.GetItemRect(0,&rect); 
  638. if (m_viewword)
  639. {
  640.     m_wndToolBar.SetSizes(CSize(SHOWTEXTLEN,rect.Size().cy),CSize(32,32));
  641. }
  642. else
  643. {
  644.         m_wndToolBar.SetSizes(CSize(NOTEXTLEN,rect.Size().cy),CSize(32,32));
  645. }
  646. ShowControlBar(&m_wndToolBar,TRUE,FALSE);
  647. }
  648. void CMainFrame::OnUpdateMiviewword(CCmdUI* pCmdUI) 
  649. {
  650. pCmdUI->Enable(m_wndToolBar.IsWindowVisible());
  651.     pCmdUI->SetCheck(m_viewword);
  652. }
  653. BOOL CMainFrame::IsShowToolBarWord()
  654. {
  655. return m_viewword;
  656. }
  657. int CMainFrame::CompareDateTimeAndNow(char * szDateTime)
  658. {
  659.     int nYear,nMonth,nDay,nHour,nMin,nSec;
  660. char temp[20];
  661.     memset(temp,0,20);
  662. strncpy(temp,szDateTime,4);
  663. nYear = atoi(temp);
  664. memset(temp,0,20);
  665. strncpy(temp,&(szDateTime[5]),2);
  666. nMonth = atoi(temp);
  667. memset(temp,0,20);
  668. strncpy(temp,&(szDateTime[8]),2);
  669. nDay = atoi(temp);
  670. memset(temp,0,20);
  671. strncpy(temp,&(szDateTime[11]),2);
  672. nHour = atoi(temp);
  673. memset(temp,0,20);
  674. strncpy(temp,&(szDateTime[14]),2);
  675. nMin = atoi(temp);
  676. memset(temp,0,20);
  677. strncpy(temp,&(szDateTime[17]),4);
  678. nSec = atoi(temp);
  679. CTime updatetime(nYear,nMonth,nDay,nHour,nMin,nSec);
  680. time_t stUpdatetime = updatetime.GetTime();
  681. CTime currenttime = CTime::GetCurrentTime();
  682.     return (currenttime.GetTime()-stUpdatetime);
  683. }
  684. BOOL CMainFrame::StartRecv(void)
  685. {
  686. SetTimer(3,100,NULL); //500ms every time.
  687. return TRUE;
  688. }
  689. void CMainFrame::StopRecvThread()
  690. {
  691. KillTimer(3);
  692. }