home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / ocl150a.zip / OCL / Source / OIcon.cpp < prev    next >
C/C++ Source or Header  |  1996-10-11  |  3KB  |  123 lines

  1. // OCL - OS/2 Class Library
  2. // (c) Cubus 1995
  3. // All Rights Reserved
  4. // OIcon.cpp
  5.  
  6. /*
  7.  * Redistribution and use in source and binary forms, with or without
  8.  * modification, are permitted provided that the following conditions
  9.  * are met:
  10.  * 1. Redistributions of source code must retain the above copyright
  11.  *    notice, this list of conditions and the following disclaimer.
  12.  * 2. Neither the name Cubus nor the name Team OCL may be used to
  13.  *    endorse or promote products derived from this software
  14.  *    without specific prior written permission.
  15.  * 3. See OCL.INF for a detailed copyright notice.
  16.  *
  17.  *              THIS SOFTWARE IS PROVIDED ``AS IS'' AND
  18.  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  19.  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  20.  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  21.  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  22.  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  23.  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  24.  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  25.  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  26.  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  27.  * SUCH DAMAGE.
  28.  */
  29.  
  30.  
  31. // $Header: W:/Projects/OCL/Source/rcs/OIcon.cpp 1.50 1996/08/11 23:49:21 B.STEIN Release $
  32.  
  33. #define __OCL_SOURCE__
  34.  
  35. #define OINCL_OSTRING
  36. #define OINCL_BASE
  37.  
  38. #include <ocl.hpp>
  39. #include <OIcon.hpp>
  40. #include <OMessage.hpp>
  41.  
  42.  
  43. OIcon::OIcon()
  44.   : OPicture(0, 0),
  45.     hptr(NULLHANDLE)
  46.   {}
  47.  
  48.  
  49. OIcon::OIcon(const ULONG resID, const HMODULE module)
  50.   : OPicture((ULONG)WinQuerySysValue(HWND_DESKTOP, SV_CXICON),
  51.              (ULONG)WinQuerySysValue(HWND_DESKTOP, SV_CYICON)), 
  52.     hptr(WinLoadPointer(HWND_DESKTOP, module, resID))
  53. {
  54.  if (!hptr)
  55.    throw OPMException(OCL::error(70), 0, OException::recoverable);
  56. }
  57.  
  58.  
  59.  
  60. OIcon::OIcon(const HPOINTER ptrHandle)
  61.   : OPicture((ULONG)WinQuerySysValue(HWND_DESKTOP, SV_CXICON),
  62.              (ULONG)WinQuerySysValue(HWND_DESKTOP, SV_CYICON)), 
  63.     hptr(ptrHandle)
  64. {
  65.  if (!hptr)
  66.    throw OPMException(OCL::error(71), 0, OException::recoverable);
  67. }
  68.  
  69.  
  70. OIcon::OIcon(PCSZ fileName)
  71.   : OPicture((ULONG)WinQuerySysValue(HWND_DESKTOP, SV_CXICON),
  72.              (ULONG)WinQuerySysValue(HWND_DESKTOP, SV_CYICON)), 
  73.     hptr(WinLoadFileIcon((PSZ)fileName, TRUE))
  74. {
  75.  if (!hptr)
  76.    throw OPMException(OCL::error(72), 0, OException::recoverable);
  77. }
  78.  
  79.  
  80. OIcon::~OIcon()
  81. {
  82.  destroy();
  83. }
  84.  
  85.  
  86. PSZ OIcon::isOfType() const
  87.  return("OIcon"); 
  88. }
  89.  
  90.  
  91. OIcon& OIcon::load(const ULONG resID, const HMODULE module)
  92. {
  93.  destroy();
  94.  hptr = WinLoadPointer(HWND_DESKTOP, module, resID);
  95.  
  96.  if (!hptr)
  97.    throw OPMException(OCL::error(70), 0, OException::recoverable);
  98.  
  99.  return(*this);
  100. }
  101.  
  102. OIcon& OIcon::loadFromFile(PSZ fileName)
  103. {
  104.  destroy();
  105.  hptr = WinLoadFileIcon(fileName, FALSE);
  106.  
  107.  if (!hptr)
  108.    throw OPMException(OCL::error(70), 0, OException::recoverable);
  109.  
  110.  return(*this);
  111. }
  112.  
  113. OIcon& OIcon::destroy()
  114. {
  115.  if (hptr)
  116.    WinDestroyPointer(hptr);
  117.  
  118.  return(*this);
  119. }
  120.  
  121. // end of source
  122.