home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / ool_main.zip / ool / source / xreslib.cpp < prev    next >
C/C++ Source or Header  |  1998-03-27  |  4KB  |  154 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. BOOL XIcon :: Load( const ULONG id)
  35. {
  36.    handle = WinLoadPointer(HWND_DESKTOP, XApplication::GetApplication()->GetResourceLibrary()->GetModuleHandle(), id);
  37.    return handle != NULLHANDLE ? TRUE : FALSE;
  38. }
  39.  
  40. /*@
  41. @class XResource
  42. @type overview
  43. @symbol _
  44. @remarks The class XResource describes resources used in an application. A resource may be an icon, a dialog template
  45. a menubar etc. An resource is decribed in the class XResource with an ID and a library (XResourceLibrary).
  46. The resources may reside in the EXE-file or in a resource-DLL (see XResouceLibrary for details).
  47. */
  48.  
  49.  
  50. /*@ XResource::XResource()
  51. @group constructors/destructors
  52. @remarks Constructs a resource. Resources are defined by an ID and
  53. a XResourceLibrary which contains the resource.
  54. @parameters
  55. <t '°' c=2>
  56. °ULONG °the ID of the resource
  57. °XResourceLibrary * °pointer to the library which contains the resource.
  58. </t>
  59. */
  60.  
  61.  
  62. /*@
  63. @class XResourceLibrary
  64. @parent XObject
  65. @type overview
  66. @symbol _
  67. */
  68.  
  69. /*@ XResourceLibrary :: XResourceLibrary(const char *path)
  70. @group constructors/destructors
  71. @remarks Constructs a resource library.
  72. @parameters
  73. char * path of the library without extension ".DLL".
  74.                                          If the path is empty, a resource library will
  75.                                          be created with the resources which are
  76.                                          linked to the exe-file.
  77.                                          If the file cannot be found an error ocures.
  78.                                       Default is NULL.
  79. @exceptions   If the method fails an exception of the type XException is thrown.
  80. @updated _
  81. */
  82. #include "xmsgbox.h"
  83. XResourceLibrary :: XResourceLibrary(const char *path)
  84. {
  85.    char errorBuffer[100];
  86.  
  87.    moduleHandle = 0;
  88.    LONG res;
  89.  
  90.    if (path)
  91.    {
  92.       if ((res = DosLoadModule((PSZ) errorBuffer, 100, (PSZ) path, &moduleHandle)) != 0)
  93.       {
  94.          XString s = "error loading resourcefile ";
  95.          s += path;
  96.          OOLThrow(s, res);
  97.       } /* end if */
  98.    }
  99. }
  100.  
  101.  
  102. /*@ XResourceLibrary::LoadString(XString * string, const unsigned long resId)
  103. @group load resources
  104. @remarks Loads a string out of the library.
  105. @parameters    XString * string          variable which will get the string<BR>
  106.                ULONG theResourceID       the ID of the string
  107. @exceptions   If the method fails an exception of the type XException is thrown.
  108. */
  109. BOOL XResourceLibrary::LoadString(XString * string, const unsigned long resId)
  110. {
  111.    char s[255];
  112.    SHORT len;
  113.  
  114.    if ((len = WinLoadString( XApplication::GetApplication()->GetAnchorBlock(), moduleHandle, resId, 255, (PCH) s)) == 0)
  115.       OOLThrow("error loading string from resources - string is empty or not avaible", -10);
  116.    else
  117.       *string = s;
  118.    return TRUE;
  119. }
  120.  
  121.  
  122. PFNWP XResourceLibrary :: LoadFunction( char * name)
  123. {
  124.    return WinLoadProcedure( XApplication::GetApplication()->GetAnchorBlock(), moduleHandle, (PSZ) name);
  125. }
  126.  
  127.  
  128. BOOL XResourceLibrary :: UnLoadFunction( PFNWP pfnwp)
  129. {
  130.    return WinDeleteProcedure( XApplication::GetApplication()->GetAnchorBlock(), pfnwp);
  131. }
  132.  
  133.  
  134. HWND XResourceLibrary::LoadMenu(const XWindow * fr, const unsigned long id)
  135. {
  136.    LONG hwnd;
  137.  
  138.    if ((hwnd = WinLoadMenu(fr->GetHandle(), moduleHandle, id)) == 0)
  139.       OOLThrow("error loading menu - menu not found", -10);
  140.  
  141.    return hwnd;
  142. }
  143.  
  144.  
  145. /*@ XResourceLibrary :: ~XResourceLibrary()
  146. @group constructors/destructors
  147. @remarks Destructs a resource library.
  148. */
  149. XResourceLibrary :: ~XResourceLibrary()
  150. {
  151.    if (moduleHandle)
  152.       DosFreeModule(moduleHandle);
  153. }
  154.