DlgSetup.cpp
资源名称:GGBT.rar [点击查看]
上传用户:lds876
上传日期:2013-05-25
资源大小:567k
文件大小:6k
源码类别:
P2P编程
开发平台:
Visual C++
- // DlgSetup.cpp : implementation file
- //
- #include "stdafx.h"
- #include "testbt.h"
- #include "DlgSetup.h"
- #include "SetupRegister.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- /////////////////////////////////////////////////////////////////////////////
- // CDlgSetup dialog
- CDlgSetup::CDlgSetup(CSetupRegister* pSetupRegister, CWnd* pParent /*=NULL*/)
- : CDialog(CDlgSetup::IDD, pParent)
- {
- //{{AFX_DATA_INIT(CDlgSetup)
- // NOTE: the ClassWizard will add member initialization here
- //}}AFX_DATA_INIT
- m_pSetupRegister = pSetupRegister;
- assert(m_pSetupRegister);
- m_vstrOptions[eBase] = "常规设置";
- m_vstrOptions[eHotkey] = "用户界面设置";
- m_vstrOptions[eDownloadSetup] = "下载基本设置";
- m_vstrOptions[eAdvanced] = "下载高级选项";
- m_strComment[eBase] = "常规设置";
- m_strComment[eHotkey] = "用户界面设置";
- m_strComment[eDownloadSetup] = "下载基本设置";
- m_strComment[eAdvanced] = "下载高级选项 : 请谨慎改变这些设置";
- }
- void CDlgSetup::DoDataExchange(CDataExchange* pDX)
- {
- CDialog::DoDataExchange(pDX);
- //{{AFX_DATA_MAP(CDlgSetup)
- DDX_Control(pDX, IDCANCEL, m_btnCancel);
- DDX_Control(pDX, IDOK, m_btnOK);
- DDX_Control(pDX, IDC_TREE_OPTIONS, m_treeOptions);
- //}}AFX_DATA_MAP
- }
- BEGIN_MESSAGE_MAP(CDlgSetup, CDialog)
- //{{AFX_MSG_MAP(CDlgSetup)
- ON_NOTIFY(TVN_SELCHANGED, IDC_TREE_OPTIONS, OnSelchangedTreeOptions)
- ON_WM_DESTROY()
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- // CDlgSetup message handlers
- BOOL CDlgSetup::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));
- //
- //
- //
- CTreeCursor root = m_treeOptions.GetRootItem();
- for (int i=0; i<eAllCount; i++)
- {
- CTreeCursor cur = root.AddTail(m_vstrOptions[i]);
- }
- m_StatusWnd.CreateEx(this, CRect(0, 0, 100, 100), 5362, 0);
- // dlgAdvanced.
- m_dlgAdvanced.Create(IDD_DIALOG_ADVANCED_PAGE, this);
- m_dlgAdvanced.SetData(m_pSetupRegister);
- // dlgSystem.
- m_dlgSystem.Create(IDD_DIALOG_SYSTEM_PAGE, this);
- m_dlgSystem.SetData(m_pSetupRegister);
- // dlgOptions.
- m_dlgOptions.Create(IDD_DIALOG_OPTIONS, this);
- m_dlgOptions.SetData(m_pSetupRegister);
- m_dlgDownloadSetup.Create(IDD_DIALOG_DOWNLOAD_SETUP, this);
- m_dlgDownloadSetup.SetData(m_pSetupRegister);
- // set position.
- CRect rc;
- GetClientRect(&rc);
- CRect rcStatus;
- rcStatus = rc;
- rcStatus.bottom = rcStatus.top + 45;
- rc.top += 55;
- rc.bottom -= 10;
- CRect rcTree = rc;
- rcTree.right = rcTree.left + 140;
- rc.left += 140;
- rc.bottom -= 30;
- // rc.DeflateRect(10, 10);
- m_StatusWnd.MoveWindow(rcStatus);
- m_treeOptions.MoveWindow(rcTree);
- m_dlgOptions.MoveWindow(rc);
- m_dlgSystem.MoveWindow(rc);
- m_dlgAdvanced.MoveWindow(rc);
- m_dlgDownloadSetup.MoveWindow(rc);
- // set cur page.
- SetData();
- return TRUE; // return TRUE unless you set the focus to a control
- // EXCEPTION: OCX Property Pages should return FALSE
- }
- void CDlgSetup::OnSelchangedTreeOptions(NMHDR* pNMHDR, LRESULT* pResult)
- {
- NM_TREEVIEW* pNMTreeView = (NM_TREEVIEW*)pNMHDR;
- OnCommandUI();
- *pResult = 0;
- }
- void CDlgSetup::OnCommandUI()
- {
- CTreeCursor curSel = m_treeOptions.GetSelectedItem();
- if (!curSel)
- {
- assert(curSel);
- return;
- }
- eSetupCate ecate = eBase;
- CString strCurText = curSel.GetText();
- if (strCurText == m_vstrOptions[eBase])
- {
- ecate = eBase;
- }
- else if (strCurText == m_vstrOptions[eHotkey])
- {
- ecate = eHotkey;
- }
- else if (strCurText == m_vstrOptions[eAdvanced])
- {
- ecate = eAdvanced;
- }
- else if (strCurText == m_vstrOptions[eDownloadSetup])
- {
- ecate = eDownloadSetup;
- }
- m_dlgSystem.ShowWindow(curSel.GetText() == m_vstrOptions[eBase]);
- m_dlgOptions.ShowWindow(curSel.GetText() == m_vstrOptions[eHotkey]);
- m_dlgAdvanced.ShowWindow(curSel.GetText() == m_vstrOptions[eAdvanced]);
- m_dlgDownloadSetup.ShowWindow(curSel.GetText() == m_vstrOptions[eDownloadSetup]);
- m_StatusWnd.SetStatusText(m_strComment[ecate]);
- }
- void CDlgSetup::OnOK()
- {
- if (!m_dlgOptions.Apply())
- return;
- if (!m_dlgSystem.Apply())
- return;
- if (!m_dlgAdvanced.Apply())
- return;
- if (!m_dlgDownloadSetup.Apply())
- return;
- m_dlgOptions.GetData(m_pSetupRegister);
- m_dlgSystem.GetData(m_pSetupRegister);
- m_dlgAdvanced.GetData(m_pSetupRegister);
- m_dlgDownloadSetup.GetData(m_pSetupRegister);
- CDialog::OnOK();
- }
- void CDlgSetup::OnDestroy()
- {
- CDialog::OnDestroy();
- GetData();
- }
- void CDlgSetup::SetData()
- {
- CTreeCursor cur = m_treeOptions.GetRootItem();
- for (int i=0; i<eAllCount; i++)
- {
- if (!cur) break;
- if (i == m_pSetupRegister->m_lSetupPage)
- {
- cur.Select();
- break;
- }
- cur = cur.GetNext(TVGN_NEXT);
- }
- if (eAllCount == i)
- m_treeOptions.GetRootItem().Select();
- }
- void CDlgSetup::GetData()
- {
- // save cur page.
- CTreeCursor curSel = m_treeOptions.GetSelectedItem();
- if (!curSel)
- {
- m_pSetupRegister->m_lSetupPage = 0;
- return;
- }
- for (int i=0; i<eAllCount; i++)
- {
- if (curSel.GetText() == m_vstrOptions[i])
- {
- m_pSetupRegister->m_lSetupPage = i;
- break;
- }
- }
- }