home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 1998 May / Pcwk5b98.iso / Borland / Cplus45 / BC45 / OWLINC.PAK / MODULE.H < prev    next >
C/C++ Source or Header  |  1995-08-29  |  6KB  |  194 lines

  1. //----------------------------------------------------------------------------
  2. // ObjectWindows
  3. // (C) Copyright 1991, 1994 by Borland International, All Rights Reserved
  4. //
  5. //   Definition of class TModule.  TModule defines the
  6. //   basic behavior for OWL libraries and applications.
  7. //----------------------------------------------------------------------------
  8. #if !defined(OWL_MODULE_H)
  9. #define OWL_MODULE_H
  10.  
  11. #if !defined(OWL_OWLDEFS_H)
  12. # include <owl/owldefs.h>
  13. #endif
  14. #if !defined(CLASSLIB_OBJSTRM_H)
  15. # include <classlib/objstrm.h>
  16. #endif
  17. #if !defined(OSL_GEOMETRY)
  18. # include <osl/geometry.h>
  19. #endif
  20. #if !defined(OWL_EVENTHAN_H)
  21. # include <owl/eventhan.h>
  22. #endif
  23. #if !defined(OWL_EXCEPT_H)
  24. # include <owl/except.h>
  25. #endif
  26.  
  27. class _OWLCLASS TWindow;
  28. class _OWLCLASS TDialog;
  29.  
  30. //
  31. //  class TModule
  32. //  ----- -------
  33. //
  34. class _OWLCLASS TModule : public TEventHandler, public TStreamableBase {
  35.   public:
  36.     class _OWLCLASS_RTL TXInvalidModule : public TXOwl {
  37.       public:
  38.         TXInvalidModule();
  39.         TXOwl* Clone();
  40.         void Throw();
  41.     };
  42.  
  43.     //
  44.     // Constructors & destructor
  45.     //
  46.     TModule(const char far* name, bool shouldLoad = true);
  47.     TModule(const char far* name, HINSTANCE hInstance);
  48.     TModule(const char far* name, HINSTANCE hInstance, const char far* cmdLine);
  49.     virtual ~TModule();
  50.  
  51.     //
  52.     // Finish-up initialization of a module
  53.     //
  54.     void          InitModule(HINSTANCE hInstance, const char far* cmdLine);
  55.  
  56.     operator      HINSTANCE() const {return HInstance;}
  57.     bool operator ==(const TModule& other) const
  58.                     {return HInstance == other.HInstance;}
  59.     bool          IsLoaded() const {return HInstance > HINSTANCE(32);}
  60.  
  61.     //
  62.     // Get & set members. Use these instead of directly accessing members
  63.     //
  64.     const char far* GetName() const {return Name;}
  65.     void          SetName(const char far* name);
  66.  
  67.     HINSTANCE     GetInstance() const {return HInstance;}
  68.     void          SetInstance(HINSTANCE hInstance);
  69.  
  70.     //
  71.     // Module wide error handler. Called when fatal exceptions are caught.
  72.     //
  73.     virtual int   Error(xmsg& x, unsigned captionResId, unsigned promptResId=0);
  74.  
  75.     //
  76.     // Windows HINSTANCE related API functions encapsulated
  77.     //
  78.     int           GetModuleFileName(char far* buff, int maxChars)
  79.                     {return ::GetModuleFileName(HInstance, buff, maxChars);}
  80.  
  81.     FARPROC       GetProcAddress(const char far* fcnName) const
  82.                     {return ::GetProcAddress(HInstance, fcnName);}
  83.  
  84. #if defined(BI_PLAT_WIN16)
  85.     int           GetModuleUsage() const {return ::GetModuleUsage(HInstance);}
  86.     int           GetInstanceData(void NEAR* data, int len) const
  87.                     {return ::GetInstanceData(HInstance, (uint8 NEAR*)data, len);}
  88. # endif
  89.  
  90.     HRSRC         FindResource(TResId id, const char far* type) const
  91.                     {return ::FindResource(HInstance, id, type);}
  92.     HGLOBAL       LoadResource(HRSRC hRsrc) const
  93.                     {return ::LoadResource(HInstance, hRsrc);}
  94.     uint32         SizeofResource(HRSRC hRsrc) const
  95.                     {return ::SizeofResource(HInstance, hRsrc);}
  96.  
  97. #if defined(BI_PLAT_WIN16)
  98.     int           AccessResource(HRSRC hRsrc) const
  99.                     {return ::AccessResource(HInstance, hRsrc);}
  100.     HGLOBAL       AllocResource(HRSRC hRsrc, uint32 size) const
  101.                     {return ::AllocResource(HInstance, hRsrc, size);}
  102.     RSRCHDLRPROC  SetResourceHandler(const char far* type, RSRCHDLRPROC loadProc) const
  103.                     {return ::SetResourceHandler(HInstance, type, loadProc);}
  104. # endif
  105.  
  106.     int           LoadString(uint id, char far* buf, int maxChars) const;
  107.     string        LoadString(uint id) const;
  108.     HBITMAP       LoadBitmap(TResId id) const
  109.                     {return ::LoadBitmap(HInstance, id);}
  110.     bool          GetClassInfo(const char far* name, WNDCLASS far* wndclass) const
  111.                     {return ::GetClassInfo(HInstance, name, wndclass);}
  112.     HACCEL        LoadAccelerators(TResId id) const
  113.                     {return ::LoadAccelerators(HInstance, id);}
  114.     HMENU         LoadMenu(TResId id) const
  115.                     {return ::LoadMenu(HInstance, id);}
  116.     HCURSOR       LoadCursor(TResId id) const
  117.                     {return ::LoadCursor(HInstance, id);}
  118.     HICON         LoadIcon(const char far* name) const
  119.                     {return ::LoadIcon(HInstance, name);}
  120.  
  121. #if defined(BI_PLAT_WIN16)
  122.     HCURSOR       CopyCursor(HCURSOR hCursor) const
  123.                     {return ::CopyCursor(HInstance, hCursor);}
  124.     HICON         CopyIcon(HICON hIcon) const
  125.                     {return ::CopyIcon(HInstance, hIcon);}
  126. #else
  127.     HICON         CopyIcon(HICON hIcon) const {return ::CopyIcon(hIcon);}
  128. #endif
  129.                     
  130.   protected:    
  131.     char far* Name;
  132.     HINSTANCE HInstance;
  133.  
  134.   private:    
  135.     bool      ShouldFree;
  136.     
  137.     //
  138.     // hidden to prevent accidental copying or assignment
  139.     //
  140.     TModule(const TModule&);
  141.     TModule& operator =(const TModule&);
  142.     friend ostream& _OWLFUNC operator <<(ostream& os, const TModule& m);
  143.  
  144.   //
  145.   // Obsolete members for Owl 1 compatibility
  146.   //
  147.   public:
  148.     char far* lpCmdLine;    // Use argv & argc for portability
  149.     TStatus   Status;       // Use exceptions
  150.  
  151.     TWindow*  ValidWindow(TWindow* win) {return win;}
  152.     TWindow*  MakeWindow(TWindow* win);
  153.     int       ExecDialog(TDialog* dialog);
  154.  
  155.     virtual void  Error(int errorCode);
  156.  
  157.     HWND      GetClientHandle(HWND hWnd);
  158.     TWindow*  GetParentObject(HWND hWndParent);
  159.  
  160.     bool      LowMemory() {return false;}
  161.     void      RestoreMemory() {}
  162.  
  163.   DECLARE_STREAMABLE(_OWLCLASS, TModule, 1);
  164. };
  165.  
  166. //
  167. // Global pointer to the current module
  168. //
  169. extern TModule* Module;
  170.  
  171. //
  172. // Exported pointers from OWL modules, implemented in GLOBAL.CPP
  173. // Unmanagled to allow easy loading via LoadLibrary
  174. //
  175. class _OWLCLASS TDocTemplate;
  176. extern "C" {
  177.   TDocTemplate** _export PASCAL GetDocTemplateHead(int version);
  178.   TModule** _export PASCAL GetModulePtr(int version);
  179. }
  180.  
  181. //
  182. // Main entry point for an Owl application
  183. //
  184. int OwlMain(int argc, char* argv[]);
  185.  
  186. //
  187. // Get this header to get GetApplicationObject() for backward compatibility 
  188. //
  189. #if !defined(OWL_APPDICT_H)
  190. # include <owl/appdict.h>
  191. #endif
  192.  
  193. #endif  // OWL_MODULE_H
  194.