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

P2P编程

开发平台:

Visual C++

  1. // DlgSetup.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "testbt.h"
  5. #include "DlgSetup.h"
  6. #include "SetupRegister.h"
  7. #ifdef _DEBUG
  8. #define new DEBUG_NEW
  9. #undef THIS_FILE
  10. static char THIS_FILE[] = __FILE__;
  11. #endif
  12. /////////////////////////////////////////////////////////////////////////////
  13. // CDlgSetup dialog
  14. CDlgSetup::CDlgSetup(CSetupRegister* pSetupRegister, CWnd* pParent /*=NULL*/)
  15. : CDialog(CDlgSetup::IDD, pParent)
  16. {
  17. //{{AFX_DATA_INIT(CDlgSetup)
  18. // NOTE: the ClassWizard will add member initialization here
  19. //}}AFX_DATA_INIT
  20. m_pSetupRegister = pSetupRegister;
  21. assert(m_pSetupRegister);
  22. m_vstrOptions[eBase] = "常规设置";
  23. m_vstrOptions[eHotkey] = "用户界面设置";
  24. m_vstrOptions[eDownloadSetup] = "下载基本设置";
  25. m_vstrOptions[eAdvanced] = "下载高级选项";
  26. m_strComment[eBase] = "常规设置";
  27. m_strComment[eHotkey] = "用户界面设置";
  28. m_strComment[eDownloadSetup] = "下载基本设置";
  29. m_strComment[eAdvanced] = "下载高级选项 : 请谨慎改变这些设置";
  30. }
  31. void CDlgSetup::DoDataExchange(CDataExchange* pDX)
  32. {
  33. CDialog::DoDataExchange(pDX);
  34. //{{AFX_DATA_MAP(CDlgSetup)
  35. DDX_Control(pDX, IDCANCEL, m_btnCancel);
  36. DDX_Control(pDX, IDOK, m_btnOK);
  37. DDX_Control(pDX, IDC_TREE_OPTIONS, m_treeOptions);
  38. //}}AFX_DATA_MAP
  39. }
  40. BEGIN_MESSAGE_MAP(CDlgSetup, CDialog)
  41. //{{AFX_MSG_MAP(CDlgSetup)
  42. ON_NOTIFY(TVN_SELCHANGED, IDC_TREE_OPTIONS, OnSelchangedTreeOptions)
  43. ON_WM_DESTROY()
  44. //}}AFX_MSG_MAP
  45. END_MESSAGE_MAP()
  46. /////////////////////////////////////////////////////////////////////////////
  47. // CDlgSetup message handlers
  48. BOOL CDlgSetup::OnInitDialog() 
  49. {
  50. CDialog::OnInitDialog();
  51. //
  52. // Create BitmapList
  53. //
  54. HBITMAP hbm = (HBITMAP)::LoadImage(AfxGetInstanceHandle(),
  55. MAKEINTRESOURCE(IDB_BITMAP_DLG_ICONS),
  56. IMAGE_BITMAP,
  57. 0,0, // cx,cy
  58. LR_CREATEDIBSECTION); // | LR_LOADMAP3DCOLORS );
  59. CBitmap bm;
  60. bm.Attach(hbm);
  61. m_ctlImage.Create(16,15, ILC_COLOR8|ILC_MASK, 3, 4);
  62. m_ctlImage.SetBkColor(RGB(255, 255,255)); 
  63. m_ctlImage.Add(&bm, (COLORREF)RGB(255,0,255));
  64. //
  65. // set button image.
  66. //
  67. // m_btnBrowseDir.Create(m_ctlImage.ExtractIcon(2), true, "选择保存路径");
  68. m_btnOK.Create(m_ctlImage.ExtractIcon(0));
  69. m_btnCancel.Create(m_ctlImage.ExtractIcon(1));
  70. //
  71. //
  72. //
  73. CTreeCursor root = m_treeOptions.GetRootItem();
  74. for (int i=0; i<eAllCount; i++)
  75. {
  76. CTreeCursor cur = root.AddTail(m_vstrOptions[i]);
  77. }
  78. m_StatusWnd.CreateEx(this, CRect(0, 0, 100, 100), 5362, 0);
  79. // dlgAdvanced.
  80. m_dlgAdvanced.Create(IDD_DIALOG_ADVANCED_PAGE, this);
  81. m_dlgAdvanced.SetData(m_pSetupRegister);
  82. // dlgSystem.
  83. m_dlgSystem.Create(IDD_DIALOG_SYSTEM_PAGE, this);
  84. m_dlgSystem.SetData(m_pSetupRegister);
  85. // dlgOptions.
  86. m_dlgOptions.Create(IDD_DIALOG_OPTIONS, this);
  87. m_dlgOptions.SetData(m_pSetupRegister);
  88. m_dlgDownloadSetup.Create(IDD_DIALOG_DOWNLOAD_SETUP, this);
  89. m_dlgDownloadSetup.SetData(m_pSetupRegister);
  90. // set position.
  91. CRect rc;
  92. GetClientRect(&rc);
  93. CRect rcStatus;
  94. rcStatus = rc;
  95. rcStatus.bottom = rcStatus.top + 45;
  96. rc.top += 55;
  97. rc.bottom -= 10;
  98. CRect rcTree = rc;
  99. rcTree.right = rcTree.left + 140;
  100. rc.left += 140;
  101. rc.bottom -= 30;
  102. // rc.DeflateRect(10, 10);
  103. m_StatusWnd.MoveWindow(rcStatus);
  104. m_treeOptions.MoveWindow(rcTree);
  105. m_dlgOptions.MoveWindow(rc);
  106. m_dlgSystem.MoveWindow(rc);
  107. m_dlgAdvanced.MoveWindow(rc);
  108. m_dlgDownloadSetup.MoveWindow(rc);
  109. // set cur page.
  110. SetData();
  111. return TRUE;  // return TRUE unless you set the focus to a control
  112.               // EXCEPTION: OCX Property Pages should return FALSE
  113. }
  114. void CDlgSetup::OnSelchangedTreeOptions(NMHDR* pNMHDR, LRESULT* pResult) 
  115. {
  116. NM_TREEVIEW* pNMTreeView = (NM_TREEVIEW*)pNMHDR;
  117. OnCommandUI();
  118. *pResult = 0;
  119. }
  120. void CDlgSetup::OnCommandUI()
  121. {
  122. CTreeCursor curSel = m_treeOptions.GetSelectedItem();
  123. if (!curSel)
  124. {
  125. assert(curSel);
  126. return;
  127. }
  128. eSetupCate ecate = eBase;
  129. CString strCurText = curSel.GetText();
  130. if (strCurText == m_vstrOptions[eBase])
  131. {
  132. ecate = eBase;
  133. }
  134. else if (strCurText == m_vstrOptions[eHotkey])
  135. {
  136. ecate = eHotkey;
  137. }
  138. else if (strCurText == m_vstrOptions[eAdvanced])
  139. {
  140. ecate = eAdvanced;
  141. }
  142. else if (strCurText == m_vstrOptions[eDownloadSetup])
  143. {
  144. ecate = eDownloadSetup;
  145. }
  146. m_dlgSystem.ShowWindow(curSel.GetText() == m_vstrOptions[eBase]);
  147. m_dlgOptions.ShowWindow(curSel.GetText() == m_vstrOptions[eHotkey]);
  148. m_dlgAdvanced.ShowWindow(curSel.GetText() == m_vstrOptions[eAdvanced]);
  149. m_dlgDownloadSetup.ShowWindow(curSel.GetText() == m_vstrOptions[eDownloadSetup]);
  150. m_StatusWnd.SetStatusText(m_strComment[ecate]);
  151. }
  152. void CDlgSetup::OnOK()
  153. {
  154. if (!m_dlgOptions.Apply())
  155. return;
  156. if (!m_dlgSystem.Apply())
  157. return;
  158. if (!m_dlgAdvanced.Apply())
  159. return;
  160. if (!m_dlgDownloadSetup.Apply())
  161. return;
  162. m_dlgOptions.GetData(m_pSetupRegister);
  163. m_dlgSystem.GetData(m_pSetupRegister);
  164. m_dlgAdvanced.GetData(m_pSetupRegister);
  165. m_dlgDownloadSetup.GetData(m_pSetupRegister);
  166. CDialog::OnOK();
  167. }
  168. void CDlgSetup::OnDestroy() 
  169. {
  170. CDialog::OnDestroy();
  171. GetData();
  172. }
  173. void CDlgSetup::SetData()
  174. {
  175. CTreeCursor cur = m_treeOptions.GetRootItem();
  176. for (int i=0; i<eAllCount; i++)
  177. {
  178. if (!cur) break;
  179. if (i == m_pSetupRegister->m_lSetupPage)
  180. {
  181. cur.Select();
  182. break;
  183. }
  184. cur = cur.GetNext(TVGN_NEXT);
  185. }
  186. if (eAllCount == i)
  187. m_treeOptions.GetRootItem().Select();
  188. }
  189. void CDlgSetup::GetData()
  190. {
  191. // save cur page.
  192. CTreeCursor curSel = m_treeOptions.GetSelectedItem();
  193. if (!curSel)
  194. {
  195. m_pSetupRegister->m_lSetupPage = 0;
  196. return;
  197. }
  198. for (int i=0; i<eAllCount; i++)
  199. {
  200. if (curSel.GetText() == m_vstrOptions[i])
  201. {
  202. m_pSetupRegister->m_lSetupPage = i;
  203. break;
  204. }
  205. }
  206. }