Leaked source code of windows server 2003
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.

95 lines
1.9 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 +1];
  59. lstrcpyn(tszApp, pszApp, MAX_PATH);
  60. tszApp[MAX_PATH] = L'\0';
  61. DeleteQuotes(tszApp);
  62. HICON hiconExtracted = (HICON) UlongToHandle(TS_ExtractIconEx(tszApp, 0, &hiconApp, 1, GetSystemMetrics(SM_CXICON)));
  63. if (hiconExtracted == NULL || hiconApp == NULL)
  64. {
  65. hiconApp = GetDefaultAppIcon(GetSystemMetrics(SM_CXICON));
  66. }
  67. }
  68. inline
  69. void
  70. CIconHelper::SetJobIcon(
  71. BOOL fEnabled)
  72. {
  73. if (hiconJob != NULL)
  74. {
  75. DestroyIcon(hiconJob);
  76. }
  77. hiconJob = JobIcon.OverlayStateIcon(hiconApp, fEnabled, GetSystemMetrics(SM_CXICON));
  78. }
  79. #endif // _ICONHLPR_HXX__