home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / ool.zip / OOL / source / xreslib.cpp < prev    next >
C/C++ Source or Header  |  1997-04-04  |  4KB  |  125 lines

  1. #include "XRes.h"
  2. #include "XResLib.h"
  3. #include "XApp.h"
  4. #include "XWindow.h"
  5. #include "XString.h"
  6. #include "XMsgBox.h"
  7. #include "XIcon.h"
  8. #include "xexcept.h"
  9.  
  10. XIcon :: ~XIcon()
  11. {
  12.     if (handle && loaded)
  13.         WinFreeFileIcon(handle);
  14. }
  15.  
  16.  
  17. BOOL XIcon::Load(const char *p, const BOOL copy)
  18. {
  19.     loaded = TRUE;
  20.     if (handle)
  21.         WinFreeFileIcon(handle);
  22.     handle = WinLoadFileIcon((PSZ) p, copy);
  23.     return handle != NULLHANDLE ? TRUE : FALSE;
  24. }
  25.  
  26.  
  27. BOOL XIcon::Load(const XResource * r)
  28. {
  29.     handle = WinLoadPointer(HWND_DESKTOP, r->GetResourceLibrary()->GetModuleHandle(), r->GetID());
  30.     return handle != NULLHANDLE ? TRUE : FALSE;
  31. }
  32.  
  33.  
  34. /*@ 
  35. @class XResource
  36. @type overview
  37. @symbol _
  38. @remarks The class XResource describes resources used in an application. A resource may be an icon, a dialog template
  39. a menubar etc. An resource is decribed in the class XResource with an ID and a library (XResourceLibrary).
  40. The resources may reside in the EXE-file or in a resource-DLL (see XResouceLibrary for details).
  41. */
  42.  
  43.  
  44. /*@ XResource::XResource()
  45. @group constructors/destructors
  46. @remarks Constructs a resource. Resources are defined by an ID and
  47. a XResourceLibrary which contains the resource.
  48. @parameters    ULONG theResourceID       the ID of the resource<BR>
  49.               XResourceLibrary * theLib     pointer to the library which contains the resource.
  50. */
  51.  
  52.  
  53. /*@ XResourceLibrary :: XResourceLibrary(const XProcess * app, const char *path)
  54. @group constructors/destructors
  55. @remarks Constructs a resource library.
  56. @parameters    <t '°' c=2>
  57.                     °XProcess * theOwner       °A pointer to the owning process. Every
  58.                                          resource which is build from the library will
  59.                                          be owned by this process
  60.                °char * thePath            °path of the library without extension ".DLL".
  61.                                          If the path is empty, a resource library will
  62.                                          be created with the resources which are
  63.                                          linked to the exe-file.
  64.                                          If the file cannot be found an error ocures.
  65.                                       Default is NULL.
  66.                     </t>
  67. @exceptions    If the method fails an exception of the type XException is thrown.
  68. */
  69. XResourceLibrary :: XResourceLibrary(const XProcess * app, const char *path)
  70. {
  71.     char errorBuffer[100];
  72.  
  73.     proc = (XProcess *) app;
  74.     moduleHandle = 0;
  75.     LONG res;
  76.  
  77.     if (path)
  78.     {
  79.         if ((res = DosLoadModule((PSZ) errorBuffer, 100, (PSZ) path, &moduleHandle)) != 0)
  80.             OOLThrow("error loading resourcefile", res);
  81.     }
  82. }
  83.  
  84.  
  85. /*@ XResourceLibrary::LoadString(XString * string, const unsigned long resId)
  86. @group load resources
  87. @remarks Loads a string out of the library.
  88. @parameters    XString * string          variable which will get the string<BR>
  89.                ULONG theResourceID       the ID of the string
  90. @exceptions    If the method fails an exception of the type XException is thrown.
  91. */
  92. BOOL XResourceLibrary::LoadString(XString * string, const unsigned long resId)
  93. {
  94.     char s[255];
  95.     SHORT len;
  96.  
  97.     if ((len = WinLoadString(proc->hab, moduleHandle, resId, 255, (PCH) s)) == 0)
  98.         OOLThrow("error loading string from resources - string is empty or not avaible", -10);
  99.     else
  100.         *string = s;
  101.     return TRUE;
  102. }
  103.  
  104.  
  105. HWND XResourceLibrary::LoadMenu(const XWindow * fr, const unsigned long id)
  106. {
  107.     LONG hwnd;
  108.  
  109.     if ((hwnd = WinLoadMenu(fr->GetHandle(), moduleHandle, id)) == 0)
  110.         OOLThrow("error loading menu - menu not found", -10);
  111.  
  112.     return hwnd;
  113. }
  114.  
  115.  
  116. /*@ XResourceLibrary :: ~XResourceLibrary()
  117. @group constructors/destructors
  118. @remarks Destructs a resource library.
  119. */
  120. XResourceLibrary :: ~XResourceLibrary()
  121. {
  122.     if (moduleHandle > 0)
  123.         DosFreeModule(moduleHandle);
  124. }
  125.