home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / cset21v1.zip / IBMCPP / IBMCLASS / IAPP.HPP < prev    next >
C/C++ Source or Header  |  1993-10-22  |  13KB  |  260 lines

  1. #ifndef _IAPP_
  2. #define _IAPP_
  3. /*******************************************************************************
  4. * FILE NAME: iapp.hpp                                                          *
  5. *                                                                              *
  6. * DESCRIPTION:                                                                 *
  7. *   Declaration of the class(es):                                              *
  8. *     IApplication        - class of objects representing OS/2 "executables"   *
  9. *     ICurrentApplication - class of the single instance of the "current"      *
  10. *                           executable                                         *
  11. *                                                                              *
  12. * COPYRIGHT:                                                                   *
  13. *   (C) Copyright IBM Corporation 1992                                         *
  14. *   All Rights Reserved                                                        *
  15. *   Licensed Materials * Property of IBM                                       *
  16. *                                                                              *
  17. *******************************************************************************/
  18. #ifndef _IVBASE_
  19.   #include <ivbase.hpp>
  20. #endif
  21.  
  22. #ifndef _IHANDLE_
  23.   #include <ihandle.hpp>
  24. #endif
  25.  
  26. /*----------------------------------------------------------------------------*/
  27. /* Align classes on four byte boundary.                                       */
  28. /*----------------------------------------------------------------------------*/
  29. #pragma pack(4)
  30.  
  31. struct pib_s;
  32.  
  33. class IResourceLibrary;
  34.  
  35. class IString;
  36.  
  37. class ICurrentApplication;
  38.  
  39. class IApplication : public IVBase {
  40. typedef IVBase
  41.   Inherited;
  42. /*******************************************************************************
  43. * The IApplication class's objects represent OS/2 processes.                   *
  44. *                                                                              *
  45. * User Interface Class Library supports only the currently executing           *
  46. * application, the single instance of the derived class ICurrentApplication.   *
  47. * The static member function current provides access to that instance.         *
  48. *******************************************************************************/
  49. public:
  50. /*-------------------------------- Accessors -----------------------------------
  51. | These functions provide means of getting and setting the accessible          |
  52. | attributes of instances of this class:                                       |
  53. |   id          - Returns the object's process identifier value.               |
  54. |   current     - Returns a reference to the current application, an instance  |
  55. |                 of the ICurrentApplication class.                            |
  56. |   asString    - Returns the string "IApplication(process identifier value)." |
  57. |   asDebugInfo - Returns a representation of the application as debug         |
  58. |                 information.                                                 |
  59. |   currentPID  - Returns the current process identifier.                      |
  60. ------------------------------------------------------------------------------*/
  61. virtual IProcessId
  62.   id ( ) const;
  63.  
  64. static ICurrentApplication
  65.  ¤t ( );
  66.  
  67. virtual IString
  68.   asString    ( ) const,
  69.   asDebugInfo ( ) const;
  70.  
  71. static IProcessId
  72.   currentPID ( );
  73.  
  74. /*--------------------------------- Priority -----------------------------------
  75. | You can use the following members to control the priority of the application |
  76. | (and its threads).  Note: While you can set priorities using the IApplication|
  77. | class, only threads actually have a priority. As a result, you need to use   |
  78. | functions of the IThread class to query the priority of an application's     |
  79. | threads.                                                                     |
  80. |   PriorityClass        - Enumeration of the various priority classes:        |
  81. |                            noChange                                          |
  82. |                            idleTime                                          |
  83. |                            regular                                           |
  84. |                            timeCritical                                      |
  85. |                            foregroundServer                                  |
  86. |   adjustPriority       - Adjusts the priority level of all the application's |
  87. |                          threads by some amount. An optional flag indicates  |
  88. |                          whether or not to also adjust the priority of       |
  89. |                          threads of descendent processes.                    |
  90. |   setPriority          - Sets the priority class and level of all the        |
  91. |                          application's threads to the argument value. An     |
  92. |                          optional Boolean argument specifies whether the     |
  93. |                          priority of descendent processes should also be     |
  94. |                          modified.                                           |
  95. ------------------------------------------------------------------------------*/
  96. enum PriorityClass
  97.   {
  98.   noChange,
  99.   idleTime,
  100.   regular,
  101.   timeCritical,
  102.   foregroundServer
  103.   };
  104.  
  105. IApplication
  106.  &adjustPriority ( int           adjustment,
  107.                    Boolean       setDescendents = false ),
  108.  &setPriority    ( PriorityClass priorityClass,
  109.                    unsigned      priorityLevel = 0,
  110.                    Boolean       setDescendents = false );
  111.  
  112. protected:
  113. /*------------------------------- Constructor ----------------------------------
  114. | You can only construct an instance of this class with the process identifier |
  115. | for the process that the object will represent.  The constructor is          |
  116. | protected; only the derived class ICurrentApplication utilizes it.           |
  117. ------------------------------------------------------------------------------*/
  118.   IApplication ( const IProcessId &id );
  119.  ~IApplication ( );
  120.  
  121. /*------------------------------ Implementation --------------------------------
  122. | This function provides utilities used to implement this class:               |
  123. |   setId     - Sets the process identifier.  This function is called by       |
  124. |               derived classes when processes are started.                    |
  125. ------------------------------------------------------------------------------*/
  126. virtual IApplication
  127.   &setId ( const IProcessId &id );
  128.  
  129. private:
  130. /*--------------------------------- PRIVATE ----------------------------------*/
  131. static ICurrentApplication
  132.  *pCurrent;
  133. IProcessId
  134.   pid;
  135. }; // IApplication
  136.  
  137. class ICurrentApplication : public IApplication {
  138. typedef IApplication
  139.   Inherited;
  140. /*******************************************************************************
  141. * The ICurrentApplication class's objects represent the OS/2 program that is   *
  142. * currently running.                                                           *
  143. *                                                                              *
  144. * There is a single instance of this class.  You can obtain a reference to it  *
  145. * by using the static member function IApplication::current.  The instance of  *
  146. * this class contains information that must be maintained for each application *
  147. * and must be accessible to the objects executing in the process.              *
  148. *******************************************************************************/
  149. public:
  150. /*-------------------------------- Arguments -----------------------------------
  151. | These functions provide means for accessing the program arguments:           |
  152. |   argc           - Obtains the number of application arguments.              |
  153. |   argv           - Obtains the nth argument to the application.              |
  154. |   setArgs        - Sets the program arguments. You should call this member   |
  155. |                    function from your application's main function, passing   |
  156. |                    its argc and argv argument values.                        |
  157. ------------------------------------------------------------------------------*/
  158. virtual int
  159.   argc ( ) const;
  160.  
  161. virtual IString
  162.   argv ( int argNo ) const;
  163.  
  164. virtual ICurrentApplication
  165.  &setArgs ( int                argc,
  166.             const char * const argv[] );
  167.  
  168. /*---------------------------- Resource Libraries ------------------------------
  169. | These functions provide access to the user's default application resource    |
  170. | library and the ICLUI library's resource library:                            |
  171. |   userResourceLibrary    - Obtains a reference to the default user resource  |
  172. |                            library for this application.  The default is the |
  173. |                            .exe itself.  IResourceId will use this resource  |
  174. |                            library if one is not specified explicitly.       |
  175. |   setUserResourceLibrary - Sets the user resource library from which         |
  176. |                            application resources will be obtained.  The      |
  177. |                            default is IResourceId.  An input argument of 0   |
  178. |                            implies that the .exe should be used.             |
  179. |   resourceLibrary        - Obtains a reference to the User Interface Class   |
  180. |                            Library resource library from which resources     |
  181. |                            required by the base library code are loaded.     |
  182. |                            If setResourceLibrary has been called with the    |
  183. |                            name of a dynamic-link library (DLL), the handle  |
  184. |                            of this library will be returned.  Otherwise, the |
  185. |                            environment variable "ICLUI RESLIB" is checked    |
  186. |                            for the name of a DLL and its handle is returned. |
  187. |                            Set the environment variable using                |
  188. |                            "SET ICLUI RESLIB=myappdll".                      |
  189. |                            Finally, if the environment variable has not been |
  190. |                            set, the default DDE4U001.DLL will be used.       |
  191. |   setResourceLibrary     - Sets the resource library from which the class    |
  192. |                            library resources are loaded.  The resource       |
  193. |                            library is specified as the name of the DLL       |
  194. |                            without the file extension.  If 0 is passed, the  |
  195. |                            resources are loaded from the application .exe.   |
  196. ------------------------------------------------------------------------------*/
  197. virtual IResourceLibrary
  198.  &userResourceLibrary ( ) const,
  199.  &resourceLibrary     ( ) const;
  200.  
  201. virtual ICurrentApplication
  202.  &setUserResourceLibrary ( const char *resLibName ),
  203.  &setResourceLibrary     ( const char *resLibName );
  204.  
  205. /*---------------------------- Starting/Stopping -------------------------------
  206. | These functions provide support for beginning and ending the current         |
  207. | process:                                                                     |
  208. |   run  - Initiates the processing of Presentation Manager messages in the    |
  209. |          current process.                                                    |
  210. |   exit - Ends the current process.                                           |
  211. ------------------------------------------------------------------------------*/
  212. virtual ICurrentApplication
  213.  &run  ( ),
  214.  &exit ( );
  215.  
  216. /*-------------------------------- Overrides -----------------------------------
  217. | This class overrides the following inherited function:                       |
  218. |   asDebugInfo    - Returns a diagnostic representation of the object.        |
  219. ------------------------------------------------------------------------------*/
  220. virtual IString
  221.   asDebugInfo ( ) const;
  222.  
  223. protected:
  224. friend class IApplication;
  225. /*------------------------------- Constructor ----------------------------------
  226. | The constructor for this class is protected to ensure that the static        |
  227. | member pCurrent of the IApplication class points to the only instance.       |
  228. ------------------------------------------------------------------------------*/
  229.   ICurrentApplication ( );
  230.  ~ICurrentApplication ( );
  231.  
  232. /*------------------------------ Implementation --------------------------------
  233.   This function provides utilities used to implement this class:
  234.     pib - Returns pointer to the current process's process information block.
  235. ------------------------------------------------------------------------------*/
  236. struct pib_s
  237.  &pib ( );
  238.  
  239. private:
  240. /*--------------------------------- PRIVATE ----------------------------------*/
  241. IResourceLibrary
  242.  *icluiLib,
  243.  *userLib;
  244. Boolean
  245.   exeResource;
  246. int
  247.   argCount;
  248. IString
  249.  *argValue;
  250. struct pib_s
  251.  *pPIB;
  252. }; // ICurrentAppliction
  253.  
  254. /*----------------------------------------------------------------------------*/
  255. /* Resume compiler default packing.                                           */
  256. /*----------------------------------------------------------------------------*/
  257. #pragma pack()
  258.  
  259. #endif /* _IAPP_ */
  260.