Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

93 lines
1.7 KiB

  1. #ifndef _ICONHLPR_HXX__
  2. #define _ICONHLPR_HXX__
  3. //____________________________________________________________________________
  4. //
  5. // Class: CIconHelper
  6. //
  7. // Purpose: A simple helper to handle icons for Task & Schedule pages.
  8. //
  9. // Interface: SetAppIcon - sets the application icon.
  10. // SetJobIcon - sets the task icon.
  11. //
  12. // History: 6/26/1996 RaviR Created
  13. //____________________________________________________________________________
  14. class CIconHelper
  15. {
  16. public:
  17. CIconHelper();
  18. ~CIconHelper();
  19. void AddRef(void) { ++cRef; }
  20. void Release(void) { --cRef; if (cRef == 0) delete this; }
  21. void SetAppIcon(LPTSTR pszApp);
  22. void SetJobIcon(BOOL fEnabled);
  23. ULONG cRef;
  24. CJobIcon JobIcon;
  25. HICON hiconApp;
  26. HICON hiconJob;
  27. };
  28. inline
  29. CIconHelper::CIconHelper()
  30. :
  31. JobIcon(),
  32. cRef(1),
  33. hiconApp(NULL),
  34. hiconJob(NULL)
  35. {
  36. }
  37. inline
  38. CIconHelper::~CIconHelper()
  39. {
  40. if (hiconApp != NULL)
  41. {
  42. DestroyIcon(hiconApp);
  43. }
  44. if (hiconJob != NULL)
  45. {
  46. DestroyIcon(hiconJob);
  47. }
  48. }
  49. inline
  50. void
  51. CIconHelper::SetAppIcon(
  52. LPTSTR pszApp)
  53. {
  54. if (hiconApp != NULL)
  55. {
  56. DestroyIcon(hiconApp);
  57. }
  58. TCHAR tszApp[MAX_PATH];
  59. lstrcpyn(tszApp, pszApp, MAX_PATH);
  60. DeleteQuotes(tszApp);
  61. HICON hiconExtracted = (HICON) UlongToHandle(ExtractIconEx(tszApp, 0, &hiconApp, NULL, 1));
  62. if (hiconExtracted == NULL || hiconApp == NULL)
  63. {
  64. hiconApp = GetDefaultAppIcon(TRUE);
  65. }
  66. }
  67. inline
  68. void
  69. CIconHelper::SetJobIcon(
  70. BOOL fEnabled)
  71. {
  72. if (hiconJob != NULL)
  73. {
  74. DestroyIcon(hiconJob);
  75. }
  76. hiconJob = JobIcon.OverlayStateIcon(hiconApp, fEnabled);
  77. }
  78. #endif // _ICONHLPR_HXX__