TaskPageIcons.cpp
上传用户:szled88
上传日期:2015-04-09
资源大小:43957k
文件大小:5k
源码类别:

对话框与窗口

开发平台:

Visual C++

  1. // TaskPageIcons.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "VistaTaskDialog.h"
  5. #include "TaskSheetProperties.h"
  6. #include "TaskPageIcons.h"
  7. #ifdef _DEBUG
  8. #define new DEBUG_NEW
  9. #undef THIS_FILE
  10. static char THIS_FILE[] = __FILE__;
  11. #endif
  12. /////////////////////////////////////////////////////////////////////////////
  13. // CTaskPageIcons property page
  14. IMPLEMENT_DYNCREATE(CTaskPageIcons, CPropertyPage)
  15. CTaskPageIcons::CTaskPageIcons() : CPropertyPage(CTaskPageIcons::IDD)
  16. {
  17. //{{AFX_DATA_INIT(CTaskPageIcons)
  18. m_nFootIcon = 4;
  19. m_nMainIcon = 2;
  20. m_strFootPath = _T("");
  21. m_strMainPath = _T("");
  22. m_bSysIcons = TRUE;
  23. //}}AFX_DATA_INIT
  24. m_hMainIcon = 0;
  25. m_hFootIcon = 0;
  26. }
  27. CTaskPageIcons::~CTaskPageIcons()
  28. {
  29. SAFE_DELETE_HICON(m_hMainIcon);
  30. SAFE_DELETE_HICON(m_hFootIcon);
  31. }
  32. void CTaskPageIcons::DoDataExchange(CDataExchange* pDX)
  33. {
  34. CPropertyPage::DoDataExchange(pDX);
  35. //{{AFX_DATA_MAP(CTaskPageIcons)
  36. DDX_Control(pDX, IDC_COMBO_MAINICON, m_comboMainIcon);
  37. DDX_Control(pDX, IDC_COMBO_FOOTICON, m_comboFootIcon);
  38. DDX_CBIndex(pDX, IDC_COMBO_FOOTICON, m_nFootIcon);
  39. DDX_CBIndex(pDX, IDC_COMBO_MAINICON, m_nMainIcon);
  40. DDX_Text(pDX, IDC_EDIT_FOOTPATH, m_strFootPath);
  41. DDX_Text(pDX, IDC_EDIT_MAINPATH, m_strMainPath);
  42. DDX_Check(pDX, IDC_CHK_SYSICON, m_bSysIcons);
  43. DDX_Control(pDX, IDC_CHK_SYSICON, m_chkSysIcon);
  44. //}}AFX_DATA_MAP
  45. }
  46. BEGIN_MESSAGE_MAP(CTaskPageIcons, CPropertyPage)
  47. //{{AFX_MSG_MAP(CTaskPageIcons)
  48. ON_CBN_SELENDOK(IDC_COMBO_MAINICON, OnSelEndOkMainIcon)
  49. ON_EN_CHANGE(IDC_EDIT_MAINPATH, OnEditChangeMainPath)
  50. ON_BN_CLICKED(IDC_BTN_MAINPATH, OnBtnMainPath)
  51. ON_CBN_SELENDOK(IDC_COMBO_FOOTICON, OnSelEndOkFootIcon)
  52. ON_EN_CHANGE(IDC_EDIT_FOOTPATH, OnEditChangeFootPath)
  53. ON_BN_CLICKED(IDC_BTN_FOOTPATH, OnBtnFootPath)
  54. ON_BN_CLICKED(IDC_CHK_SYSICON, OnChkSysIcon)
  55. //}}AFX_MSG_MAP
  56. END_MESSAGE_MAP()
  57. /////////////////////////////////////////////////////////////////////////////
  58. // CTaskPageIcons message handlers
  59. void CTaskPageIcons::OnSelEndOkMainIcon()
  60. {
  61. UpdateData();
  62. SAFE_DELETE_HICON(m_hMainIcon);
  63. m_strMainPath.Empty();
  64. UpdateData(FALSE);
  65. }
  66. void CTaskPageIcons::OnEditChangeMainPath()
  67. {
  68. UpdateData();
  69. if (FILEEXISTS_S(m_strMainPath))
  70. {
  71. SAFE_DELETE_HICON(m_hMainIcon);
  72. m_hMainIcon = (HICON)::LoadImage(NULL, m_strMainPath, IMAGE_ICON,
  73. ::GetSystemMetrics(SM_CXICON), ::GetSystemMetrics(SM_CYICON), LR_LOADFROMFILE);
  74. m_nMainIcon = 0;
  75. m_comboMainIcon.SetCurSel(m_nMainIcon);
  76. }
  77. }
  78. void CTaskPageIcons::OnSelEndOkFootIcon()
  79. {
  80. UpdateData();
  81. SAFE_DELETE_HICON(m_hFootIcon);
  82. m_strFootPath.Empty();
  83. UpdateData(FALSE);
  84. }
  85. void CTaskPageIcons::OnEditChangeFootPath()
  86. {
  87. UpdateData();
  88. if (FILEEXISTS_S(m_strFootPath))
  89. {
  90. SAFE_DELETE_HICON(m_hFootIcon);
  91. m_hFootIcon = (HICON)::LoadImage(NULL, m_strFootPath, IMAGE_ICON,
  92. ::GetSystemMetrics(SM_CXSMICON), ::GetSystemMetrics(SM_CYSMICON), LR_LOADFROMFILE);
  93. m_nFootIcon = 0;
  94. m_comboFootIcon.SetCurSel(m_nFootIcon);
  95. }
  96. }
  97. void CTaskPageIcons::OnBtnMainPath() 
  98. {
  99. CString strFilter = _T("Icon Files|*.ico||All files (*.*)|*.*||");
  100. CFileDialog dlg(TRUE, _T("ico"), NULL,
  101. OFN_HIDEREADONLY | OFN_FILEMUSTEXIST | OFN_EXPLORER, strFilter, this);
  102. if (dlg.DoModal() == IDOK)
  103. {
  104. m_strMainPath = dlg.GetPathName();
  105. UpdateData(FALSE);
  106. OnEditChangeMainPath();
  107. }
  108. }
  109. void CTaskPageIcons::OnBtnFootPath() 
  110. {
  111. CString strFilter = _T("Icon Files|*.ico||All files (*.*)|*.*||");
  112. CFileDialog dlg(TRUE, _T("ico"), NULL,
  113. OFN_HIDEREADONLY | OFN_FILEMUSTEXIST | OFN_EXPLORER, strFilter, this);
  114. if (dlg.DoModal() == IDOK)
  115. {
  116. m_strFootPath = dlg.GetPathName();
  117. UpdateData(FALSE);
  118. OnEditChangeFootPath();
  119. }
  120. }
  121. void CTaskPageIcons::OnChkSysIcon() 
  122. {
  123. UpdateData();
  124. }
  125. static const TCHAR* TASKICON[5][2] = 
  126. {
  127. { (TCHAR*)NULL, _T("None") },
  128. { (TCHAR*)TD_ERROR_ICON, _T("Error Icon") },
  129. { (TCHAR*)TD_WARNING_ICON, _T("Warning Icon") },
  130. { (TCHAR*)TD_INFORMATION_ICON, _T("Information Icon") },
  131. { (TCHAR*)TD_SHIELD_ICON, _T("Shield Icon") }
  132. };
  133. BOOL CTaskPageIcons::OnInitDialog() 
  134. {
  135. CPropertyPage::OnInitDialog();
  136. // TODO: Add extra initialization here
  137. m_pDlgParent = DYNAMIC_DOWNCAST(CTaskSheetProperties, GetParent());
  138. ASSERT_VALID(m_pDlgParent);
  139. for (int i = 0; i < 5; ++i)
  140. {
  141. m_comboMainIcon.SetItemData(
  142. m_comboMainIcon.AddString(TASKICON[i][1]), (DWORD_PTR)TASKICON[i][0]);
  143. m_comboFootIcon.SetItemData(
  144. m_comboFootIcon.AddString(TASKICON[i][1]), (DWORD_PTR)TASKICON[i][0]);
  145. }
  146. UpdateData(FALSE);
  147. //m_comboMainIcon.SetCurSel(4);
  148. //m_comboFootIcon.SetCurSel(3);
  149. return TRUE;  // return TRUE unless you set the focus to a control
  150.               // EXCEPTION: OCX Property Pages should return FALSE
  151. }
  152. BOOL CTaskPageIcons::OnSetActive()
  153. {
  154. if (!CPropertyPage::OnSetActive())
  155. return FALSE;
  156. if (m_pDlgParent)
  157. {
  158. m_chkSysIcon.EnableWindow(!m_pDlgParent->UsingComCtl32());
  159. }
  160. return TRUE;
  161. }