Sitebook.cpp
上传用户:wpp2016
上传日期:2010-02-01
资源大小:1250k
文件大小:5k
源码类别:

Telnet服务器

开发平台:

Visual C++

  1. // Sitebook.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "anywhere.h"
  5. #include "Sitebook.h"
  6. #include "thread1.h"
  7. #ifdef _DEBUG
  8. #define new DEBUG_NEW
  9. #undef THIS_FILE
  10. static char THIS_FILE[] = __FILE__;
  11. #endif
  12. /////////////////////////////////////////////////////////////////////////////
  13. // CSitebook dialog
  14. const char sitebook[]="sitebook";
  15. static CString iplist[]={
  16. "ip1",
  17. "ip2",
  18. "ip3",
  19. "ip4",
  20. "ip5"
  21. };
  22. static CString label[]={
  23. "label1",
  24. "label2",
  25. "label3",
  26. "label4",
  27. "label5"
  28. };
  29. static CString user[]={
  30. "user1",
  31. "user2",
  32. "user3",
  33. "user4",
  34. "user5"
  35. };
  36. static CString pass[]={
  37. "pass1",
  38. "pass2",
  39. "pass3",
  40. "pass4",
  41. "pass5"
  42. };
  43. CSitebook::CSitebook(CWnd* pParent /*=NULL*/)
  44. : CDialog(CSitebook::IDD, pParent)
  45. {
  46. //{{AFX_DATA_INIT(CSitebook)
  47. m_ip = _T("");
  48. m_label = _T("");
  49. m_password = _T("");
  50. m_username = _T("");
  51. //}}AFX_DATA_INIT
  52. bFirst=true;
  53. }
  54. void CSitebook::DoDataExchange(CDataExchange* pDX)
  55. {
  56. CDialog::DoDataExchange(pDX);
  57. //{{AFX_DATA_MAP(CSitebook)
  58. DDX_Control(pDX, IDC_ASSUME, m_btassume);
  59. DDX_Control(pDX, IDOK, m_btok);
  60. DDX_Control(pDX, IDCANCEL, m_btcancel);
  61. DDX_Control(pDX, IDC_APPLY, m_btapply);
  62. DDX_Control(pDX, IDC_SITE_LIST, m_site);
  63. DDX_Text(pDX, IDC_IP, m_ip);
  64. DDX_Text(pDX, IDC_LABEL, m_label);
  65. DDX_Text(pDX, IDC_PASSWORD, m_password);
  66. DDX_Text(pDX, IDC_USER, m_username);
  67. //}}AFX_DATA_MAP
  68. }
  69. BEGIN_MESSAGE_MAP(CSitebook, CDialog)
  70. //{{AFX_MSG_MAP(CSitebook)
  71. ON_NOTIFY(NM_CLICK, IDC_SITE_LIST, OnClickSiteList)
  72. ON_BN_CLICKED(IDC_APPLY, OnApply)
  73. //}}AFX_MSG_MAP
  74. END_MESSAGE_MAP()
  75. /////////////////////////////////////////////////////////////////////////////
  76. // CSitebook message handlers
  77. BOOL CSitebook::OnInitDialog() 
  78. {
  79. CDialog::OnInitDialog();
  80. m_ImageList.Create(32,32,ILC_COLOR16|ILC_MASK,5,1);
  81. m_ImageList.Add(AfxGetApp()->LoadIcon(IDI_IPLIST));
  82. m_site.SetImageList(&m_ImageList,LVSIL_NORMAL);
  83. m_btassume.SetCheck(1);
  84. readdata();
  85.   //if (bFirst) {
  86.   
  87. //m_treedir.SubclassDlgItem(IDC_TREE_DIR, this );
  88. //m_TreeCtrl->Expand(m_root,TVE_EXPAND);
  89. //m_TreeCtrl->Expand(m_child,TVE_EXPAND);
  90. //m_TreeCtrl->SelectItem(m_child);
  91.     //m_treedir.FindDir("\debug");
  92. //select=FALSE;
  93. //m_treedir.SetSelPath("e:\myproject\anywhere\Include");
  94.     //m_treedir.init("e:\myproject");//SetRoot("我的配置文件夹");
  95. return TRUE;  // return TRUE unless you set the focus to a control
  96.               // EXCEPTION: OCX Property Pages should return FALSE
  97. }
  98. void CSitebook::OnOK() 
  99. {
  100. UpdateData(TRUE);
  101. if (m_username.GetLength()!=8 || m_password.GetLength()!=8) 
  102. return;
  103. if (m_ip.IsEmpty()||m_username.IsEmpty()||m_password.IsEmpty()) {
  104. CString sErrmsg,caption;
  105. sErrmsg.LoadString(IDS_WRONG_ACTION);
  106. caption.LoadString(IDS_CAPTION);
  107. MessageBox(sErrmsg,caption,MB_OK);
  108. return;
  109. }
  110. linkrc.ip=m_ip;
  111. linkrc.mainport=7700;//主端口
  112. linkrc.getfileport=9110;//getfile端口;
  113. linkrc.putfileport=9111;//putfile端口;
  114. linkrc.viewport=9113;//viewscr端口;
  115. linkrc.username=m_username;
  116. linkrc.password=m_password;
  117. linkrc.sAddr=CSockAddr(linkrc.ip,linkrc.mainport);
  118.     if (m_btassume.GetCheck()==1) linkrc.bConnected=FALSE;
  119.    else linkrc.bConnected=TRUE;
  120. //linkrc.bConnected=FALSE;
  121.     //设定主端口及ip
  122.     //strcpy(linkrc.sbuf,linkrc.username);
  123. //strcat(linkrc.sbuf,linkrc.password);
  124. CDialog::OnOK();
  125. }
  126. void CSitebook::OnClickSiteList(NMHDR* pNMHDR, LRESULT* pResult) 
  127. {
  128.     int i=m_site.GetNextItem(-1,LVNI_ALL|LVNI_SELECTED);
  129. if (i==-1) return ;
  130. m_label=strlabel[i];//m_site.GetItemText(i,0);
  131. m_ip=strip[i];
  132. m_username=struser[i];
  133. m_password=strpass[i];
  134. UpdateData(FALSE);
  135. *pResult = 0;
  136. }
  137. void CSitebook::OnApply() 
  138. {
  139.    UpdateData(TRUE);
  140.    int i=m_site.GetNextItem(-1,LVNI_ALL|LVNI_SELECTED);
  141.    if (i==-1) return;
  142.    AfxGetApp()->WriteProfileString(sitebook,iplist[i],m_ip);
  143.    AfxGetApp()->WriteProfileString(sitebook,label[i],m_label);
  144.    AfxGetApp()->WriteProfileString(sitebook,user[i],m_username);
  145.    AfxGetApp()->WriteProfileString(sitebook,pass[i],m_password);
  146.    readdata();
  147. }
  148. void CSitebook::readdata()
  149. {
  150. m_site.DeleteAllItems();
  151. for (int i=0;i<5;i++)
  152.   {
  153.   strip[i]=AfxGetApp()->GetProfileString(sitebook,iplist[i]);
  154.   strlabel[i]=AfxGetApp()->GetProfileString(sitebook,label[i]);
  155.   struser[i]=AfxGetApp()->GetProfileString(sitebook,user[i]);
  156.   strpass[i]=AfxGetApp()->GetProfileString(sitebook,pass[i]);
  157.   m_site.InsertItem(i,strlabel[i],0);
  158.   }
  159. timeout=AfxGetApp()->GetProfileInt("Settings","timeout",30);
  160. request=AfxGetApp()->GetProfileInt("Settings","request",300);
  161. }