DlgRunParameters.cpp
资源名称:GGBT.rar [点击查看]
上传用户:lds876
上传日期:2013-05-25
资源大小:567k
文件大小:15k
源码类别:
P2P编程
开发平台:
Visual C++
- // DlgRunParameters.cpp : implementation file
- //
- #include "stdafx.h"
- #include "testbt.h"
- #include "DlgRunParameters.h"
- #include "FileDB.h"
- #include "SetupRegister.h"
- #include "Download.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- /////////////////////////////////////////////////////////////////////////////
- // CDlgRunParameters dialog
- CDlgRunParameters::CDlgRunParameters(CFileDBItem* pFileDBItem, CSetupRegister* pSetupRegister, CWnd* pParent /*=NULL*/)
- : CDialog(CDlgRunParameters::IDD, pParent)
- {
- //{{AFX_DATA_INIT(CDlgRunParameters)
- // NOTE: the ClassWizard will add member initialization here
- //}}AFX_DATA_INIT
- m_pSetupRegister = pSetupRegister;
- m_pFileDBItem = pFileDBItem;
- assert(m_pFileDBItem && m_pSetupRegister);
- }
- void CDlgRunParameters::DoDataExchange(CDataExchange* pDX)
- {
- CDialog::DoDataExchange(pDX);
- //{{AFX_DATA_MAP(CDlgRunParameters)
- DDX_Control(pDX, IDC_SPIN_CONNECT_INTVAL, m_spinConnectIntval);
- DDX_Control(pDX, IDC_SPIN_CONNECT_ERR_MAX, m_spinConnectErrMax);
- DDX_Control(pDX, IDC_SPIN_PEERS_MAX_SPECIAL, m_spinPeersMax);
- DDX_Control(pDX, IDC_SPIN_PEERS_MIN_SPECIAL, m_spinPeersMin);
- DDX_Control(pDX, IDC_SPIN_COMPLETE_KEEP_SEED_HOUR, m_spinCompleteKeepSeedHour);
- DDX_Control(pDX, IDC_GROUP_UPSPEED, m_gpUpSpeed);
- DDX_Control(pDX, IDC_GROUP_GERNERAL, m_gpGeneral);
- DDX_Control(pDX, IDCANCEL, m_btnCancel);
- DDX_Control(pDX, IDOK, m_btnOK);
- DDX_Control(pDX, IDC_STATIC_SPEED_MAX, m_stSpeedMax);
- DDX_Control(pDX, IDC_STATIC_SPEED_MIN, m_stSpeedMin);
- DDX_Control(pDX, IDC_STATIC_PEERS_MAX, m_stPeersMax);
- DDX_Control(pDX, IDC_STATIC_PEERS_MIN, m_stPeersMin);
- DDX_Control(pDX, IDC_COMBO_GLOBAL_SETUP, m_cbGlobalSetup);
- DDX_Control(pDX, IDC_SLIDER_UPLOAD_SPEED_MAX, m_sliderUploadSpeedMax);
- DDX_Control(pDX, IDC_SLIDER_UPLOAD_PEERS_MAX, m_sliderUploadPeersMax);
- DDX_Control(pDX, IDC_SPIN_UPLOAD_SPEED_MAX, m_spinUploadSpeedMax);
- DDX_Control(pDX, IDC_SPIN_UPLOAD_PEERS_MAX, m_spinUploadPeersMax);
- DDX_Control(pDX, IDC_COMBO_DOWN_SPEED, m_cbDownSpeed);
- //}}AFX_DATA_MAP
- }
- BEGIN_MESSAGE_MAP(CDlgRunParameters, CDialog)
- //{{AFX_MSG_MAP(CDlgRunParameters)
- ON_CBN_SELCHANGE(IDC_COMBO_GLOBAL_SETUP, OnSelchangeComboGlobalSetup)
- ON_CBN_SELCHANGE(IDC_COMBO_DOWN_SPEED, OnSelchangeComboDownSpeed)
- ON_WM_HSCROLL()
- ON_NOTIFY(UDN_DELTAPOS, IDC_SPIN_UPLOAD_SPEED_MAX, OnDeltaposSpinUploadSpeedMax)
- ON_NOTIFY(UDN_DELTAPOS, IDC_SPIN_UPLOAD_PEERS_MAX, OnDeltaposSpinUploadPeersMax)
- ON_WM_VSCROLL()
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- // CDlgRunParameters message handlers
- BOOL CDlgRunParameters::OnInitDialog()
- {
- CDialog::OnInitDialog();
- ///////////////////////////////////////////////////////////////////////
- // Create BitmapList
- //
- HBITMAP hbm = (HBITMAP)::LoadImage(AfxGetInstanceHandle(),
- MAKEINTRESOURCE(IDB_BITMAP_DLG_ICONS),
- IMAGE_BITMAP,
- 0,0, // cx,cy
- LR_CREATEDIBSECTION); // | LR_LOADMAP3DCOLORS );
- CBitmap bm;
- bm.Attach(hbm);
- m_ctlImage.Create(16,15, ILC_COLOR8|ILC_MASK, 3, 4);
- m_ctlImage.SetBkColor(RGB(255, 255,255));
- m_ctlImage.Add(&bm, (COLORREF)RGB(255,0,255));
- //
- // set button image.
- //
- // m_btnBrowseDir.Create(m_ctlImage.ExtractIcon(2), true, "选择保存路径");
- m_btnOK.Create(m_ctlImage.ExtractIcon(0));
- m_btnCancel.Create(m_ctlImage.ExtractIcon(1));
- /////////////////////////////////////////////////////////////////////
- // init data
- if (!m_pFileDBItem->m_bSpecialRunParameter)
- {
- m_pFileDBItem->m_lUploadSpeedMode = m_pSetupRegister->m_lDownSpeed;
- m_pFileDBItem->m_lUploadSpeedMax = CSpeedParameters::m_lArrSpeedVal[m_pSetupRegister->m_lDownSpeed];
- m_pFileDBItem->m_lUploadPeerMax = CSpeedParameters::m_lArrPeerVal[m_pSetupRegister->m_lDownSpeed];
- m_pFileDBItem->m_lPeersMin = m_pSetupRegister->m_lPeersMin;
- m_pFileDBItem->m_lPeersMax = m_pSetupRegister->m_lPeersMax;
- m_pFileDBItem->m_lConnectErrorMax = m_pSetupRegister->m_lConnectErrorMax;
- m_pFileDBItem->m_lConnectIntval = m_pSetupRegister->m_lConnectIntval;
- m_pFileDBItem->m_lCompleteKeepSeedHour = m_pSetupRegister->m_lCompleteKeepSeedHour;
- }
- /////////////////////////////////////////////////////////////////////
- // upspeed.
- // init contronls data.
- m_cbGlobalSetup.AddString("所有参数使用全局设置");
- m_cbGlobalSetup.AddString("使用特殊设置");
- for (int i=0; i<CSpeedParameters::eSpeedModeAll; i++)
- {
- m_cbDownSpeed.AddString(CSpeedParameters::m_strArrSpeedMode[i]);
- m_cbDownSpeed.SetItemData(m_cbDownSpeed.GetCount()-1, i);
- }
- m_spinUploadSpeedMax.SetBuddy(GetDlgItem(IDC_EDIT_UPLOAD_SPEED_MAX));
- m_spinUploadPeersMax.SetBuddy(GetDlgItem(IDC_EDIT_UPLOAD_PEERS_MAX));
- // show cur state.
- m_cbGlobalSetup.SetCurSel(m_pFileDBItem->m_bSpecialRunParameter);
- // m_cbDownSpeed.SetCurSel(m_pFileDBItem->m_lUploadSpeedMode);
- // OnSelchangeComboDownSpeed();
- // SetValue(m_pFileDBItem->m_lUploadSpeedMax, m_pFileDBItem->m_lUploadPeerMax);
- /////////////////////////////////////////////////////////////////////
- // general setup.
- //
- m_spinCompleteKeepSeedHour.SetBuddy(GetDlgItem(IDC_EDIT_COMPLETE_KEEP_SEED_HOUR));
- m_spinPeersMin.SetBuddy(GetDlgItem(IDC_EDIT_PEERS_MIN_SPECIAL));
- m_spinPeersMax.SetBuddy(GetDlgItem(IDC_EDIT_PEERS_MAX_SPECIAL));
- m_spinConnectErrMax.SetBuddy(GetDlgItem(IDC_EDIT_CONNECT_ERR_MAX));
- m_spinConnectIntval.SetBuddy(GetDlgItem(IDC_EDIT_CONNECT_INTVAL));
- m_spinPeersMin.SetRange(10, 60);
- m_spinPeersMax.SetRange(10, 60);
- m_spinCompleteKeepSeedHour.SetRange(0, 1000);
- m_spinConnectIntval.SetRange(0, 500);
- m_spinConnectErrMax.SetRange(1, 10000);
- ///////////////////////////////////////////////////////////////////////
- // set all values.
- //
- OnSelchangeComboGlobalSetup();
- return TRUE; // return TRUE unless you set the focus to a control
- // EXCEPTION: OCX Property Pages should return FALSE
- }
- void CDlgRunParameters::OnOK()
- {
- m_pFileDBItem->m_bSpecialRunParameter = m_cbGlobalSetup.GetCurSel() > 0;
- ////////////////////////////////////////////
- // Get data from ctrl.
- //
- // upspeed.
- //
- m_pFileDBItem->m_lUploadSpeedMode = m_cbDownSpeed.GetCurSel(); //m_cbDownSpeed.GetItemData(iCurSel);
- m_pFileDBItem->m_lUploadSpeedMax = m_sliderUploadSpeedMax.GetPos();
- m_pFileDBItem->m_lUploadPeerMax = m_sliderUploadPeersMax.GetPos();
- //
- // gerneral.
- //
- m_pFileDBItem->m_lPeersMin = GetSpinValue(m_spinPeersMin);
- m_pFileDBItem->m_lPeersMax = GetSpinValue(m_spinPeersMax);
- m_pFileDBItem->m_lConnectErrorMax = GetSpinValue(m_spinConnectErrMax);
- m_pFileDBItem->m_lConnectIntval = GetSpinValue(m_spinConnectIntval);
- m_pFileDBItem->m_lCompleteKeepSeedHour = GetSpinValue(m_spinCompleteKeepSeedHour);
- if (m_pFileDBItem->m_lPeersMin >= m_pFileDBItem->m_lPeersMax)
- {
- int lower=0, upper=0;
- m_spinPeersMin.GetRange(lower, upper);
- m_pFileDBItem->m_lPeersMin = lower;
- }
- if (!m_pFileDBItem->m_bSpecialRunParameter)
- {
- //
- // upspeed.
- //
- m_pFileDBItem->m_lUploadSpeedMode = m_pSetupRegister->m_lDownSpeed;
- m_pFileDBItem->m_lUploadSpeedMax = CSpeedParameters::m_lArrSpeedVal[m_pSetupRegister->m_lDownSpeed];
- m_pFileDBItem->m_lUploadPeerMax = CSpeedParameters::m_lArrPeerVal[m_pSetupRegister->m_lDownSpeed];
- //
- // gerneral.
- //
- m_pFileDBItem->m_lPeersMin = m_pSetupRegister->m_lPeersMin;
- m_pFileDBItem->m_lPeersMax = m_pSetupRegister->m_lPeersMax;
- m_pFileDBItem->m_lConnectErrorMax = m_pSetupRegister->m_lConnectErrorMax;
- m_pFileDBItem->m_lConnectIntval = m_pSetupRegister->m_lConnectIntval;
- m_pFileDBItem->m_lCompleteKeepSeedHour = m_pSetupRegister->m_lCompleteKeepSeedHour;
- }
- ////////////////////////////////////////////
- // Implete change if item is running..
- if (m_pFileDBItem->m_pDownload &&
- m_pFileDBItem->m_pDownload->IsDownloading() &&
- !m_pFileDBItem->m_pDownload->IsBad() &&
- m_pFileDBItem->m_pDownload->CanSetRunParameters())
- {
- m_pFileDBItem->m_pDownload->SetRunParameters(
- m_pFileDBItem->m_lUploadSpeedMax,
- m_pFileDBItem->m_lUploadPeerMax,
- m_pFileDBItem->m_lCompleteKeepSeedHour,
- m_pFileDBItem->m_lConnectErrorMax,
- m_pFileDBItem->m_lConnectIntval,
- m_pFileDBItem->m_lPeersMin,
- m_pFileDBItem->m_lPeersMax);
- }
- CDialog::OnOK();
- }
- void CDlgRunParameters::OnSelchangeComboGlobalSetup()
- {
- UpdateCommandUI();
- }
- void CDlgRunParameters::UpdateCommandUI()
- {
- bool bSpecial = m_cbGlobalSetup.GetCurSel() != 0;
- m_cbDownSpeed.EnableWindow(bSpecial);
- //
- // upspeed
- //
- GetDlgItem(IDC_EDIT_UPLOAD_SPEED_MAX)->EnableWindow(bSpecial);
- GetDlgItem(IDC_EDIT_UPLOAD_PEERS_MAX)->EnableWindow(bSpecial);
- m_spinUploadSpeedMax.EnableWindow(bSpecial);
- m_spinUploadPeersMax.EnableWindow(bSpecial);
- m_sliderUploadSpeedMax.EnableWindow(bSpecial);
- m_sliderUploadPeersMax.EnableWindow(bSpecial);
- //
- // gerneral.
- //
- GetDlgItem(IDC_EDIT_COMPLETE_KEEP_SEED_HOUR)->EnableWindow(bSpecial);
- GetDlgItem(IDC_EDIT_PEERS_MIN_SPECIAL)->EnableWindow(bSpecial);
- GetDlgItem(IDC_EDIT_PEERS_MAX_SPECIAL)->EnableWindow(bSpecial);
- GetDlgItem(IDC_EDIT_CONNECT_ERR_MAX)->EnableWindow(bSpecial);
- GetDlgItem(IDC_EDIT_CONNECT_INTVAL)->EnableWindow(bSpecial);
- m_spinCompleteKeepSeedHour.EnableWindow(bSpecial);
- m_spinPeersMin.EnableWindow(bSpecial);
- m_spinPeersMax.EnableWindow(bSpecial);
- m_spinConnectErrMax.EnableWindow(bSpecial);
- m_spinConnectIntval.EnableWindow(bSpecial);
- // set parameter to global setup.
- if (!bSpecial)
- {
- //
- // upspeed
- //
- m_cbDownSpeed.SetCurSel(m_pSetupRegister->m_lDownSpeed);
- OnSelchangeComboDownSpeed();
- //
- // gerneral.
- //
- m_spinConnectErrMax.SetPos(m_pSetupRegister->m_lConnectErrorMax);
- m_spinConnectIntval.SetPos(m_pSetupRegister->m_lConnectIntval);
- m_spinCompleteKeepSeedHour.SetPos(m_pSetupRegister->m_lCompleteKeepSeedHour);
- m_spinPeersMin.SetPos(m_pSetupRegister->m_lPeersMin);
- m_spinPeersMax.SetPos(m_pSetupRegister->m_lPeersMax);
- }
- else
- {
- //
- // upspeed
- //
- m_cbDownSpeed.SetCurSel(m_pFileDBItem->m_lUploadSpeedMode);
- OnSelchangeComboDownSpeed();
- SetValue(m_pFileDBItem->m_lUploadSpeedMax, m_pFileDBItem->m_lUploadPeerMax);
- //
- // gerneral.
- //
- m_spinConnectErrMax.SetPos(m_pFileDBItem->m_lConnectErrorMax);
- m_spinConnectIntval.SetPos(m_pFileDBItem->m_lConnectIntval);
- m_spinCompleteKeepSeedHour.SetPos(m_pFileDBItem->m_lCompleteKeepSeedHour);
- m_spinPeersMin.SetPos(m_pFileDBItem->m_lPeersMin);
- m_spinPeersMax.SetPos(m_pFileDBItem->m_lPeersMax);
- }
- }
- void CDlgRunParameters::OnSelchangeComboDownSpeed()
- {
- long lCurSel = m_cbDownSpeed.GetCurSel();
- //
- // Set range.
- //
- m_spinUploadSpeedMax.SetRange(CSpeedParameters::m_lArrSpeedRange[lCurSel].cx,
- CSpeedParameters::m_lArrSpeedRange[lCurSel].cy);
- m_sliderUploadSpeedMax.SetRange(CSpeedParameters::m_lArrSpeedRange[lCurSel].cx,
- CSpeedParameters::m_lArrSpeedRange[lCurSel].cy, true);
- m_spinUploadPeersMax.SetRange(CSpeedParameters::m_lArrPeerRange[lCurSel].cx,
- CSpeedParameters::m_lArrPeerRange[lCurSel].cy);
- m_sliderUploadPeersMax.SetRange(CSpeedParameters::m_lArrPeerRange[lCurSel].cx,
- CSpeedParameters::m_lArrPeerRange[lCurSel].cy, true);
- // temp set their pos.
- m_sliderUploadSpeedMax.SetPos(CSpeedParameters::m_lArrSpeedRange[lCurSel].cx);
- m_sliderUploadPeersMax.SetPos(CSpeedParameters::m_lArrPeerRange[lCurSel].cx);
- // true set pos.
- SetValue(CSpeedParameters::m_lArrSpeedVal[lCurSel], CSpeedParameters::m_lArrPeerVal[lCurSel]);
- //
- // show text.
- //
- CString strText;
- strText.Format("%d", CSpeedParameters::m_lArrSpeedRange[lCurSel].cx);
- m_stSpeedMin.SetWindowText(strText);
- strText.Format("%d", CSpeedParameters::m_lArrSpeedRange[lCurSel].cy);
- m_stSpeedMax.SetWindowText(strText);
- strText.Format("%d", CSpeedParameters::m_lArrPeerRange[lCurSel].cx);
- m_stPeersMin.SetWindowText(strText);
- strText.Format("%d", CSpeedParameters::m_lArrPeerRange[lCurSel].cy);
- m_stPeersMax.SetWindowText(strText);
- }
- void CDlgRunParameters::SetValue(long lSpeedMax, long lPeersMax)
- {
- // m_sliderUploadSpeedMax.VerifyPos();
- // m_sliderUploadPeersMax.VerifyPos();
- m_sliderUploadSpeedMax.SetPos(lSpeedMax);
- m_spinUploadSpeedMax.SetPos(lSpeedMax);
- m_sliderUploadPeersMax.SetPos(lPeersMax);
- m_spinUploadPeersMax.SetPos(lPeersMax);
- #ifdef _DEBUG
- int lMin = 0, lMax = 0;
- m_sliderUploadSpeedMax.GetRange(lMin, lMax);
- ASSERT(lSpeedMax >= lMin && lSpeedMax <= lMax);
- int lSpeedMaxtrue = m_sliderUploadSpeedMax.GetPos();
- ASSERT(lSpeedMaxtrue == lSpeedMax);
- m_sliderUploadPeersMax.GetRange(lMin, lMax);
- ASSERT(lPeersMax >= lMin && lPeersMax <= lMax);
- int lPeersMaxtrue = m_spinUploadPeersMax.GetPos();
- ASSERT(lPeersMaxtrue == lPeersMax);
- #endif
- // m_sliderUploadSpeedMax.VerifyPos();
- // m_sliderUploadPeersMax.VerifyPos();
- }
- void CDlgRunParameters::OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
- {
- if (nSBCode == SB_ENDSCROLL)
- {
- if ((CSliderCtrl*)pScrollBar == &m_sliderUploadSpeedMax)
- {
- m_spinUploadSpeedMax.SetPos(m_sliderUploadSpeedMax.GetPos());
- }
- else if ((CSliderCtrl*)pScrollBar == &m_sliderUploadPeersMax)
- {
- m_spinUploadPeersMax.SetPos(m_sliderUploadPeersMax.GetPos());
- }
- }
- CDialog::OnHScroll(nSBCode, nPos, pScrollBar);
- }
- void CDlgRunParameters::OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
- {
- if (nSBCode == SB_ENDSCROLL)
- {
- if (pScrollBar == (CScrollBar *)&m_spinUploadSpeedMax)
- {
- long lPos = LOWORD(m_spinUploadSpeedMax.GetPos());
- m_sliderUploadSpeedMax.SetPos(lPos);
- #ifdef _DEBUG
- int lMin = 0, lMax = 0;
- m_sliderUploadSpeedMax.GetRange(lMin, lMax);
- ASSERT(lPos >= lMin && lPos <= lMax);
- #endif
- }
- else if (pScrollBar == (CScrollBar *)&m_spinUploadPeersMax)
- {
- long lPos = LOWORD(m_spinUploadPeersMax.GetPos());
- m_sliderUploadPeersMax.SetPos(lPos);
- #ifdef _DEBUG
- int lMin = 0, lMax = 0;
- m_sliderUploadPeersMax.GetRange(lMin, lMax);
- ASSERT(lPos >= lMin && lPos <= lMax);
- #endif
- }
- }
- CDialog::OnVScroll(nSBCode, nPos, pScrollBar);
- }
- void CDlgRunParameters::OnDeltaposSpinUploadSpeedMax(NMHDR* pNMHDR, LRESULT* pResult)
- {
- NM_UPDOWN* pNMUpDown = (NM_UPDOWN*)pNMHDR;
- *pResult = 0;
- // m_sliderUploadSpeedMax.SetPos(pNMUpDown->iPos);
- }
- void CDlgRunParameters::OnDeltaposSpinUploadPeersMax(NMHDR* pNMHDR, LRESULT* pResult)
- {
- NM_UPDOWN* pNMUpDown = (NM_UPDOWN*)pNMHDR;
- *pResult = 0;
- // m_sliderUploadPeersMax.SetPos(pNMUpDown->iPos);
- }
- long CDlgRunParameters::GetSpinValue(CSpinButtonCtrl& SpinCtrl)
- {
- long lPos = LOWORD(SpinCtrl.GetPos());
- int lower=0, upper=0;
- SpinCtrl.GetRange(lower, upper);
- if (lPos < 0)
- {
- lPos = upper;
- }
- else
- {
- lPos = max(lower, lPos);
- lPos = min(upper, lPos);
- }
- return lPos;
- }