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

对话框与窗口

开发平台:

Visual C++

  1. // PropertiesDialog.cpp : implementation file
  2. //
  3. // This file is a part of the XTREME TOOLKIT PRO MFC class library.
  4. // (c)1998-2008 Codejock Software, All Rights Reserved.
  5. //
  6. // THIS SOURCE FILE IS THE PROPERTY OF CODEJOCK SOFTWARE AND IS NOT TO BE
  7. // RE-DISTRIBUTED BY ANY MEANS WHATSOEVER WITHOUT THE EXPRESSED WRITTEN
  8. // CONSENT OF CODEJOCK SOFTWARE.
  9. //
  10. // THIS SOURCE CODE CAN ONLY BE USED UNDER THE TERMS AND CONDITIONS OUTLINED
  11. // IN THE XTREME TOOLKIT PRO LICENSE AGREEMENT. CODEJOCK SOFTWARE GRANTS TO
  12. // YOU (ONE SOFTWARE DEVELOPER) THE LIMITED RIGHT TO USE THIS SOFTWARE ON A
  13. // SINGLE COMPUTER.
  14. //
  15. // CONTACT INFORMATION:
  16. // support@codejock.com
  17. // http://www.codejock.com
  18. //
  19. /////////////////////////////////////////////////////////////////////////////
  20. #include "stdafx.h"
  21. #include "TrayIconDemo.h"
  22. #include "PropertiesDialog.h"
  23. #include "MainFrm.h"
  24. #ifdef _DEBUG
  25. #define new DEBUG_NEW
  26. #undef THIS_FILE
  27. static char THIS_FILE[] = __FILE__;
  28. #endif
  29. bool CPropertiesDialog::m_bMinimized = false;
  30. CPropertiesDialog *CPropertiesDialog::m_pInstance = NULL;
  31. /////////////////////////////////////////////////////////////////////////////
  32. // CPropertiesDialog dialog
  33. CPropertiesDialog::CPropertiesDialog(CWnd* pParentWnd /*=NULL*/)
  34. : CXTResizeDialog(CPropertiesDialog::IDD, pParentWnd)
  35. {
  36. //{{AFX_DATA_INIT(CPropertiesDialog)
  37. m_bAnimateIcon = FALSE;
  38. m_bHideIcon = FALSE;
  39. m_bShowIcon = TRUE;
  40. m_strBalloonMsg = _T("");
  41. m_strBalloonTitle = _T("");
  42. m_iTimeOut = 10;
  43. m_strToolTip = _T("Power Tools for MFC!");
  44. m_iBalloonIcon = 1;
  45. //}}AFX_DATA_INIT
  46. m_strBalloonMsg.LoadString(IDS_BALLOON_MESSAGE);
  47. m_strBalloonTitle.LoadString(IDS_BALLOON_TITLE);
  48. // Note that LoadIcon does not require a subsequent DestroyIcon in Win32
  49. m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
  50. m_pParentWnd = pParentWnd;
  51. m_pInstance = this;
  52. }
  53. void CPropertiesDialog::DoDataExchange(CDataExchange* pDX)
  54. {
  55. CXTResizeDialog::DoDataExchange(pDX);
  56. //{{AFX_DATA_MAP(CPropertiesDialog)
  57. DDX_Control(pDX, IDC_TEXT_INFO, m_txtInfo);
  58. DDX_Control(pDX, IDC_TXT_TOOLTIP, m_txtToolTip);
  59. DDX_Control(pDX, IDC_TXT_TIMEOUT, m_txtTimeOut);
  60. DDX_Control(pDX, IDC_TXT_BALLOONTITLE, m_txtBalloonTitle);
  61. DDX_Control(pDX, IDC_TXT_BALLOONMSG, m_txtBalloonMsg);
  62. DDX_Control(pDX, IDC_TXT_BALLOONICON, m_txtBalloonIcon);
  63. DDX_Control(pDX, IDC_EDIT_TOOLTIP, m_editTooltip);
  64. DDX_Control(pDX, IDC_EDIT_TIMEOUT, m_editTimeout);
  65. DDX_Control(pDX, IDC_EDIT_BALLOONTITLE, m_editBalloonTitle);
  66. DDX_Control(pDX, IDC_COMBO_BALLOONICON, m_comboBalloonIcon);
  67. DDX_Control(pDX, IDC_CHK_SHOWICON, m_chkShowIcon);
  68. DDX_Control(pDX, IDC_CHK_HIDEICON, m_chkHideIcon);
  69. DDX_Control(pDX, IDC_CHK_ANIMATEICON, m_chkAnimateIcon);
  70. DDX_Control(pDX, IDC_BTN_TOOLTIP, m_btnTooltip);
  71. DDX_Control(pDX, IDC_BTN_SHOWBALLOON, m_btnShowBalloon);
  72. DDX_Control(pDX, IDC_BTN_MINIMIZETRAY, m_btnMinimizeToTray);
  73. DDX_Control(pDX, IDC_TXT_BALLOONTIP, m_txtBalloonTip);
  74. DDX_Control(pDX, IDC_GBOX_BALLOONTIP, m_gboxBalloonTip);
  75. DDX_Check(pDX, IDC_CHK_ANIMATEICON, m_bAnimateIcon);
  76. DDX_Check(pDX, IDC_CHK_HIDEICON, m_bHideIcon);
  77. DDX_Check(pDX, IDC_CHK_SHOWICON, m_bShowIcon);
  78. DDX_Text(pDX, IDC_EDIT_BALLOONMSG, m_strBalloonMsg);
  79. DDV_MaxChars(pDX, m_strBalloonMsg, 255);
  80. DDX_Text(pDX, IDC_EDIT_BALLOONTITLE, m_strBalloonTitle);
  81. DDV_MaxChars(pDX, m_strBalloonTitle, 63);
  82. DDX_Text(pDX, IDC_EDIT_TIMEOUT, m_iTimeOut);
  83. DDV_MinMaxInt(pDX, m_iTimeOut, 10, 30);
  84. DDX_Text(pDX, IDC_EDIT_TOOLTIP, m_strToolTip);
  85. DDX_CBIndex(pDX, IDC_COMBO_BALLOONICON, m_iBalloonIcon);
  86. DDX_Control(pDX, IDC_EDIT_BALLOONMSG, m_editBalloonMsg);
  87. //}}AFX_DATA_MAP
  88. }
  89. BEGIN_MESSAGE_MAP(CPropertiesDialog, CXTResizeDialog)
  90. //{{AFX_MSG_MAP(CPropertiesDialog)
  91. ON_WM_DESTROY()
  92. ON_BN_CLICKED(IDC_CHK_SHOWICON, OnChkShowicon)
  93. ON_BN_CLICKED(IDC_CHK_HIDEICON, OnChkHideicon)
  94. ON_BN_CLICKED(IDC_CHK_ANIMATEICON, OnChkAnimateicon)
  95. ON_EN_CHANGE(IDC_EDIT_TOOLTIP, OnChangeEditTooltip)
  96. ON_BN_CLICKED(IDC_BTN_TOOLTIP, OnBtnTooltip)
  97. ON_EN_CHANGE(IDC_EDIT_BALLOONTITLE, OnChangeEditBalloontitle)
  98. ON_EN_CHANGE(IDC_EDIT_TIMEOUT, OnChangeEditTimeout)
  99. ON_EN_CHANGE(IDC_EDIT_BALLOONMSG, OnChangeEditBalloonmsg)
  100. ON_CBN_SELENDOK(IDC_COMBO_BALLOONICON, OnSelendokComboBalloonicon)
  101. ON_BN_CLICKED(IDC_BTN_SHOWBALLOON, OnBtnShowBalloon)
  102. ON_BN_CLICKED(IDC_BTN_MINIMIZETRAY, OnBtnMinimizetray)
  103. //}}AFX_MSG_MAP
  104. END_MESSAGE_MAP()
  105. /////////////////////////////////////////////////////////////////////////////
  106. // CPropertiesDialog message handlers
  107. BOOL CPropertiesDialog::OnInitDialog()
  108. {
  109. CXTResizeDialog::OnInitDialog();
  110. // Set the icon for this dialog.
  111. SetIcon(m_hIcon, TRUE);         // Set big icon
  112. SetIcon(m_hIcon, FALSE);        // Set small icon
  113. // Set control resizing.
  114. SetResize(IDC_EDIT_TOOLTIP,      SZ_TOP_LEFT,     SZ_TOP_RIGHT);
  115. SetResize(IDC_BTN_TOOLTIP,       SZ_TOP_RIGHT,    SZ_TOP_RIGHT);
  116. SetResize(IDC_BTN_MINIMIZETRAY,  SZ_TOP_RIGHT,    SZ_TOP_RIGHT);
  117. SetResize(IDOK,                  SZ_TOP_RIGHT,    SZ_TOP_RIGHT);
  118. SetResize(IDC_TEXT_INFO,         SZ_TOP_LEFT,     SZ_TOP_RIGHT);
  119. SetResize(IDC_GBOX_FEATURES,     SZ_TOP_LEFT,     SZ_TOP_RIGHT);
  120. SetResize(IDC_GBOX_BALLOONTIP,   SZ_TOP_LEFT,     SZ_TOP_RIGHT);
  121. SetResize(IDC_EDIT_BALLOONTITLE, SZ_TOP_LEFT,     SZ_TOP_RIGHT);
  122. SetResize(IDC_TXT_TIMEOUT,       SZ_TOP_RIGHT,    SZ_TOP_RIGHT);
  123. SetResize(IDC_EDIT_TIMEOUT,      SZ_TOP_RIGHT,    SZ_TOP_RIGHT);
  124. SetResize(IDC_EDIT_BALLOONMSG,   SZ_TOP_LEFT,     SZ_BOTTOM_RIGHT);
  125. SetResize(IDC_TXT_BALLOONICON,   SZ_BOTTOM_LEFT,  SZ_BOTTOM_LEFT);
  126. SetResize(IDC_COMBO_BALLOONICON, SZ_BOTTOM_LEFT,  SZ_BOTTOM_RIGHT);
  127. SetResize(IDC_BTN_SHOWBALLOON,   SZ_BOTTOM_RIGHT, SZ_BOTTOM_RIGHT);
  128. // Load window placement
  129. LoadPlacement(_T("CPropertiesDialog"));
  130. m_txtBalloonTip.SetFont(&XTAuxData().fontBold);
  131. EnableControls();
  132. // display the balloon tooltip.
  133. OnBtnShowBalloon();
  134. return TRUE;  // return TRUE unless you set the focus to a control
  135.               // EXCEPTION: OCX Property Pages should return FALSE
  136. }
  137. void CPropertiesDialog::OnDestroy()
  138. {
  139. // Save window placement
  140. SavePlacement(_T("CPropertiesDialog"));
  141. m_pInstance = NULL;
  142. CXTResizeDialog::OnDestroy();
  143. }
  144. void CPropertiesDialog::OnChkShowicon()
  145. {
  146. UpdateData();
  147. CMainFrame* pMainFrame = (CMainFrame*)AfxGetMainWnd();
  148. ASSERT_VALID(pMainFrame);
  149. if (m_bShowIcon) {
  150. pMainFrame->m_TrayIcon.AddIcon();
  151. }
  152. else {
  153. pMainFrame->m_TrayIcon.RemoveIcon();
  154. }
  155. }
  156. void CPropertiesDialog::OnChkHideicon()
  157. {
  158. UpdateData();
  159. CMainFrame* pMainFrame = (CMainFrame*)AfxGetMainWnd();
  160. ASSERT_VALID(pMainFrame);
  161. if (m_bHideIcon) {
  162. pMainFrame->m_TrayIcon.HideIcon();
  163. }
  164. else {
  165. pMainFrame->m_TrayIcon.ShowIcon();
  166. }
  167. }
  168. void CPropertiesDialog::OnChkAnimateicon()
  169. {
  170. UpdateData();
  171. CMainFrame* pMainFrame = (CMainFrame*)AfxGetMainWnd();
  172. ASSERT_VALID(pMainFrame);
  173. if (m_bAnimateIcon) {
  174. pMainFrame->m_TrayIcon.StartAnimation();
  175. }
  176. else {
  177. pMainFrame->m_TrayIcon.StopAnimation();
  178. }
  179. }
  180. void CPropertiesDialog::OnChangeEditTooltip()
  181. {
  182. UpdateData();
  183. }
  184. void CPropertiesDialog::OnBtnTooltip()
  185. {
  186. UpdateData();
  187. CMainFrame* pMainFrame = (CMainFrame*)AfxGetMainWnd();
  188. ASSERT_VALID(pMainFrame);
  189. pMainFrame->m_TrayIcon.SetTooltipText(m_strToolTip);
  190. }
  191. void CPropertiesDialog::OnChangeEditBalloontitle()
  192. {
  193. UpdateData();
  194. }
  195. void CPropertiesDialog::OnChangeEditTimeout()
  196. {
  197. }
  198. void CPropertiesDialog::OnChangeEditBalloonmsg()
  199. {
  200. UpdateData();
  201. }
  202. void CPropertiesDialog::OnSelendokComboBalloonicon()
  203. {
  204. UpdateData();
  205. }
  206. UINT balloonIcon[] =
  207. {
  208. NIIF_ERROR,  // Error icon.
  209. NIIF_INFO,   // Information icon.
  210. NIIF_NONE,   // No icon.
  211. NIIF_WARNING // Warning icon.
  212. };
  213. void CPropertiesDialog::OnBtnShowBalloon()
  214. {
  215. if (!UpdateData())
  216. return;
  217. CMainFrame* pMainFrame = (CMainFrame*)AfxGetMainWnd();
  218. ASSERT_VALID(pMainFrame);
  219. pMainFrame->m_TrayIcon.ShowBalloonTip(m_strBalloonMsg, m_strBalloonTitle,
  220. balloonIcon[m_iBalloonIcon], m_iTimeOut);
  221. }
  222. void CPropertiesDialog::MinMaxWindow()
  223. {
  224. CMainFrame* pMainFrame = (CMainFrame*)AfxGetMainWnd();
  225. ASSERT_VALID(pMainFrame);
  226. m_bMinimized = !m_bMinimized;
  227. if (m_bMinimized)
  228. {
  229. pMainFrame->m_TrayIcon.MinimizeToTray(pMainFrame);
  230. if (m_pInstance)
  231. {
  232. m_pInstance->m_btnMinimizeToTray.SetWindowText(
  233. _T("&Maximize from Tray..."));
  234. }
  235. }
  236. else
  237. {
  238. pMainFrame->m_TrayIcon.MaximizeFromTray(pMainFrame);
  239. if (m_pInstance)
  240. {
  241. m_pInstance->m_btnMinimizeToTray.SetWindowText(_T("&Minimize to Tray..."));
  242. }
  243. }
  244. }
  245. void CPropertiesDialog::OnBtnMinimizetray()
  246. {
  247. MinMaxWindow();
  248. }
  249. void CPropertiesDialog::EnableControls()
  250. {
  251. CMainFrame* pMainFrame = (CMainFrame*)AfxGetMainWnd();
  252. BOOL bEnable = pMainFrame->m_TrayIcon.IsShellVersion5();
  253. // Requirements:
  254. // Windows 2000 or later, VC6 with platform SDK or
  255. // later to use these features.
  256. m_chkHideIcon.      EnableWindow(bEnable);
  257. m_txtBalloonTip.    EnableWindow(bEnable);
  258. m_txtBalloonTitle.  EnableWindow(bEnable);
  259. m_editBalloonTitle. EnableWindow(bEnable);
  260. m_txtTimeOut.       EnableWindow(bEnable);
  261. m_editTimeout.      EnableWindow(bEnable);
  262. m_txtBalloonMsg.    EnableWindow(bEnable);
  263. m_editBalloonMsg.   EnableWindow(bEnable);
  264. m_txtBalloonIcon.   EnableWindow(bEnable);
  265. m_comboBalloonIcon. EnableWindow(bEnable);
  266. m_btnShowBalloon.   EnableWindow(bEnable);
  267. m_editBalloonMsg.SetBackColor(bEnable ?
  268. GetXtremeColor(COLOR_WINDOW) : GetXtremeColor(COLOR_3DFACE));
  269. }
  270. INT_PTR CPropertiesDialog::DoModal(CWnd* pParentWnd)
  271. {
  272. m_pParentWnd = pParentWnd;
  273. return CXTResizeDialog::DoModal();
  274. }