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

  1. //*********************************************************
  2. // Frame Window Closing - Confirm Frame Closing
  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 <imsgbox.hpp>
  11. #include <istattxt.hpp>
  12. #include <isysmenu.hpp>
  13. #include <ithread.hpp>
  14.  
  15. class CloseHandler : public ICommandHandler {
  16. public:
  17. // Use this function to attach this handler to your frame.
  18. virtual CloseHandler
  19.  &handleClosingOf( IFrameWindow& frame )
  20.   {
  21.     this->ICommandHandler::handleEventsFor( &frame );
  22.     return *this;
  23.   }
  24. // Override this function to insert your own "close" logic.
  25. virtual Boolean
  26.   systemCommand ( ICommandEvent& event )
  27.   {
  28.     Boolean
  29.       stopProcessingEvent = false;
  30.     if ( event.commandId() == ISystemMenu::idClose )
  31.     {
  32.        IFrameWindow
  33.         *frame = (IFrameWindow*)( event.dispatchingWindow() );
  34.        IMessageBox
  35.          prompt( frame );
  36.        const char
  37.         *text = "Press Cancel to keep the window open. "
  38.                 "Press OK to let it close.";
  39.        IMessageBox::Response
  40.          rc = prompt.show( text,
  41.                            IMessageBox::okCancelButton
  42.                              | IMessageBox::informationIcon
  43.                              | IMessageBox::moveable );
  44.        if ( rc == IMessageBox::cancel )
  45.        {
  46.           stopProcessingEvent = true;
  47.        }
  48.     }
  49.     return stopProcessingEvent;
  50.   }
  51. private:
  52. virtual IHandler
  53.  &handleEventsFor( IWindow* window )
  54.   {
  55.     return this->ICommandHandler::handleEventsFor( window );
  56.   }
  57. }; // CloseHandler
  58.  
  59. void main ( )
  60. {
  61.   IFrameWindow
  62.     frame( "Confirm on Close" );
  63.   IStaticText
  64.     client( IC_FRAME_CLIENT_ID, &frame, &frame );
  65.   client
  66.    .setAlignment( IStaticText::centerCenter )
  67.    .setText( "Press Alt+F4 to close this window." );
  68.   frame
  69.    .setClient( &client );
  70.  
  71.   CloseHandler
  72.     closeHandler;
  73.   closeHandler
  74.    .handleClosingOf( frame );
  75.  
  76.   frame
  77.    .setFocus()
  78.    .show();
  79.  
  80.   IThread::current().processMsgs();
  81. }
  82.