Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

198 lines
7.4 KiB

  1. /**********************************************************************/
  2. /** Microsoft Windows/NT **/
  3. /** Copyright(c) Microsoft Corp., 1991 **/
  4. /**********************************************************************/
  5. /*
  6. bltapp.hxx
  7. Simple application framework: definition
  8. This class encapsulates the skeleton of a Windows application
  9. and messageloop as a simple "application startup" object.
  10. FILE HISTORY
  11. beng 01-Apr-1991 Added to BLT
  12. rustanl 17-Jun-1991 Added APPLICATION
  13. rustanl 15-Jul-1991 Code review changes (no functional
  14. differences). CR attended by
  15. BenG, ChuckC, Hui-LiCh, TerryK, RustanL.
  16. rustanl 29-Aug-1991 Virtualized Run
  17. beng 14-Oct-1991 Removed APPSTART
  18. beng 29-Jun-1992 DLLization delta
  19. */
  20. #ifndef _BLT_HXX_
  21. #error "Don't include this file directly; instead, include it through blt.hxx"
  22. #endif // _BLT_HXX_
  23. #ifndef _BLTAPP_HXX_
  24. #define _BLTAPP_HXX_
  25. #include <stdlib.h>
  26. #include "base.hxx"
  27. #include "bltpump.hxx"
  28. /*************************************************************************
  29. NAME: APPLICATION
  30. SYNOPSIS: An application object: a thang that you run.
  31. INTERFACE: APPLICATION() - Constructor
  32. Initializes BLT and other common
  33. subsystems that need to be initialized
  34. during application start-up time.
  35. ~APPLICATION() - Destructor
  36. Undoes what the constructor did
  37. Run() - Runs the application
  38. This method is called automatically
  39. (by the SET_ROOT_OBJECT macro).
  40. A subclass may replace Run, do some
  41. second stage construction, call the
  42. parent Run method, destroys things
  43. set up in the second stage construction.
  44. Run will not be called unless the object
  45. constructed successfully, so the Run
  46. method does not need to call QueryError.
  47. QueryArgc() - Return # of args on command line
  48. QueryArgv() - Return the tokenized command line
  49. PARENT: BASE, HAS_MESSAGE_PUMP
  50. NOTES:
  51. The constructor, Run method, and destructor are all
  52. accessible only to BltMain. SET_ROOT_OBJECT will handle
  53. this for the application.
  54. Currently ignores the Windows command line.
  55. HISTORY:
  56. rustanl 17-Jun-1991 Created
  57. beng 08-Jul-1991 Accessible only to BltMain;
  58. FilterMessage added
  59. rustanl 29-Aug-1991 Virtualized Run
  60. rustanl 04-Sep-1991 Added DisplayCtError
  61. beng 07-Oct-1991 Uses HAS_MESSAGE_PUMP
  62. beng 24-Apr-1992 More realistic command-line support
  63. beng 03-Aug-1992 Add QueryInstance
  64. **************************************************************************/
  65. DLL_CLASS APPLICATION : public BASE, public HAS_MESSAGE_PUMP
  66. {
  67. friend INT BltMain(HINSTANCE hInst, INT nShow);
  68. private:
  69. HINSTANCE _hInstance;
  70. BOOL _fMsgPopupIsInit;
  71. VOID DisplayCtError( APIERR err );
  72. protected:
  73. APPLICATION( HINSTANCE hInstance, INT nCmdShow,
  74. UINT nMinR, UINT nMaxR, UINT nMinS, UINT nMaxS );
  75. ~APPLICATION();
  76. virtual INT Run();
  77. public:
  78. HINSTANCE QueryInstance() const
  79. { return _hInstance; }
  80. static BOOL IsSystemInitialized( VOID );
  81. // The runtime takes care of support for the following
  82. // in DLLCLIENT vs APP situations.
  83. #if 0
  84. //#ifdef _DLL
  85. static CHAR ** QueryArgv()
  86. { return * :: __argv_dll; }
  87. static const UINT QueryArgc()
  88. { return * :: __argc_dll; }
  89. #else
  90. static CHAR ** QueryArgv()
  91. { return __argv; }
  92. static const UINT QueryArgc()
  93. { return __argc; }
  94. #endif /* _DLL */
  95. };
  96. /*******************************************************************
  97. NAME: SET_ROOT_OBJECT
  98. SYNOPSIS: Macro that allows a client to specify what class
  99. describes the application. The macro will arrange
  100. for the construction, execution, and destruction of
  101. an instance of a particular type of APPLICATION.
  102. ENTRY: root_obj_class_name - Name of class that describes
  103. the application
  104. CAVEATS: This macro sets up the app's WinMain.
  105. Clients should not try to supply their own WinMain.
  106. NOTES: This macro should be used exactly once in every
  107. application.
  108. Clients of APPLICATION may still set a breakpoint
  109. at WinMain, generating a break before the application
  110. really gets started.
  111. HISTORY:
  112. rustanl 17-Jun-1991 Created
  113. beng 08-Jul-1991 Emits BltMain instead of WinMain
  114. rustanl 29-Aug-1991 Virtualized Run
  115. rustanl 04-Sep-1991 Make use of new DisplayCtError
  116. beng 24-Apr-1992 Ignore Windows command line
  117. beng 29-Jun-1992 DLLization delta (includes WinMain)
  118. KeithMo 11-May-1993 Fail gracefully if USER32 not initialized.
  119. ********************************************************************/
  120. #define SET_ROOT_OBJECT( root_class_name, idMinR, idMaxR, idMinS, idMaxS ) \
  121. INT BltMain( HINSTANCE hInstance, INT nCmdShow ) \
  122. { \
  123. if( !APPLICATION::IsSystemInitialized() ) \
  124. { \
  125. return (INT)ERROR_ACCESS_DENIED; \
  126. } \
  127. root_class_name app( hInstance, nCmdShow, \
  128. idMinR, idMaxR, \
  129. idMinS, idMaxS ); \
  130. if ( app.QueryError() != NERR_Success ) \
  131. { \
  132. app.DisplayCtError( app.QueryError()); \
  133. return (INT)app.QueryError(); \
  134. } \
  135. /* The following is a trick to get */ \
  136. /* to the protected Run method of */ \
  137. /* an APPLICATION subclass. */ \
  138. APPLICATION * papp = &app; \
  139. return papp->Run(); \
  140. } \
  141. extern "C" { \
  142. INT WINAPI WinMain(HINSTANCE hInstance, \
  143. HINSTANCE hPrevInstance, \
  144. CHAR * pszCmdLine, \
  145. INT nCmdShow) \
  146. { \
  147. UNREFERENCED(hPrevInstance); \
  148. UNREFERENCED(pszCmdLine); \
  149. return BltMain(hInstance, nCmdShow ); \
  150. } \
  151. } \
  152. #endif // _BLTAPP_HXX_ - end of file