SettingDlg.cpp
上传用户:lmzg333
上传日期:2013-04-15
资源大小:376k
文件大小:7k
源码类别:

通讯/手机编程

开发平台:

Visual C++

  1. // SettingDlg.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "vc_demo.h"
  5. #include "SettingDlg.h"
  6. #include "winsock2.h"
  7. #include "wcomm_dll.h"
  8. #ifdef _DEBUG
  9. #define new DEBUG_NEW
  10. #undef THIS_FILE
  11. static char THIS_FILE[] = __FILE__;
  12. #endif
  13. /////////////////////////////////////////////////////////////////////////////
  14. // CSettingDlg dialog
  15. CSettingDlg::CSettingDlg(CWnd* pParent /*=NULL*/,int tabindex,BOOL Enabled)
  16. : CDialog(CSettingDlg::IDD, pParent)
  17. {
  18. //{{AFX_DATA_INIT(CSettingDlg)
  19. m_bSaveToLog = FALSE;
  20. m_iLogItemCount = _T("");
  21. m_iOffLineTime = _T("");
  22. m_iPollTime = _T("");
  23. m_iServerPort = _T("");
  24. m_bSysAutoPoll = FALSE;
  25. m_bShowHead = FALSE;
  26. m_bHexShow = FALSE;
  27. m_szlist = _T("");
  28. //}}AFX_DATA_INIT
  29. m_tabindex=tabindex;
  30. m_BEnabled=Enabled;
  31. }
  32. void CSettingDlg::DoDataExchange(CDataExchange* pDX)
  33. {
  34. CDialog::DoDataExchange(pDX);
  35. //{{AFX_DATA_MAP(CSettingDlg)
  36. DDX_Control(pDX, IDC_LIST1, m_list);
  37. DDX_Control(pDX, IDC_COMBO1, m_comb);
  38. DDX_Check(pDX, IDC_CKSAVETOLOG, m_bSaveToLog);
  39. DDX_CBString(pDX, IDC_CMLOGITEMCOUNT, m_iLogItemCount);
  40. DDX_CBString(pDX, IDC_CMOFFLINETIME, m_iOffLineTime);
  41. DDX_CBString(pDX, IDC_CMPOLLTIME, m_iPollTime);
  42. DDX_CBString(pDX, IDC_CMSERVERPORT, m_iServerPort);
  43. DDX_Check(pDX, IDC_CKSYSAUTOPOLL, m_bSysAutoPoll);
  44. DDX_Check(pDX, IDC_CKSHOWHEAD, m_bShowHead);
  45. DDX_Check(pDX, IDC_CKHEXSHOW, m_bHexShow);
  46. DDX_Control(pDX, IDC_TAB1, m_tab);
  47. DDX_LBString(pDX, IDC_LIST1, m_szlist);
  48. //}}AFX_DATA_MAP
  49. }
  50. BEGIN_MESSAGE_MAP(CSettingDlg, CDialog)
  51. //{{AFX_MSG_MAP(CSettingDlg)
  52. ON_WM_SHOWWINDOW()
  53. ON_NOTIFY(TCN_SELCHANGE, IDC_TAB1, OnSelchangeTab1)
  54. ON_BN_CLICKED(IDC_CKSAVETOLOG, OnCksavetolog)
  55. ON_CBN_SELCHANGE(IDC_COMBO1, OnSelchangeCombo1)
  56. ON_BN_CLICKED(IDC_DELETEIP, OnDeleteip)
  57. ON_LBN_DBLCLK(IDC_LIST1, OnDblclkList1)
  58. //}}AFX_MSG_MAP
  59. END_MESSAGE_MAP()
  60. /////////////////////////////////////////////////////////////////////////////
  61. // CSettingDlg message handlers
  62. void CSettingDlg::OnShowWindow(BOOL bShow, UINT nStatus) 
  63. {
  64. CDialog::OnShowWindow(bShow, nStatus);
  65. CImageList img;
  66. int  iIndex;
  67. img.Create(IDB_SETTING,16,0,RGB(255,0,255));
  68.     this->m_tab.SetImageList(&img);
  69. img.Detach();
  70. this->m_tab.InsertItem(TCIF_TEXT | TCIF_IMAGE,0,"服务参数",0,NULL);
  71. this->m_tab.InsertItem(TCIF_TEXT | TCIF_IMAGE,1,"数据处理",1,NULL);
  72. this->m_tab.SetCurSel(m_tabindex);
  73. this->ShowItem();
  74. if (!this->m_bSaveToLog)
  75.         ((CComboBox *)GetDlgItem(IDC_CMLOGITEMCOUNT))->EnableWindow(FALSE);
  76. ((CComboBox *)GetDlgItem(IDC_CMSERVERPORT))->EnableWindow(m_BEnabled);
  77. ((CComboBox *)GetDlgItem(IDC_CMPOLLTIME))->EnableWindow(m_BEnabled);
  78. ((CComboBox *)GetDlgItem(IDC_CMOFFLINETIME))->EnableWindow(m_BEnabled);
  79. ((CButton   *)GetDlgItem(IDC_CKSYSAUTOPOLL))->EnableWindow(m_BEnabled);
  80.     iIndex=0;
  81. ULONG ulIP;
  82. char ipaddr[32];
  83. while ((ulIP=GetIP(iIndex++))>0)
  84. {
  85. sprintf(ipaddr,"%s",inet_ntoa(*((IN_ADDR *)&ulIP)));
  86. m_list.AddString(ipaddr);
  87. }
  88. WSADATA wsa;
  89. if (::WSAStartup(MAKEWORD(1,1),&wsa)!=0)
  90. {
  91. return;
  92. }
  93. struct hostent *hp;
  94. char name[64];
  95. iIndex=0;
  96. if (0==gethostname(name,64))
  97. {
  98. hp=gethostbyname(name);
  99. if (hp!=NULL)
  100. {
  101. while (hp->h_addr_list[iIndex])
  102. {
  103. sprintf(ipaddr,"%s",inet_ntoa(*((IN_ADDR *)hp->h_addr_list[iIndex])));
  104. if (LB_ERR==m_list.FindString(-1,ipaddr))
  105. m_comb.AddString(ipaddr);
  106. iIndex++;
  107. }
  108. }
  109. }
  110. ::WSACleanup();
  111. }
  112. void CSettingDlg::OnSelchangeTab1(NMHDR* pNMHDR, LRESULT* pResult) 
  113. {
  114. m_tabindex=this->m_tab.GetCurSel();
  115. this->ShowItem();
  116. *pResult = 0;
  117. }
  118. void CSettingDlg::ShowItem()
  119. {    
  120. if (0==m_tabindex)
  121. {
  122. ((CStatic *)GetDlgItem(IDC_STATIC1))->SetWindowText("服务端口");
  123. ((CStatic *)GetDlgItem(IDC_STATIC2))->SetWindowText("轮询时间");
  124. ((CStatic *)GetDlgItem(IDC_STATIC3))->SetWindowText("下线时间");
  125.         ((CStatic *)GetDlgItem(IDC_STATIC4))->SetWindowText("IP过滤");
  126. ((CComboBox *)GetDlgItem(IDC_CMSERVERPORT))->ShowWindow(SW_SHOW);
  127. ((CComboBox *)GetDlgItem(IDC_CMPOLLTIME))->ShowWindow(SW_SHOW);
  128. ((CComboBox *)GetDlgItem(IDC_CMOFFLINETIME))->ShowWindow(SW_SHOW);
  129. ((CComboBox *)GetDlgItem(IDC_CMLOGITEMCOUNT))->ShowWindow(SW_HIDE);
  130. ((CButton *)GetDlgItem(IDC_CKSYSAUTOPOLL))->ShowWindow(SW_SHOW);
  131. ((CListBox *)GetDlgItem(IDC_LIST1))->ShowWindow(SW_SHOW);
  132. ((CButton *)GetDlgItem(IDC_DELETEIP))->ShowWindow(SW_SHOW);
  133. ((CComboBox *)GetDlgItem(IDC_COMBO1))->ShowWindow(SW_SHOW);
  134. ((CButton *)GetDlgItem(IDC_CKSAVETOLOG))->ShowWindow(SW_HIDE);
  135. ((CButton *)GetDlgItem(IDC_CKSHOWHEAD))->ShowWindow(SW_HIDE);
  136. ((CButton *)GetDlgItem(IDC_CKHEXSHOW))->ShowWindow(SW_HIDE);
  137. }
  138. else
  139. {
  140.         ((CStatic *)GetDlgItem(IDC_STATIC1))->SetWindowText("日志数量");
  141. ((CStatic *)GetDlgItem(IDC_STATIC2))->SetWindowText("");
  142. ((CStatic *)GetDlgItem(IDC_STATIC3))->SetWindowText("");
  143. ((CStatic *)GetDlgItem(IDC_STATIC4))->SetWindowText("");
  144. ((CComboBox *)GetDlgItem(IDC_CMSERVERPORT))->ShowWindow(SW_HIDE);
  145. ((CComboBox *)GetDlgItem(IDC_CMPOLLTIME))->ShowWindow(SW_HIDE);
  146. ((CComboBox *)GetDlgItem(IDC_CMOFFLINETIME))->ShowWindow(SW_HIDE);
  147. ((CComboBox *)GetDlgItem(IDC_CMLOGITEMCOUNT))->ShowWindow(SW_SHOW);
  148. ((CButton *)GetDlgItem(IDC_CKSYSAUTOPOLL))->ShowWindow(SW_HIDE);
  149. ((CListBox *)GetDlgItem(IDC_LIST1))->ShowWindow(SW_HIDE);
  150. ((CButton *)GetDlgItem(IDC_DELETEIP))->ShowWindow(SW_HIDE);
  151. ((CComboBox *)GetDlgItem(IDC_COMBO1))->ShowWindow(SW_HIDE);
  152. ((CButton *)GetDlgItem(IDC_CKSAVETOLOG))->ShowWindow(SW_SHOW);
  153. ((CButton *)GetDlgItem(IDC_CKSHOWHEAD))->ShowWindow(SW_SHOW);
  154. ((CButton *)GetDlgItem(IDC_CKHEXSHOW))->ShowWindow(SW_SHOW);
  155. }
  156. }
  157. void CSettingDlg::OnCksavetolog() 
  158. {
  159.     CButton *ck;
  160. ck=(CButton *)GetDlgItem(IDC_CKSAVETOLOG);
  161. if (1==ck->GetCheck())
  162. {
  163. ((CComboBox *)GetDlgItem(IDC_CMLOGITEMCOUNT))->EnableWindow(TRUE);
  164. }
  165. else
  166. {
  167. ((CComboBox *)GetDlgItem(IDC_CMLOGITEMCOUNT))->EnableWindow(FALSE);
  168. }
  169. }
  170. void CSettingDlg::OnSelchangeCombo1() 
  171. {
  172. // TODO: Add your control notification handler code here
  173. char buf[32];
  174. m_comb.GetLBText(m_comb.GetCurSel(),buf);
  175. m_list.AddString(buf);
  176. }
  177. void CSettingDlg::OnDeleteip() 
  178. {
  179. int iIndex;
  180. iIndex=m_list.GetCurSel();
  181. if (iIndex>=0)
  182. m_list.DeleteString(iIndex);
  183. }
  184. void CSettingDlg::OnDblclkList1() 
  185. {
  186. OnDeleteip();
  187. }
  188. void CSettingDlg::OnOK() 
  189. {
  190. // TODO: Add extra validation here
  191. char buf[32];
  192. DelFilterIP(0);
  193. for (int i=0;i<m_list.GetCount();i++)
  194. {
  195. m_list.GetText(i,buf);
  196. if (-1==AddFilterIP(inet_addr(buf)))
  197. {
  198. break;
  199. }
  200. }
  201. CDialog::OnOK();
  202. }