DlgAdvancedPage.cpp
上传用户:lds876
上传日期:2013-05-25
资源大小:567k
文件大小:10k
源码类别:

P2P编程

开发平台:

Visual C++

  1. // DlgAdvancedPage.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "testbt.h"
  5. #include "DlgAdvancedPage.h"
  6. #ifdef _DEBUG
  7. #define new DEBUG_NEW
  8. #undef THIS_FILE
  9. static char THIS_FILE[] = __FILE__;
  10. #endif
  11. /////////////////////////////////////////////////////////////////////////////
  12. // CDlgAdvancedPage dialog
  13. CDlgAdvancedPage::CDlgAdvancedPage(CWnd* pParent /*=NULL*/)
  14. : CPropertyPage(CDlgAdvancedPage::IDD)
  15. {
  16. //{{AFX_DATA_INIT(CDlgAdvancedPage)
  17. m_strSendServerIP = _T("");
  18. m_strBindIP = _T("");
  19. //}}AFX_DATA_INIT
  20. m_lPeersMin = 0;
  21. m_lPeersMax = 0;
  22. m_lDisplayItval = 0;
  23. m_lAllocSpeed = 0;
  24. m_eAllocType = CStorageWrapperEx::eAllocNormal;
  25. m_lFileOpenMax = 0;
  26. m_bSuperSeed = false;
  27. m_pSetupRegister = 0;
  28. }
  29. void CDlgAdvancedPage::DoDataExchange(CDataExchange* pDX)
  30. {
  31. CPropertyPage::DoDataExchange(pDX);
  32. //{{AFX_DATA_MAP(CDlgAdvancedPage)
  33. DDX_Control(pDX, IDC_BUTTON_RESET, m_btnReset);
  34. DDX_Control(pDX, IDC_GROUP_ADVSETUP, m_gpAdvSetup);
  35. DDX_Control(pDX, IDC_COMBO_FILE_LOCK, m_cbFileLock);
  36. DDX_Control(pDX, IDC_COMBO_EXTRA_CHECK, m_cbExtraCheck);
  37. DDX_Control(pDX, IDC_SPIN_ALLOC_SPEED, m_spinAllocSpeed);
  38. DDX_Control(pDX, IDC_COMBO_SEED_TYPE, m_cbSeedType);
  39. DDX_Control(pDX, IDC_COMBO_FILEOPEN_MAX, m_cbFileOpenMax);
  40. DDX_Control(pDX, IDC_COMBO_ALLOC_TYPE, m_cbAllocType);
  41. DDX_Control(pDX, IDC_SPIN_PEERS_MAX, m_spinPeersMax);
  42. DDX_Control(pDX, IDC_SPIN_DISPLAY_ITVAL, m_spinDisplayItval);
  43. DDX_Control(pDX, IDC_SPIN_PEERS_MIN, m_spinPeersMin);
  44. DDX_Text(pDX, IDC_EDIT_SEND_SERVER_IP, m_strSendServerIP);
  45. DDX_Text(pDX, IDC_EDIT_BIND_IP, m_strBindIP);
  46. //}}AFX_DATA_MAP
  47. }
  48. BEGIN_MESSAGE_MAP(CDlgAdvancedPage, CPropertyPage)
  49. //{{AFX_MSG_MAP(CDlgAdvancedPage)
  50. ON_BN_CLICKED(IDC_BUTTON_RESET, OnButtonReset)
  51. //}}AFX_MSG_MAP
  52. END_MESSAGE_MAP()
  53. /////////////////////////////////////////////////////////////////////////////
  54. // CDlgAdvancedPage message handlers
  55. BOOL CDlgAdvancedPage::OnInitDialog() 
  56. {
  57. CPropertyPage::OnInitDialog();
  58. // spins.
  59. m_spinPeersMin.SetBuddy(GetDlgItem(IDC_EDIT_PEERS_MIN));
  60. m_spinPeersMax.SetBuddy(GetDlgItem(IDC_EDIT_PEERS_MAX));
  61. m_spinDisplayItval.SetBuddy(GetDlgItem(IDC_EDIT_DISPLAY_ITVAL));
  62. m_spinAllocSpeed.SetBuddy(GetDlgItem(IDC_EDIT_ALLOC_SPEED));
  63. m_spinPeersMin.SetRange(10, 60);
  64. m_spinPeersMax.SetRange(10, 60);
  65. m_spinDisplayItval.SetRange(100, 10000);
  66. m_spinAllocSpeed.SetRange(1, 10);
  67. // CComboBox
  68. m_cbAllocType.AddString("普通分配");
  69. m_cbAllocType.SetItemData(m_cbAllocType.GetCount()-1, CStorageWrapperEx::eAllocNormal);
  70. m_cbAllocType.AddString("后台分配");
  71. m_cbAllocType.SetItemData(m_cbAllocType.GetCount()-1, CStorageWrapperEx::eAllocBackGound);
  72. m_cbAllocType.AddString("预分配");
  73. m_cbAllocType.SetItemData(m_cbAllocType.GetCount()-1, CStorageWrapperEx::eAllocPreAllocate);
  74. m_cbAllocType.AddString("特殊分配");
  75. m_cbAllocType.SetItemData(m_cbAllocType.GetCount()-1, CStorageWrapperEx::eAllocSparse);
  76. m_cbFileOpenMax.AddString("50");
  77. m_cbFileOpenMax.SetItemData(m_cbFileOpenMax.GetCount()-1, 50);
  78. m_cbFileOpenMax.AddString("100");
  79. m_cbFileOpenMax.SetItemData(m_cbFileOpenMax.GetCount()-1, 100);
  80. m_cbFileOpenMax.AddString("200");
  81. m_cbFileOpenMax.SetItemData(m_cbFileOpenMax.GetCount()-1, 200);
  82. m_cbFileOpenMax.AddString("无限制");
  83. m_cbFileOpenMax.SetItemData(m_cbFileOpenMax.GetCount()-1, 0);
  84. m_cbSeedType.AddString("普通");
  85. m_cbSeedType.SetItemData(m_cbSeedType.GetCount()-1, 0);
  86. m_cbSeedType.AddString("超级种子");
  87. m_cbSeedType.SetItemData(m_cbSeedType.GetCount()-1, 1);
  88. for (int i=0; i<CSetupRegister::eFileLockCount; i++)
  89. m_cbFileLock.AddString(CSetupRegister::m_strFileLock[i]);
  90. for (i=0; i<CSetupRegister::eExtraCheckCount; i++)
  91. m_cbExtraCheck.AddString(CSetupRegister::m_strExtraCheck[i]);
  92. //
  93. // Tool tip
  94. //
  95. m_Tooltip.Create(this);
  96. m_Tooltip.SetMaxTipWidth(200);
  97. m_Tooltip.Activate(TRUE); 
  98. EnableToolTips();
  99. CRect rcItem;
  100. GetDlgItem(IDC_EDIT_SEND_SERVER_IP)->GetWindowRect(&rcItem);
  101. ScreenToClient(rcItem);
  102. //if (!m_Tooltip.AddTool(this, "你好", rcItem, IDC_EDIT_SEND_SERVER_IP))
  103. if (!m_Tooltip.AddTool(GetDlgItem(IDC_EDIT_PEERS_MIN), "当达到最小下载者数时,不再试图连接服务器,来获得新的客户端信息"))
  104. {
  105. ASSERT(FALSE);
  106. }
  107. if (!m_Tooltip.AddTool(GetDlgItem(IDC_EDIT_PEERS_MAX), "连接客户端数量的最大值,达到这个值后,系统不再新建与其他客户端的连接"))
  108. {
  109. ASSERT(FALSE);
  110. }
  111. if (!m_Tooltip.AddTool(GetDlgItem(IDC_COMBO_FILE_LOCK), "文件锁定选项防止数据在下载过程中被破坏."))
  112. {
  113. ASSERT(FALSE);
  114. }
  115. if (!m_Tooltip.AddTool(GetDlgItem(IDC_COMBO_EXTRA_CHECK), "该选项设定程序做额外的文件检查以便确定没有被破坏的文件,双倍检查可能耗用cpu资源,完全检查将减慢磁盘读写速度."))
  116. {
  117. ASSERT(FALSE);
  118. }
  119. if (!m_Tooltip.AddTool(GetDlgItem(IDC_COMBO_ALLOC_TYPE), "普通分配:将让文件大小随下载过程逐渐增长,这将有利于加快文件检查速度.rnrn后台分配:将在下载过程中分配空间.rnrn预分配:在下载前完成分配,这将有助于减少文件碎片.rnrn特殊分配:将先数据保存到一个地方直到下载完成移动数据"))
  120. {
  121. ASSERT(FALSE);
  122. }
  123. if (!m_Tooltip.AddTool(GetDlgItem(IDC_EDIT_ALLOC_SPEED), "安置速度是指在后台分配方式下,后台分配空间的速度"))
  124. {
  125. ASSERT(FALSE);
  126. }
  127. if (!m_Tooltip.AddTool(GetDlgItem(IDC_COMBO_FILEOPEN_MAX), "在同一时间打开文件的最大值,零表示无限制.注意这个选项有效时不能保证文件被锁定"))
  128. {
  129. ASSERT(FALSE);
  130. }
  131. if (!m_Tooltip.AddTool(GetDlgItem(IDC_COMBO_SEED_TYPE), "超级种子能让你更有效地做一个大文件的种子."))
  132. {
  133. ASSERT(FALSE);
  134. }
  135. if (!m_Tooltip.AddTool(GetDlgItem(IDC_EDIT_DISPLAY_ITVAL), "更新显示时间的间隔.单位是千分之一秒,这个值设得太低将会拖慢你的系统和视频播放."))
  136. {
  137. ASSERT(FALSE);
  138. }
  139. if (!m_Tooltip.AddTool(GetDlgItem(IDC_EDIT_SEND_SERVER_IP), "报告给服务器的IP."))
  140. {
  141. ASSERT(FALSE);
  142. }
  143. if (!m_Tooltip.AddTool(GetDlgItem(IDC_EDIT_BIND_IP), "客户端绑定的IP,这个选项只有在你可以直接连接到多个IP时才有效,如果你不知道如何设置,请将留空."))
  144. {
  145. ASSERT(FALSE);
  146. }
  147. return TRUE;  // return TRUE unless you set the focus to a control
  148.               // EXCEPTION: OCX Property Pages should return FALSE
  149. }
  150. bool CDlgAdvancedPage::Apply()
  151. {
  152. UpdateData();
  153. int lower=0, upper=0;
  154. m_lPeersMin = LOWORD(m_spinPeersMin.GetPos());
  155. m_lPeersMax = LOWORD(m_spinPeersMax.GetPos());
  156. m_lDisplayItval = LOWORD(m_spinDisplayItval.GetPos());
  157. m_lAllocSpeed = LOWORD(m_spinAllocSpeed.GetPos());
  158. m_spinPeersMin.GetRange(lower, upper);
  159. m_lPeersMin = max(lower, m_lPeersMin);
  160. m_lPeersMin = min(upper, m_lPeersMin);
  161. m_spinPeersMax.GetRange(lower, upper);
  162. m_lPeersMax = max(lower, m_lPeersMax);
  163. m_lPeersMax = min(upper, m_lPeersMax);
  164. if (m_lPeersMin >= m_lPeersMax)
  165. {
  166. m_spinPeersMin.GetRange(lower, upper);
  167. m_lPeersMin = lower;
  168. }
  169. m_spinDisplayItval.GetRange(lower, upper);
  170. m_lDisplayItval = max(lower, m_lDisplayItval);
  171. m_lDisplayItval = min(upper, m_lDisplayItval);
  172. m_spinAllocSpeed.GetRange(lower, upper);
  173. m_lAllocSpeed = max(lower, m_lAllocSpeed);
  174. m_lAllocSpeed = min(upper, m_lAllocSpeed);
  175. m_eAllocType = (CStorageWrapperEx::eAllocType)m_cbAllocType.GetItemData(m_cbAllocType.GetCurSel());
  176. m_lFileOpenMax = m_cbFileOpenMax.GetItemData(m_cbFileOpenMax.GetCurSel());
  177. m_bSuperSeed = m_cbSeedType.GetItemData(m_cbSeedType.GetCurSel()) > 0;
  178. return true;
  179. }
  180. void CDlgAdvancedPage::SetData(CSetupRegister *pSetupRegister)
  181. {
  182. m_pSetupRegister = pSetupRegister;
  183. m_lPeersMin = pSetupRegister->m_lPeersMin;
  184. m_lPeersMax = pSetupRegister->m_lPeersMax;
  185. m_lDisplayItval = pSetupRegister->m_lDisplayItval;
  186. m_lAllocSpeed = pSetupRegister->m_lAllocSpeed;
  187. m_eAllocType = pSetupRegister->m_eAllocType;
  188. m_lFileOpenMax = pSetupRegister->m_lFileOpenMax;
  189. m_bSuperSeed = pSetupRegister->m_bSuperSeed;
  190. m_spinPeersMin.SetPos(m_lPeersMin);
  191. m_spinPeersMax.SetPos(m_lPeersMax);
  192. m_spinDisplayItval.SetPos(m_lDisplayItval);
  193. m_spinAllocSpeed.SetPos(m_lAllocSpeed);
  194. m_cbAllocType.SetCurSel(0);
  195. for (int i=0; m_cbAllocType.GetCount(); i++)
  196. {
  197. if (m_cbAllocType.GetItemData(i) == m_eAllocType)
  198. {
  199. m_cbAllocType.SetCurSel(i);
  200. break;
  201. }
  202. }
  203. m_cbFileOpenMax.SetCurSel(0);
  204. for (i=0; m_cbFileOpenMax.GetCount(); i++)
  205. {
  206. if (m_cbFileOpenMax.GetItemData(i) == m_lFileOpenMax)
  207. {
  208. m_cbFileOpenMax.SetCurSel(i);
  209. break;
  210. }
  211. }
  212. m_cbSeedType.SetCurSel(0);
  213. for (i=0; m_cbSeedType.GetCount(); i++)
  214. {
  215. if (m_cbSeedType.GetItemData(i) == (long)m_bSuperSeed)
  216. {
  217. m_cbSeedType.SetCurSel(i);
  218. break;
  219. }
  220. }
  221. m_cbFileLock.SetCurSel(pSetupRegister->m_eFileLock);
  222. m_cbExtraCheck.SetCurSel(pSetupRegister->m_eExtraCheck);
  223. m_strBindIP = m_strSendServerIP = "";
  224. in_addr inaddress;
  225. if (pSetupRegister->m_lBindIP != INADDR_NONE )
  226. {
  227. inaddress.S_un.S_addr = pSetupRegister->m_lBindIP;
  228. m_strBindIP = inet_ntoa(inaddress);
  229. }
  230. if (pSetupRegister->m_lSendServerIP != INADDR_NONE)
  231. {
  232. inaddress.S_un.S_addr = pSetupRegister->m_lSendServerIP;
  233. m_strSendServerIP = inet_ntoa(inaddress);
  234. }
  235. UpdateData(false);
  236. }
  237. void CDlgAdvancedPage::GetData(CSetupRegister *pSetupRegister)
  238. {
  239. pSetupRegister->m_lPeersMin = m_lPeersMin;
  240. pSetupRegister->m_lPeersMax = m_lPeersMax ;
  241. pSetupRegister->m_lDisplayItval = m_lDisplayItval;
  242. pSetupRegister->m_lAllocSpeed = m_lAllocSpeed;
  243. pSetupRegister->m_eAllocType = m_eAllocType;
  244. pSetupRegister->m_lFileOpenMax = m_lFileOpenMax;
  245. pSetupRegister->m_bSuperSeed = m_bSuperSeed;
  246. pSetupRegister->m_eFileLock = (CSetupRegister::eFileLockType)m_cbFileLock.GetCurSel();
  247. pSetupRegister->m_eExtraCheck = (CSetupRegister::eExtraCheck)m_cbExtraCheck.GetCurSel();
  248. pSetupRegister->m_lBindIP = inet_addr(m_strBindIP);
  249. pSetupRegister->m_lSendServerIP = inet_addr(m_strSendServerIP);
  250. }
  251. void CDlgAdvancedPage::OnOK() 
  252. {
  253. GetParent()->SendMessage(WM_COMMAND, IDOK, 0);
  254. CPropertyPage::OnOK();
  255. }
  256. void CDlgAdvancedPage::OnCancel() 
  257. {
  258. GetParent()->SendMessage(WM_COMMAND, IDCANCEL, 0);
  259. CPropertyPage::OnCancel();
  260. }
  261. void CDlgAdvancedPage::OnButtonReset() 
  262. {
  263. /*
  264. if (!m_pSetupRegister)
  265. {
  266. assert(false);
  267. return;
  268. }
  269. m_pSetupRegister->GetDefaultAdvaced();
  270. //*/
  271. CSetupRegister tempSetupRegister;
  272. SetData(&tempSetupRegister);
  273. }
  274. BOOL CDlgAdvancedPage::PreTranslateMessage(MSG* pMsg) 
  275. {
  276. ASSERT(m_Tooltip.GetSafeHwnd());
  277. m_Tooltip.RelayEvent(pMsg);
  278. CWnd* pNext = GetNextDlgTabItem(0);
  279. if (pMsg->message == WM_KEYDOWN && GetAsyncKeyState(VK_CONTROL) < 0 &&
  280. (pMsg->wParam == VK_TAB || pMsg->wParam == VK_PRIOR || pMsg->wParam == VK_NEXT))
  281. {
  282. }
  283. return CPropertyPage::PreTranslateMessage(pMsg);
  284. }