home *** CD-ROM | disk | FTP | other *** search
/ C Programming Starter Kit 2.0 / SamsPublishing-CProgrammingStarterKit-v2.0-Win31.iso / bc45 / owlsrc.pak / ICON.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1997-07-24  |  2.0 KB  |  79 lines

  1. //----------------------------------------------------------------------------
  2. // ObjectWindows
  3. // (C) Copyright 1992, 1994 by Borland International, All Rights Reserved
  4. //
  5. //   Implementation of TIcons, GDI Icon object class
  6. //----------------------------------------------------------------------------
  7. #include <owl/owlpch.h>
  8. #include <owl/gdiobjec.h>
  9.  
  10. DIAG_DECLARE_GROUP(OwlGDI);        // General GDI diagnostic group
  11.  
  12. TIcon::TIcon(HICON handle, TAutoDelete autoDelete)
  13. :
  14.   TGdiBase(handle, autoDelete)
  15. {
  16. }
  17.  
  18. #if defined(BI_PLAT_WIN32)
  19. TIcon::TIcon(HINSTANCE, const TIcon& icon)
  20. {
  21.   Handle = ::CopyIcon(icon);
  22.   CheckValid();
  23. }
  24. #else
  25. TIcon::TIcon(HINSTANCE instance, const TIcon& icon)
  26. {
  27.   Handle = ::CopyIcon(instance, icon);
  28.   CheckValid();
  29. }
  30. #endif
  31.  
  32. TIcon::TIcon(HINSTANCE instance, TResId resId)
  33. {
  34.   Handle = ::LoadIcon(instance, resId);
  35.   ShouldDelete = (instance != 0);
  36.   CheckValid();
  37. }
  38.  
  39. TIcon::TIcon(HINSTANCE instance, const char far* fileName, int index)
  40. {
  41. #if defined(BI_PLAT_WIN32) && WINVER >= 0x400
  42. #else
  43.   Handle = ::ExtractIcon(instance, (LPSTR)fileName, index);
  44. #endif
  45.   if ((int)Handle == 1)
  46.     Handle = 0;
  47.   CheckValid();
  48. }
  49.  
  50. TIcon::TIcon(HINSTANCE instance, const TSize& size, int planes, int bitsPixel,
  51.              const void far* andBits, const void far* xorBits)
  52. {
  53.   Handle = ::CreateIcon(instance, size.cx, size.cy,
  54.                         uint8(planes), uint8(bitsPixel),
  55.                         (const uint8 far*)andBits, (const uint8 far*)xorBits);
  56.   CheckValid();
  57. }
  58.  
  59. #if defined(BI_PLAT_WIN32)
  60. TIcon::TIcon(const void* resBits, uint32 resSize)
  61. {
  62.   Handle = CreateIconFromResource((PBYTE)resBits, resSize, true, 0x00030000);
  63.   CheckValid();
  64. }
  65.  
  66. TIcon::TIcon(const ICONINFO* iconInfo)
  67. {
  68.   //IconInfo->fIcon = true;  // assume the user setup the struct OK
  69.   Handle = CreateIconIndirect((PICONINFO)iconInfo);
  70.   CheckValid();
  71. }
  72. #endif
  73.  
  74. TIcon::~TIcon()
  75. {
  76.   if (ShouldDelete)
  77.     ::DestroyIcon((HICON)Handle);
  78. }
  79.