home *** CD-ROM | disk | FTP | other *** search
/ Power GUI Programming with VisualAge C++ / powergui.iso / trialva / ibmcppw / samples / ioc / ownhdr / ownhdr.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1996-02-22  |  6.2 KB  |  117 lines

  1. /******************************************************************************
  2. * .FILE:         ownhdr.cpp                                                   *
  3. *                                                                             *
  4. * .DESCRIPTION:  Create Your Own Handler Window : Class Implementation        *
  5. *                                                                             *
  6. * .CLASSES:      MyWindow                                                     *
  7. *                MyTimeHandler                                                *
  8. *                                                                             *
  9. * .COPYRIGHT:                                                                 *
  10. *    Licensed Material - Program-Property of IBM                              *
  11. *    (C) Copyright IBM Corp. 1992, 1996 - All Rights Reserved                 *
  12. *                                                                             *
  13. * .DISCLAIMER:                                                                *
  14. *   The following [enclosed] code is sample code created by IBM               *
  15. *   Corporation.  This sample code is not part of any standard IBM product    *
  16. *   and is provided to you solely for the purpose of assisting you in the     *
  17. *   development of your applications.  The code is provided 'AS IS',          *
  18. *   without warranty of any kind.  IBM shall not be liable for any damages    *
  19. *   arising out of your use of the sample code, even if they have been        *
  20. *   advised of the possibility of such damages.                               *
  21. *                                                                             *
  22. * .NOTE: WE RECOMMEND USING A FIXED SPACE FONT TO LOOK AT THE SOURCE          *
  23. *                                                                             *
  24. ******************************************************************************/
  25. #ifndef _IBASE_                         //Make sure ibase.hpp is included
  26.   #include <ibase.hpp>                  //  since that is where IC_<environ>
  27. #endif                                  //  is defined.
  28. #include <iapp.hpp>
  29. #include <ifont.hpp>
  30. #include <itime.hpp>
  31. #include <icoordsy.hpp>
  32. #include "timehdr.hpp"
  33. #include "ownhdr.hpp"
  34. #include "ownhdr.h"
  35.  
  36. int main()
  37. {
  38.   ICoordinateSystem::setApplicationOrientation(
  39.           ICoordinateSystem::originLowerLeft );
  40.   MyWindow win;
  41.   IApplication::current().run();
  42.   return 0;
  43. }
  44.  
  45. /******************************************************************************
  46. * Class MyWindow :: MyWindow - Constructor for the main window                *
  47. *                                                                             *
  48. * Define yourself as an IFrameWindow                                          *
  49. * Create static text                                                          *
  50. * Create time handler                                                         *
  51. ******************************************************************************/
  52. MyWindow::MyWindow()
  53.   :IFrameWindow( "Create Your Own Handler Sample", ID_MAIN )
  54.   ,staticText( ID_TEXT, this, this )
  55.   ,timeHdr( &staticText )
  56. {
  57. /*-----------------------------------------------------------------------------
  58. | Begin handling timer events for this window                                 |
  59.  ----------------------------------------------------------------------------*/
  60.   timeHdr.handleEventsFor( this );
  61.  
  62. /*-----------------------------------------------------------------------------
  63. | Set the static text font                                                    |
  64. | Set the static text alignment to be center vertically and horizontally      |
  65.  ----------------------------------------------------------------------------*/
  66.   staticText.setFont( IFont( "Courier", 24 ) );
  67.   staticText.setAlignment( IStaticText::centerCenter );
  68.  
  69. /*-----------------------------------------------------------------------------
  70. | Set the application icon                                                    |
  71. | Set the client to the static text                                           |
  72. | Set focus to the frame window and show                                      |
  73.  ----------------------------------------------------------------------------*/
  74.   setIcon( ID_ICON );
  75.   setClient( &staticText );
  76.   setFocus().show();
  77. }
  78.  
  79.  
  80. /******************************************************************************
  81. * Class MyWindow :: ~MyWindow - Destructor for the main window                *
  82. *                                                                             *
  83. ******************************************************************************/
  84. MyWindow::~MyWindow()
  85. {
  86. /*-----------------------------------------------------------------------------
  87. | Stop handling timer events for this window                                  |
  88.  ----------------------------------------------------------------------------*/
  89.   timeHdr.stopHandlingEventsFor( this );
  90. }
  91.  
  92.  
  93. /******************************************************************************
  94. * Class MyTimeHandler :: MyTimeHandler - Constructor for an time handler      *
  95. *                                                                             *
  96. * Define yourself as an ATimeHandler                                          *
  97. * Store the static text pointer                                               *
  98. ******************************************************************************/
  99. MyTimeHandler::MyTimeHandler( IStaticText* staticText )
  100.   :ATimeHandler()
  101.   ,pText( staticText )
  102. {
  103. }
  104.  
  105. /******************************************************************************
  106. * Class MyTimeHandler :: tick - Override for time events                      *
  107. ******************************************************************************/
  108. IBase::Boolean MyTimeHandler::tick( IEvent& event )
  109. {
  110. /*-----------------------------------------------------------------------------
  111. | Set the static text to the current time                                     |
  112. | Return false indicating we didn't handle the event                          |
  113.  ----------------------------------------------------------------------------*/
  114.   pText->setText( ITime().asString() );
  115.   return false;
  116. }
  117.