xrcdemo.cpp 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. //-----------------------------------------------------------------------------
  2. // Name: xrcdemo.cpp
  3. // Purpose: XML resources sample: Main application file
  4. // Author: Robert O'Connor (rob@medicalmnemonics.com), Vaclav Slavik
  5. // Copyright: (c) Robert O'Connor and Vaclav Slavik
  6. // Licence: wxWindows licence
  7. //-----------------------------------------------------------------------------
  8. //-----------------------------------------------------------------------------
  9. // Standard wxWidgets headers
  10. //-----------------------------------------------------------------------------
  11. // For compilers that support precompilation, includes "wx/wx.h".
  12. #include "wx/wxprec.h"
  13. #ifdef __BORLANDC__
  14. #pragma hdrstop
  15. #endif
  16. // For all others, include the necessary headers (this file is usually all you
  17. // need because it includes almost all "standard" wxWidgets headers)
  18. #ifndef WX_PRECOMP
  19. #include "wx/wx.h"
  20. #endif
  21. //-----------------------------------------------------------------------------
  22. // Header of this .cpp file
  23. //-----------------------------------------------------------------------------
  24. #include "xrcdemo.h"
  25. //-----------------------------------------------------------------------------
  26. // Remaining headers: Needed wx headers, then wx/contrib headers, then app one
  27. //-----------------------------------------------------------------------------
  28. #include "wx/image.h" // wxImage
  29. #include "wx/xrc/xmlres.h" // XRC XML resources
  30. #if wxUSE_RIBBON
  31. #include "wx/xrc/xh_ribbon.h"
  32. #endif // wxUSE_RIBBON
  33. #include "wx/cshelp.h" // wxSimpleHelpProvider for helptext
  34. #include "myframe.h"
  35. //-----------------------------------------------------------------------------
  36. // wxWidgets macro: Declare the application.
  37. //-----------------------------------------------------------------------------
  38. // Create a new application object: this macro will allow wxWidgets to create
  39. // the application object during program execution (it's better than using a
  40. // static object for many reasons) and also declares the accessor function
  41. // wxGetApp() which will return the reference of the right type (i.e. the_app and
  42. // not wxApp).
  43. IMPLEMENT_APP(MyApp)
  44. //-----------------------------------------------------------------------------
  45. // Public methods
  46. //-----------------------------------------------------------------------------
  47. // 'Main program' equivalent: the program execution "starts" here
  48. bool MyApp::OnInit()
  49. {
  50. if ( !wxApp::OnInit() )
  51. return false;
  52. // If there is any of a certain format of image in the xrcs, then first
  53. // load a handler for that image type. This example uses XPMs & a gif, but
  54. // if you want PNGs, then add a PNG handler, etc. See wxImage::AddHandler()
  55. // documentation for the types of image handlers available.
  56. wxImage::AddHandler(new wxXPMHandler);
  57. wxImage::AddHandler(new wxGIFHandler);
  58. // Initialize all the XRC handlers. Always required (unless you feel like
  59. // going through and initializing a handler of each control type you will
  60. // be using (ie initialize the spinctrl handler, initialize the textctrl
  61. // handler). However, if you are only using a few control types, it will
  62. // save some space to only initialize the ones you will be using. See
  63. // wxXRC docs for details.
  64. wxXmlResource::Get()->InitAllHandlers();
  65. #if wxUSE_RIBBON
  66. wxXmlResource::Get()->AddHandler(new wxRibbonXmlHandler);
  67. #endif
  68. // Load all of the XRC files that will be used. You can put everything
  69. // into one giant XRC file if you wanted, but then they become more
  70. // diffcult to manage, and harder to reuse in later projects.
  71. if ( !wxXmlResource::Get()->LoadAllFiles("rc") )
  72. return false;
  73. #if wxUSE_HELP
  74. // Use the simple help provider to show the context-sensitive help
  75. wxHelpProvider::Set( new wxSimpleHelpProvider );
  76. #endif // wxUSE_HELP
  77. // Make an instance of your derived frame. Passing NULL (the default value
  78. // of MyFrame's constructor is NULL) as the frame doesn't have a parent
  79. // since it is the main application window.
  80. MyFrame *frame = new MyFrame();
  81. // Show the frame as it's created initially hidden.
  82. frame->Show(true);
  83. // Return true to tell program to continue (false would terminate).
  84. return true;
  85. }