home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 10 Tools
/
10-Tools.zip
/
VSCPPv8.zip
/
VACPP
/
IBMCPP
/
samples
/
IOC
/
MSGBOX
/
MSGBOX.CPP
< prev
next >
Wrap
C/C++ Source or Header
|
1995-05-01
|
11KB
|
249 lines
/*****************************************************************************
* FILE NAME: msgbox.cpp (Message Box Sample Program) *
* *
* COPYRIGHT: Copyright (C) International Business Machines Corp., 1992,1995. *
* *
* DISCLAIMER OF WARRANTIES: *
* The following [enclosed] code is sample code created by IBM *
* Corporation. This sample code is not part of any standard IBM product *
* and is provided to you solely for the purpose of assisting you in the *
* development of your applications. The code is provided "AS IS", *
* without warranty of any kind. IBM shall not be liable for any damages *
* arising out of your use of the sample code, even if they have been *
* advised of the possibility of such damages. *
*****************************************************************************/
//NOTE: WE RECOMMEND USING A FIXED-SPACE FONT TO LOOK AT THE SOURCE.
/**************************************************************************
* IBM User Interface Class Library - Message Box Sample *
* The purpose of this sample application is to show various types of *
* message boxes. A frame window with an IMultiLineEdit client window *
* is used to display information about the progress of the sample. *
* Information is also traced to the trace destination. Tracing *
* information is turned on by setting the ICLUI_TRACE environment *
* variable to ON and the destination is set using the ICLUI_TRACETO *
* environment variable. *
**************************************************************************/
//Include User Interface Class Library class headers:
#ifndef _IBASE_ //Make sure ibase.hpp is included
#include <ibase.hpp> // since that is where IC_<environ>
#endif // is defined.
#ifndef _IAPP_
#include <iapp.hpp> //Include IApplication class header
#endif
#include "msgbox.hpp" //Include AMsgBoxDemo class header
#include "msgbox.h" //Include symbolic definitions
int main()
{
/*--------------------- Create Demo Object and Run It --------------------|
| Create an object from the AMsgBoxDemo class with window ID, WND_MAIN. |
| Size the frame window used to display the demo status. |
| Begin the demonstration; runDemo performs the show for the frame. |
| Begin processing events for the window. This allows the user to |
| interact with the frame window after the demo has completed. |
|------------------------------------------------------------------------*/
AMsgBoxDemo mbDisplay(WND_MAIN);
mbDisplay.sizeTo(ISize(800,300));
mbDisplay.runDemo();
IApplication::current().run();
return 0;
} /* end main() */
/**************************************************************************
* AMsbBoxDemo :: AMsgBoxDemo - Constructor *
* Construct the IFrameWindow using the default style. *
* Create the IMultiLineEdit object with the default style and make it *
* read only it is used only to display status. *
* Create the message box owned by the frame window. *
* Create the help window also owned by the frame window. *
**************************************************************************/
AMsgBoxDemo :: AMsgBoxDemo( unsigned long windowId )
:IFrameWindow(windowId)
,mbResponses(WND_MLE, this, this, IRectangle(),
IMultiLineEdit::defaultStyle() | IMultiLineEdit::readOnly)
,mb(this)
,mbHelp(this)
{
/*--------------------- Setup the User Interface Objects -----------------|
| Set the icon for the application. |
| Use the addLibraries member function to identify which IPF help file |
| contains the help information. |
| Set the client window of the frame to the IMultiLineEdit window, |
| size the frame, and show it. |
| Set the titles for the help and message box windows. |
|------------------------------------------------------------------------*/
setIcon( windowId );
try
{
mbHelp.addLibraries( "msgbox.hlp" );
mbHelp.setTitle(IResourceId(STR_HELPT));
}
catch( ... )
{
IMessageBox
msgBox( this );
msgBox.show( STR_HELP_NOT_FOUND, IMessageBox::warning );
}
setClient(&mbResponses);
mb.setTitle(IResourceId(MSGBOX_TITLE));
}
AMsgBoxDemo
&AMsgBoxDemo :: runDemo()
{
show(); //Show the message box status frame
/*--------------------- Message Box Samples Display Loop -----------------|
| Each time the message box is to be shown: |
| write a line to the status window describing the message box type, |
| show the message box, |
| trace the response to both the ITrace destination and status window. |
| Use a message box to determine whether to repeat the loop. |
|------------------------------------------------------------------------*/
IMessageBox::Response
reply;
do
{
mbResponses.addLineAsLast(
"Message Box Sample 1 - okCancelButton and informationIcon");
reply = mb.show( IResourceId( MSGBOX_OKCANCEL ),
IMessageBox::okCancelButton |
IMessageBox::informationIcon);
traceReply(reply);
mbResponses.addLineAsLast(
"Message Box Sample 2 - okButton and warningIcon");
reply = mb.show( IResourceId( MSGBOX_OKWARNING ),
IMessageBox::okButton |
IMessageBox::warningIcon);
traceReply(reply);
mbResponses.addLineAsLast(
"Message Box Sample 3 - cancelButton and errorIcon");
reply = mb.show( IResourceId( MSGBOX_CANCELERROR ),
IMessageBox::cancelButton |
IMessageBox::errorIcon);
traceReply(reply);
mbResponses.addLineAsLast(
"Message Box Sample 4 - yesNoCancelButton and queryIcon");
reply = mb.show( IResourceId( MSGBOX_YESNOCANCEL ),
IMessageBox::yesNoCancelButton |
IMessageBox::queryIcon);
traceReply(reply);
mbResponses.addLineAsLast(
"Message Box Sample 5 - yesNoCancelButton, queryIcon, moveable, helpId");
reply = mb.show( IResourceId( MSGBOX_YESNOCANCELHELP ),
IMessageBox::yesNoCancelButton |
IMessageBox::queryIcon |
IMessageBox::moveable,
MB_HELPID);
traceReply(reply);
mbResponses.addLineAsLast(
"Message Box Sample 6 - enterButton, systemModal, and errorIcon");
reply = mb.show( IResourceId( MSGBOX_SYSMODAL ),
IMessageBox::enterButton | IMessageBox::systemModal |
IMessageBox::errorIcon);
traceReply(reply);
/*--------------------- Demonstrate Exception Messages -------------------|
| Call the throwException function to throw an IAccessError type of |
| exception. |
| Catch the exception and show it in a message box. |
|------------------------------------------------------------------------*/
mbResponses.addLineAsLast(
"Message Box Sample 7 - exception (from generated IAccessError)");
try
{
throwException();
}
catch( IException &exc)
{
reply = mb.show( exc );
}
traceReply(reply);
reply = mb.show( IResourceId( MSGBOX_CONTINUE ),
IMessageBox::yesNoButton |
IMessageBox::queryIcon);
} while (reply == IMessageBox::yes);
/*--------------------- Display Final Message Box ------------------------|
| Use the message box to display instructions for how to close the frame.|
|------------------------------------------------------------------------*/
reply = mb.show( IResourceId( MSGBOX_END ),
IMessageBox::okButton |
IMessageBox::informationIcon);
return (*this);
} /* end AMsgBoxDemo :: runDemo() */
/********************** Format the Message Box Response *******************
* Generate IStrings corresponding to each IMessageBox enumeration. *
* Trace the string reply to the ITrace destination. *
* Add the response to the end of the status window. *
**************************************************************************/
AMsgBoxDemo
&AMsgBoxDemo :: traceReply( IMessageBox::Response response )
{
IString traceLine("traceReply * ");
IString stringReply("response = ");
switch (response)
{
case IMessageBox::enter:
stringReply += IString("enter");
break;
case IMessageBox::ok:
stringReply += IString("ok");
break;
case IMessageBox::cancel:
stringReply += IString("cancel");
break;
case IMessageBox::abort:
stringReply += IString("abort");
break;
case IMessageBox::retry:
stringReply += IString("retry");
break;
case IMessageBox::ignore:
stringReply += IString("ignore");
break;
case IMessageBox::yes:
stringReply += IString("yes");
break;
case IMessageBox::no:
stringReply += IString("no");
break;
case IMessageBox::unknown:
stringReply += IString("unknown");
break;
default:
stringReply += IString("bad reply");
break;
}
traceLine += stringReply;
IMODTRACE_ALL(traceLine);
mbResponses.addLineAsLast(stringReply)
.setCursorLinePosition(mbResponses.numberOfLines()-1)
.addLineAsLast(" ");
return (*this);
} /* end AMsgBoxDemo :: traceReply() */
/********************** Format the Message Box Response *******************
* Generate an IAccessError type of exception to demonstrate use of the *
* IException type of message box. *
**************************************************************************/
void
AMsgBoxDemo :: throwException()
{
ITHROWLIBRARYERROR( IC_MEMBER_ACCESS_ERROR ,
IErrorInfo::accessError,
IException::recoverable);
} /* end AMsgBoxDemo :: throwException() */