init.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. ///////////////////////////////////////////////////////////////////////////////
  2. // Name: wx/init.h
  3. // Purpose: wxWidgets initialization and finalization functions
  4. // Author: Vadim Zeitlin
  5. // Modified by:
  6. // Created: 29.06.2003
  7. // Copyright: (c) 2003 Vadim Zeitlin <vadim@wxwidgets.org>
  8. // Licence: wxWindows licence
  9. ///////////////////////////////////////////////////////////////////////////////
  10. #ifndef _WX_INIT_H_
  11. #define _WX_INIT_H_
  12. #include "wx/defs.h"
  13. #include "wx/chartype.h"
  14. // ----------------------------------------------------------------------------
  15. // wxEntry helper functions which allow to have more fine grained control
  16. // ----------------------------------------------------------------------------
  17. // do common initialization, return true if ok (in this case wxEntryCleanup
  18. // must be called later), otherwise the program can't use wxWidgets at all
  19. //
  20. // this function also creates wxTheApp as a side effect, if IMPLEMENT_APP
  21. // hadn't been used a dummy default application object is created
  22. //
  23. // note that the parameters may be modified, this is why we pass them by
  24. // reference!
  25. extern bool WXDLLIMPEXP_BASE wxEntryStart(int& argc, wxChar **argv);
  26. // free the resources allocated by the library in wxEntryStart() and shut it
  27. // down (wxEntryStart() may be called again afterwards if necessary)
  28. extern void WXDLLIMPEXP_BASE wxEntryCleanup();
  29. // ----------------------------------------------------------------------------
  30. // wxEntry: this function initializes the library, runs the main event loop
  31. // and cleans it up
  32. // ----------------------------------------------------------------------------
  33. // note that other, platform-specific, overloads of wxEntry may exist as well
  34. // but this one always exists under all platforms
  35. //
  36. // returns the program exit code
  37. extern int WXDLLIMPEXP_BASE wxEntry(int& argc, wxChar **argv);
  38. // we overload wxEntry[Start]() to take "char **" pointers too
  39. #if wxUSE_UNICODE
  40. extern bool WXDLLIMPEXP_BASE wxEntryStart(int& argc, char **argv);
  41. extern int WXDLLIMPEXP_BASE wxEntry(int& argc, char **argv);
  42. #endif// wxUSE_UNICODE
  43. // Under Windows we define additional wxEntry() overloads with signature
  44. // compatible with WinMain() and not the traditional main().
  45. #if wxUSE_GUI && defined(__WINDOWS__)
  46. #include "wx/msw/init.h"
  47. #endif
  48. // ----------------------------------------------------------------------------
  49. // Using the library without (explicit) application object: you may avoid using
  50. // wxDECLARE_APP and wxIMPLEMENT_APP macros and call the functions below instead at
  51. // the program startup and termination
  52. // ----------------------------------------------------------------------------
  53. // initialize the library (may be called as many times as needed, but each
  54. // call to wxInitialize() must be matched by wxUninitialize())
  55. extern bool WXDLLIMPEXP_BASE wxInitialize();
  56. extern bool WXDLLIMPEXP_BASE wxInitialize(int argc, wxChar **argv);
  57. #if wxUSE_UNICODE
  58. extern bool WXDLLIMPEXP_BASE wxInitialize(int argc, char **argv);
  59. #endif
  60. // clean up -- the library can't be used any more after the last call to
  61. // wxUninitialize()
  62. extern void WXDLLIMPEXP_BASE wxUninitialize();
  63. // create an object of this class on stack to initialize/cleanup the library
  64. // automatically
  65. class WXDLLIMPEXP_BASE wxInitializer
  66. {
  67. public:
  68. // initialize the library
  69. wxInitializer()
  70. {
  71. m_ok = wxInitialize();
  72. }
  73. wxInitializer(int argc, wxChar **argv)
  74. {
  75. m_ok = wxInitialize(argc, argv);
  76. }
  77. #if wxUSE_UNICODE
  78. wxInitializer(int argc, char **argv)
  79. {
  80. m_ok = wxInitialize(argc, argv);
  81. }
  82. #endif // wxUSE_UNICODE
  83. // has the initialization been successful? (explicit test)
  84. bool IsOk() const { return m_ok; }
  85. // has the initialization been successful? (implicit test)
  86. operator bool() const { return m_ok; }
  87. // dtor only does clean up if we initialized the library properly
  88. ~wxInitializer() { if ( m_ok ) wxUninitialize(); }
  89. private:
  90. bool m_ok;
  91. };
  92. #endif // _WX_INIT_H_