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

  1. /******************************************************************************
  2. * .FILE:         msgbox.cpp                                                   *
  3. *                                                                             *
  4. * .DESCRIPTION:  Message Box Sample Program:  Class Implementation            *
  5. *                                                                             *
  6. * .CLASSES:      AMsgBoxDemo                                                  *
  7. *                                                                             *
  8. * .COPYRIGHT:                                                                 *
  9. *    Licensed Material - Program-Property of IBM                              *
  10. *    (C) Copyright IBM Corp. 1992, 1996 - All Rights Reserved                 *
  11. *                                                                             *
  12. * .DISCLAIMER:                                                                *
  13. *   The following [enclosed] code is sample code created by IBM               *
  14. *   Corporation.  This sample code is not part of any standard IBM product    *
  15. *   and is provided to you solely for the purpose of assisting you in the     *
  16. *   development of your applications.  The code is provided 'AS IS',          *
  17. *   without warranty of any kind.  IBM shall not be liable for any damages    *
  18. *   arising out of your use of the sample code, even if they have been        *
  19. *   advised of the possibility of such damages.                               *
  20. *                                                                             *
  21. * .NOTE: WE RECOMMEND USING A FIXED SPACE FONT TO LOOK AT THE SOURCE          *
  22. *                                                                             *
  23. ******************************************************************************/
  24. #include <ibase.hpp>
  25. #include <iapp.hpp>
  26. #include <ireslib.hpp>
  27. #include <icoordsy.hpp>
  28. #include "msgbox.hpp"
  29. #include "msgbox.h"
  30.  
  31. int main()
  32. {
  33.   ICoordinateSystem::setApplicationOrientation(
  34.           ICoordinateSystem::originLowerLeft );
  35.   #ifdef USE_IPF
  36.   IHelpWindow::setDefaultStyle( IHelpWindow::defaultStyle()
  37.                                 | IHelpWindow::ipfCompatible );
  38.   #endif
  39.   AMsgBoxDemo mbDisplay(WND_MAIN);
  40.   mbDisplay.sizeTo(ISize(800,300));
  41.   mbDisplay.runDemo();
  42.   IApplication::current().run();
  43.   return 0;
  44. } /* end main() */
  45.  
  46. /**************************************************************************
  47. * AMsbBoxDemo :: AMsgBoxDemo - Constructor                                *
  48. *                                                                         *
  49. * Construct the IFrameWindow using the default style.                     *
  50. * Create the IMultiLineEdit object with the default style and make it     *
  51. *   read only it is used only to display status.                          *
  52. * Create the message box owned by the frame window.                       *
  53. * Create the help window also owned by the frame window.                  *
  54. **************************************************************************/
  55.  
  56. AMsgBoxDemo :: AMsgBoxDemo( unsigned long windowId )
  57.         :IFrameWindow(windowId)
  58.         ,mbResponses(WND_MLE, this, this, IRectangle(),
  59.                 IMultiLineEdit::defaultStyle() | IMultiLineEdit::readOnly)
  60.         ,mb(this)
  61.         ,mbHelp(this)
  62. {
  63.  
  64. /*--------------------- Setup the User Interface Objects -----------------|
  65. |  Set the icon for the application.                                      |
  66. |  Use the addLibraries member function to identify which IPF help file   |
  67. |    contains the help information.                                       |
  68. |  Set the client window of the frame to the IMultiLineEdit window,       |
  69. |    size the frame, and show it.                                         |
  70. |  Set the titles for the help and message box windows.                   |
  71. |------------------------------------------------------------------------*/
  72.    setIcon( windowId );
  73.    try
  74.    {
  75.       mbHelp.addLibraries( "msgbox.hlp" );
  76.       mbHelp.setTitle(IResourceId(STR_HELPT));
  77.    }
  78.    catch( ... )
  79.    {
  80.       IMessageBox
  81.          msgBox( this );
  82.       msgBox.show( STR_HELP_NOT_FOUND, IMessageBox::warning );
  83.    }
  84.  
  85.    setClient(&mbResponses);
  86.    mb.setTitle(IResourceId(MSGBOX_TITLE));
  87. } /* AMsgBoxDemo::AMsgBoxDemo( ... ) */
  88.  
  89. AMsgBoxDemo& AMsgBoxDemo :: runDemo()
  90. {
  91.    show();
  92. /*--------------------- Message Box Samples Display Loop -----------------|
  93. |  Each time the message box is to be shown:                              |
  94. |    write a line to the status window describing the message box type,   |
  95. |    show the message box,                                                |
  96. |    trace the response to both the ITrace destination and status window. |
  97. |  Use a message box to determine whether to repeat the loop.             |
  98. |------------------------------------------------------------------------*/
  99.   IMessageBox::Response reply;
  100.   IResourceLibrary reslib;
  101.   do
  102.   {
  103.     mbResponses.addLineAsLast(reslib.loadString(MSGBOX_SAMPLE_1));
  104.     reply = mb.show( IResourceId( MSGBOX_OKCANCEL ),
  105.                      IMessageBox::okCancelButton |
  106.                      IMessageBox::informationIcon);
  107.     traceReply(reply);
  108.  
  109.     mbResponses.addLineAsLast(reslib.loadString(MSGBOX_SAMPLE_2));
  110.     reply = mb.show( IResourceId( MSGBOX_OKWARNING ),
  111.                      IMessageBox::okButton |
  112.                      IMessageBox::warningIcon);
  113.     traceReply(reply);
  114.  
  115.     mbResponses.addLineAsLast(reslib.loadString(MSGBOX_SAMPLE_3));
  116.     reply = mb.show( IResourceId( MSGBOX_CANCELERROR ),
  117.                      IMessageBox::cancelButton |
  118.                      IMessageBox::errorIcon);
  119.     traceReply(reply);
  120.  
  121.     mbResponses.addLineAsLast(reslib.loadString(MSGBOX_SAMPLE_4));
  122.     reply = mb.show( IResourceId( MSGBOX_YESNOCANCEL ),
  123.                      IMessageBox::yesNoCancelButton |
  124.                      IMessageBox::queryIcon);
  125.     traceReply(reply);
  126.  
  127.     mbResponses.addLineAsLast(reslib.loadString(MSGBOX_SAMPLE_5));
  128.     reply = mb.show( IResourceId( MSGBOX_YESNOCANCELHELP ),
  129.                      IMessageBox::yesNoCancelButton |
  130.                      IMessageBox::queryIcon |
  131.                      IMessageBox::moveable,
  132.                      MB_HELPID);
  133.     traceReply(reply);
  134.  
  135.     mbResponses.addLineAsLast(reslib.loadString(MSGBOX_SAMPLE_6));
  136.     reply = mb.show( IResourceId( MSGBOX_SYSMODAL ),
  137.                      IMessageBox::enterButton | IMessageBox::systemModal |
  138.                      IMessageBox::errorIcon);
  139.     traceReply(reply);
  140.  
  141. /*--------------------- Demonstrate Exception Messages -------------------|
  142. |  Call the throwException function to throw an IAccessError type of      |
  143. |    exception.                                                           |
  144. |  Catch the exception and show it in a message box.                      |
  145. |------------------------------------------------------------------------*/
  146.     mbResponses.addLineAsLast(reslib.loadString(MSGBOX_SAMPLE_7));
  147.     try
  148.     {
  149.       throwException();
  150.     }
  151.     catch( IException &exc)
  152.     {
  153.       reply = mb.show( exc );
  154.     }
  155.     traceReply(reply);
  156.  
  157.     reply = mb.show( IResourceId( MSGBOX_CONTINUE ),
  158.                       IMessageBox::yesNoButton |
  159.                       IMessageBox::queryIcon);
  160.  
  161.   } while (reply == IMessageBox::yes);
  162.  
  163. /*--------------------- Display Final Message Box ------------------------|
  164. |  Use the message box to display instructions for how to close the frame.|
  165. |------------------------------------------------------------------------*/
  166.   reply = mb.show( IResourceId( MSGBOX_END ),
  167.                    IMessageBox::okButton |
  168.                    IMessageBox::informationIcon);
  169.  
  170.   return (*this);
  171. } /* end AMsgBoxDemo :: runDemo() */
  172.  
  173.  
  174. /**************************************************************************
  175. * Class AMsgBoxDemo :: traceReply -  Generates IStrings corresponding to  *
  176. *   each IMessageBox enumeration and add the strings to the end of the    *
  177. *   status windows.                                                       *
  178. **************************************************************************/
  179. AMsgBoxDemo& AMsgBoxDemo :: traceReply( IMessageBox::Response response )
  180. {
  181.   IResourceLibrary reslib;
  182.   IString traceLine(reslib.loadString(STR_TRACE_LINE));
  183.   IString stringReply(reslib.loadString(STR_TRACE_REPLY));
  184.   switch (response)
  185.   {
  186.     case IMessageBox::enter:
  187.       stringReply += IString(reslib.loadString(STR_TRACE_ENTER));
  188.       break;
  189.     case IMessageBox::ok:
  190.       stringReply += IString(reslib.loadString(STR_TRACE_OK));
  191.       break;
  192.     case IMessageBox::cancel:
  193.       stringReply += IString(reslib.loadString(STR_TRACE_CANCEL));
  194.       break;
  195.     case IMessageBox::abort:
  196.       stringReply += IString(reslib.loadString(STR_TRACE_ABORT));
  197.       break;
  198.     case IMessageBox::retry:
  199.       stringReply += IString(reslib.loadString(STR_TRACE_RETRY));
  200.       break;
  201.     case IMessageBox::ignore:
  202.       stringReply += IString(reslib.loadString(STR_TRACE_IGNORE));
  203.       break;
  204.     case IMessageBox::yes:
  205.       stringReply += IString(reslib.loadString(STR_TRACE_YES));
  206.       break;
  207.     case IMessageBox::no:
  208.       stringReply += IString(reslib.loadString(STR_TRACE_NO));
  209.       break;
  210.     case IMessageBox::unknown:
  211.       stringReply += IString(reslib.loadString(STR_TRACE_UNKNOWN));
  212.       break;
  213.     default:
  214.       stringReply += IString(reslib.loadString(STR_TRACE_BAD));
  215.       break;
  216.   }
  217.   traceLine += stringReply;
  218.   IMODTRACE_ALL(traceLine);
  219.   mbResponses.addLineAsLast(stringReply)
  220.              .setCursorLinePosition(mbResponses.numberOfLines()-1)
  221.              .addLineAsLast(reslib.loadString(STR_SPACE));
  222.   return (*this);
  223. } /* end AMsgBoxDemo :: traceReply() */
  224.  
  225.  
  226. /**************************************************************************
  227. * Class AMsgBoxDemo::throwException - Generates an IAccessError type of   *
  228. *   exception to demonstrate use of the  IException type of message box.  *
  229. **************************************************************************/
  230. AMsgBoxDemo& AMsgBoxDemo :: throwException()
  231. {
  232.   ITHROWLIBRARYERROR( IC_MEMBER_ACCESS_ERROR ,
  233.                       IBaseErrorInfo::accessError,
  234.                       IException::recoverable);
  235.   return *this;
  236. } /* end AMsgBoxDemo :: throwException() */
  237.