home *** CD-ROM | disk | FTP | other *** search
/ Power GUI Programming with VisualAge C++ / powergui.iso / powergui / frame1 / dismiss / dismiss.cpp next >
Encoding:
C/C++ Source or Header  |  1996-10-29  |  2.1 KB  |  85 lines

  1. //*********************************************************
  2. // Frame Window Basics - Dismissing a Window
  3. //
  4. // Copyright (C) 1994, Law, Leong, Love, Olson, Tsuji.
  5. // Copyright (c) 1997 John Wiley & Sons, Inc. 
  6. // All Rights Reserved.
  7. //*********************************************************
  8. #include <icmdhdr.hpp>
  9. #include <iframe.hpp>
  10. #include <ipushbut.hpp>
  11. #include <istattxt.hpp>
  12. #include <istring.hpp>
  13. #include <icconst.h>
  14.  
  15. #ifdef IC_PM
  16.   // Define the system command identifier not originally
  17.   // included in VisualAge for C++ for OS/2, V3.0.
  18.   #ifndef IC_ID_CLOSE
  19.     #define IC_ID_CLOSE  0x8004
  20.   #endif
  21. #endif
  22.  
  23. #define AGAIN_CMD  100
  24.  
  25. class CmdHandler : public ICommandHandler {
  26. public:
  27.   CmdHandler ( IFrameWindow& frame )
  28.     : frame( frame )
  29.   {
  30.     this->handleEventsFor( &frame );
  31.   }
  32. protected:
  33. virtual Boolean
  34.   command ( ICommandEvent& event )
  35.   {
  36.     Boolean
  37.       stopProcessingEvent = false;
  38.     if ( event.commandId() == AGAIN_CMD )
  39.     {
  40.        frame.dismiss( event.commandId() );
  41.        stopProcessingEvent = true;
  42.     }
  43.     return stopProcessingEvent;
  44.   }
  45. private:
  46. CmdHandler
  47.  &operator= ( CmdHandler& );
  48. IFrameWindow
  49.  &frame;
  50. }; // CmdHandler
  51.  
  52. void main ( )
  53. {
  54.   IFrameWindow
  55.     frameWindow( "Using IFrameWindow::dismiss" );
  56.   IStaticText
  57.     text( IC_FRAME_CLIENT_ID, &frameWindow, &frameWindow );
  58.   frameWindow
  59.    .setClient( &text );
  60.  
  61.   IPushButton
  62.     againButton( AGAIN_CMD, &frameWindow, &frameWindow );
  63.   againButton
  64.    .setText( "Show the window again." );
  65.   frameWindow
  66.    .addExtension( &againButton,
  67.                   IFrameWindow::belowClient );
  68.  
  69.   CmdHandler
  70.     handler( frameWindow );
  71.  
  72.   // Keep displaying the frame window until the user has
  73.   // closed it via some means other than the "Again"
  74.   // push button (for example, pressing Alt+F4).
  75.   frameWindow
  76.    .setResult( AGAIN_CMD);
  77.   for ( int i = 1; frameWindow.result() == AGAIN_CMD; i++ )
  78.   {
  79.      text.setText( "Display Number " + IString( i ) );
  80.      frameWindow.setResult( IC_ID_CLOSE );
  81.      frameWindow.setFocus();
  82.      frameWindow.showModally();
  83.   }
  84. }
  85.