DlgDownloadSetup.cpp
资源名称:GGBT.rar [点击查看]
上传用户:lds876
上传日期:2013-05-25
资源大小:567k
文件大小:7k
源码类别:
P2P编程
开发平台:
Visual C++
- // DlgDownloadSetup.cpp : implementation file
- //
- #include "stdafx.h"
- #include "testbt.h"
- #include "DlgDownloadSetup.h"
- #include "FileBase.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- /////////////////////////////////////////////////////////////////////////////
- // CDlgDownloadSetup dialog
- CDlgDownloadSetup::CDlgDownloadSetup(CWnd* pParent /*=NULL*/)
- : CPropertyPage(CDlgDownloadSetup::IDD)
- {
- //{{AFX_DATA_INIT(CDlgDownloadSetup)
- //}}AFX_DATA_INIT
- // m_bCompleteKeepSeed = FALSE;
- m_lConnectErrorMax = 200;
- m_lConnectIntval = 10;
- m_lDownloadAllCount = 10;
- }
- void CDlgDownloadSetup::DoDataExchange(CDataExchange* pDX)
- {
- CPropertyPage::DoDataExchange(pDX);
- //{{AFX_DATA_MAP(CDlgDownloadSetup)
- DDX_Control(pDX, IDC_STATIC_UP_SPEED_INFO, m_stUpSpeedInfo);
- DDX_Control(pDX, IDC_GROUP_UPLOAD_SPEED, m_gpUpSpeed);
- DDX_Control(pDX, IDC_GROUP_CON_SETUP, m_gpConSetup);
- DDX_Control(pDX, IDC_SPIN_COMPLETE_KEEP_SEED_HOUR, m_spinCompleteKeepSeedHour);
- DDX_Control(pDX, IDC_SPIN_DOWNLOAD_ALL_COUNT, m_spinDownloadAllCount);
- DDX_Control(pDX, IDC_SPIN_CONNECT_INTVAL, m_spinConnectIntval);
- DDX_Control(pDX, IDC_SPIN_CONNECT_ERR_MAX, m_spinConnectErrMax);
- DDX_Control(pDX, IDC_COMBO_DOWN_SPEED, m_cbDownSpeed);
- DDX_Control(pDX, IDC_SPIN_PORT_MAX, m_spinPortMax);
- DDX_Control(pDX, IDC_SPIN_PORT_MIN, m_spinPortMin);
- //}}AFX_DATA_MAP
- // DDX_Check(pDX, IDC_CHECK_KEEP_SEED, m_bCompleteKeepSeed);
- }
- BEGIN_MESSAGE_MAP(CDlgDownloadSetup, CPropertyPage)
- //{{AFX_MSG_MAP(CDlgDownloadSetup)
- ON_CBN_SELCHANGE(IDC_COMBO_DOWN_SPEED, OnSelchangeComboDownSpeed)
- //}}AFX_MSG_MAP
- // ON_BN_CLICKED(IDC_CHECK_KEEP_SEED, OnCheckKeepSeed)
- END_MESSAGE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- // CDlgDownloadSetup message handlers
- BOOL CDlgDownloadSetup::OnInitDialog()
- {
- CPropertyPage::OnInitDialog();
- //
- // Up speed setup.
- //
- m_spinPortMin.SetBuddy(GetDlgItem(IDC_EDIT_PORT_MIN));
- m_spinPortMax.SetBuddy(GetDlgItem(IDC_EDIT_PORT_MAX));
- m_spinPortMin.SetRange(1, 31000);
- m_spinPortMax.SetRange(1, 32000);
- m_spinConnectIntval.SetBuddy(GetDlgItem(IDC_EDIT_CONNECT_INTVAL));
- m_spinConnectErrMax.SetBuddy(GetDlgItem(IDC_EDIT_CONNECT_ERR_MAX));
- m_spinDownloadAllCount.SetBuddy(GetDlgItem(IDC_EDIT_DOWNLOAD_ALL_COUNT));
- m_spinConnectIntval.SetRange(0, 500);
- m_spinConnectErrMax.SetRange(1, 10000);
- m_spinDownloadAllCount.SetRange(1, 1000);
- m_spinCompleteKeepSeedHour.SetBuddy(GetDlgItem(IDC_EDIT_COMPLETE_KEEP_SEED_HOUR));
- m_spinCompleteKeepSeedHour.SetRange(0, 1000);
- for (int i=0; i<CSpeedParameters::eSpeedModeAll; i++)
- {
- m_cbDownSpeed.AddString(CSpeedParameters::m_strArrSpeedMode[i]);
- m_cbDownSpeed.SetItemData(m_cbDownSpeed.GetCount()-1, i);
- }
- return TRUE; // return TRUE unless you set the focus to a control
- // EXCEPTION: OCX Property Pages should return FALSE
- }
- bool CDlgDownloadSetup::Apply()
- {
- UpdateData();
- int lower=0, upper=0;
- m_lPortMin = LOWORD(m_spinPortMin.GetPos());
- m_lPortMax = LOWORD(m_spinPortMax.GetPos());
- m_spinPortMin.GetRange(lower, upper);
- m_lPortMin = max(lower, m_lPortMin);
- m_lPortMin = min(upper, m_lPortMin);
- m_spinPortMax.GetRange(lower, upper);
- m_lPortMax = max(lower, m_lPortMax);
- m_lPortMax = min(upper, m_lPortMax);
- m_lPortMax = max(m_lPortMin + 100, m_lPortMax);
- // get pos.
- m_lConnectErrorMax = LOWORD(m_spinConnectErrMax.GetPos());
- m_lConnectIntval = LOWORD(m_spinConnectIntval.GetPos());
- m_lDownloadAllCount = LOWORD(m_spinDownloadAllCount.GetPos());
- m_lCompleteKeepSeedHour = LOWORD(m_spinCompleteKeepSeedHour.GetPos());
- // normalize.
- m_spinConnectErrMax.GetRange(lower, upper);
- m_lConnectErrorMax = max(lower, m_lConnectErrorMax);
- m_lConnectErrorMax = min(upper, m_lConnectErrorMax);
- m_spinConnectIntval.GetRange(lower, upper);
- m_lConnectIntval = max(lower, m_lConnectIntval);
- m_lConnectIntval = min(upper, m_lConnectIntval);
- m_spinDownloadAllCount.GetRange(lower, upper);
- m_lDownloadAllCount = max(lower, m_lDownloadAllCount);
- m_lDownloadAllCount = min(upper, m_lDownloadAllCount);
- m_spinCompleteKeepSeedHour.GetRange(lower, upper);
- m_lCompleteKeepSeedHour = max(lower, m_lCompleteKeepSeedHour);
- m_lCompleteKeepSeedHour = min(upper, m_lCompleteKeepSeedHour);
- // update auto.
- // m_bCompleteKeepSeed =
- m_lDownSpeed = m_cbDownSpeed.GetItemData(m_cbDownSpeed.GetCurSel());
- return true;
- }
- void CDlgDownloadSetup::SetData(CSetupRegister *pSetupRegister)
- {
- m_lDownSpeed = pSetupRegister->m_lDownSpeed;
- m_lPortMin = pSetupRegister->m_lPortMin;
- m_lPortMax = pSetupRegister->m_lPortMax;
- m_lConnectErrorMax = pSetupRegister->m_lConnectErrorMax;
- m_lConnectIntval = pSetupRegister->m_lConnectIntval;
- m_lDownloadAllCount = pSetupRegister->m_lDownloadAllCount;
- // m_bCompleteKeepSeed = pSetupRegister->m_bCompleteKeepSeed;
- m_lCompleteKeepSeedHour = pSetupRegister->m_lCompleteKeepSeedHour;
- m_spinPortMin.SetPos(m_lPortMin);
- m_spinPortMax.SetPos(m_lPortMax);
- m_spinConnectErrMax.SetPos(m_lConnectErrorMax);
- m_spinConnectIntval.SetPos(m_lConnectIntval);
- m_spinDownloadAllCount.SetPos(m_lDownloadAllCount);
- m_spinCompleteKeepSeedHour.SetPos(m_lCompleteKeepSeedHour);
- m_cbDownSpeed.SetCurSel(0);
- for (int i=0; m_cbDownSpeed.GetCount(); i++)
- {
- if (m_cbDownSpeed.GetItemData(i) == m_lDownSpeed)
- {
- m_cbDownSpeed.SetCurSel(i);
- break;
- }
- }
- UpdateData(false);
- OnCheckKeepSeed();
- OnSelchangeComboDownSpeed();
- }
- void CDlgDownloadSetup::GetData(CSetupRegister *pSetupRegister)
- {
- pSetupRegister->m_lDownSpeed = m_lDownSpeed;
- pSetupRegister->m_lPortMin = m_lPortMin ;
- pSetupRegister->m_lPortMax = m_lPortMax;
- pSetupRegister->m_lConnectErrorMax = m_lConnectErrorMax;
- pSetupRegister->m_lConnectIntval = m_lConnectIntval;
- pSetupRegister->m_lDownloadAllCount = m_lDownloadAllCount;
- pSetupRegister->m_lCompleteKeepSeedHour = m_lCompleteKeepSeedHour;
- // pSetupRegister->m_bCompleteKeepSeed = m_bCompleteKeepSeed != 0;
- }
- void CDlgDownloadSetup::OnOK()
- {
- GetParent()->SendMessage(WM_COMMAND, IDOK, 0);
- CPropertyPage::OnOK();
- }
- void CDlgDownloadSetup::OnCancel()
- {
- GetParent()->SendMessage(WM_COMMAND, IDCANCEL, 0);
- CPropertyPage::OnCancel();
- }
- void CDlgDownloadSetup::OnCheckKeepSeed()
- {
- UpdateData();
- // m_spinCompleteKeepSeedHour.EnableWindow(m_bCompleteKeepSeed);
- // GetDlgItem(IDC_EDIT_COMPLETE_KEEP_SEED_HOUR)->EnableWindow(m_bCompleteKeepSeed);
- }
- void CDlgDownloadSetup::OnSelchangeComboDownSpeed()
- {
- long lCurSel = m_cbDownSpeed.GetCurSel();
- if (lCurSel < 0 || lCurSel >= CSpeedParameters::eSpeedModeAll)
- {
- ASSERT(FALSE);
- return;
- }
- CString strText;
- strText.Format("最大上传速度(0代表无限速): %dKB, 最大上传连接:%d", CSpeedParameters::m_lArrSpeedVal[lCurSel], CSpeedParameters::m_lArrPeerVal[lCurSel]);
- m_stUpSpeedInfo.SetWindowText(strText);
- }