home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 10 Tools
/
10-Tools.zip
/
ICLUI.ZIP
/
HELLO6
/
AHELLOW6.CPP
< prev
next >
Wrap
C/C++ Source or Header
|
1993-03-09
|
68KB
|
908 lines
/******************************************************************************/
/* HELLO WORLD SAMPLE PROGRAM - Version 6: Class Implementation (AHELLOW6.CPP)*/
/* */
/* COPYRIGHT: Copyright (C) International Business Machines Corp., 1992,1993. */
/* */
/* 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
//**************************************************************************
// C++ Hello World History and Key Functions: *
// Version 1: *
// - Creates and runs a simple application *
// - Creates the main window (IFrameWindow) *
// - Creates a static text control set to "Hello, World!" as the *
// client window *
// *
// Version 2: (lines with v2 in column 79-80) * v2
// - Create Main Window (AHellowWindow) as subclass of IFrameWindow * .
// - Gets the "Hello, World!!" text string and other items from a * .
// resource file * .
// - Sets the window title from a resource file * .
// - Creates and sets the information area at the bottom of the * .
// client area * v2
// *
// Version 3: (lines with v3 in column 79-80) * v3
// - Add Alignment (Left, Center, Right) Menu Bar * .
// - Add Command Processing to set the "Hello, World" alignment * .
// - Place check in front of the Left, Center or Right Menu Item * .
// - Create and maintain Status Line with current alignment status * v3
// *
// Version 4: (lines with v4 in column 79-80) * v4
// - Add Accelerator Keys for Left (F7), Center(F8), Right(F9) * .
// - Modify Left, Center and Right Menu Items to show function key * .
// - Modify Menu Bar to create Edit Menu and "text..." Menu Item * .
// - Add ADialogText to allow user to change "Hello, World" text * .
// - Add Push Buttons & Set Canvas to change alignment * v4
// *
// Version 5: (lines with v5 in column 79-80) * v5
// - Code a new control (AEarthWindow) using PM Graphics calls * .
// - Add AEarthWindow to the bottom of the client area * .
// - Add Help Windows for the Main, Dialog, Entry Field Windows * .
// - Use Split Canvas as the Client Area * .
// - Add ListBox to Client Area to change "Hello, World" text * v5
// *
// Version 6: (lines with v6 in column 79-80) * v6
// - Command Line option to use Enlish or Portuguese DLL resources * .
// - Add Open Menu Item and use File Dialog * .
// - Show MessageBox when can not read input file from File Dialog * .
// - Add Menu PopUp for changing the alignment * .
// - Change Status Area to Split Canvas and add Date & Time * .
// - Add ATimeHandler & Update Time in Status Area * .
// - Add HELLOWPS.CMD to create Workplace Folder with Programs * v6
//**************************************************************************
//Include IBM UI class headers:
#include <iapp.hpp> //IApplication Class
#include <istattxt.hpp> //IStaticText Class
#include <imenubar.hpp> //IMenuBar Class v3
#include <istring.hpp> //IString Class v4
#include <ihelp.hpp> //IHelpWindow Class v5
#include <ihelphdr.hpp> //IHelpHandler Class v5
#include <isplitcv.hpp> //ISplitCanvas Class v5
#include <isetcv.hpp> //ISetCanvas Class v4
#include <ipushbut.hpp> //IPushButton Class v4
#include <iinfoa.hpp> //IInfoArea Class v2
#include <imsgbox.hpp> //IMessageBox Class v6
#include <ifiledlg.hpp> //IFileDialog v6
#include <ifontdlg.hpp> //IFontDialog v6
#include <imenuevt.hpp> //IMenuEvent v6
#include <ipopmenu.hpp> //IPopUpMenu v6
#include <icolor.hpp> //IColor v6
#include <ilistbox.hpp> //IListBox v5
#include <inotebk.hpp> //INoteBook v6
#include <idate.hpp> //IDate v6
#include <itime.hpp> //ITime v6
#include <ifont.hpp> //IFont v3
#include <iprofile.hpp> //IProfile v6
#include <ithread.hpp> //IThread for Timer Call to PM v6
#define INCL_WINTIMER //Include OS/2 Timer Calls v6
#include <os2.h> //os/2.h to call beep if error v6
#include <iostream.h> //iostream v6
#include <fstream.h> //fstream v6
#include <stdlib.h> //stdlib v6
#include "ahellow6.hpp" //Include AHelloWindow Class headers v2
#include "ahellow6.h" //Include our Symbolic definitions v2
#include "adialog6.hpp" //ATextDialog Class v4
#include "aearthw6.hpp" //AEarthWindow Class v5
#include "acolorw6.hpp" //AColorWindow Class v6
#include "aspeedw6.hpp" //ASpeedWindow Class v6
//*************************************************************************
// main - Application entry point *
//*************************************************************************
int main(int argc, char **argv) //Main Procedure with no parameters v6
{
IString dllName("AHELLOW"); //Get Base DLL Name v6
IString langKey("E"); //Language Key .
IString langOption(""); //Language Option .
int i, imax; //Loop variables v6
IApplication::current(). //Get current v6
setArgs(argc, argv); // and set command line parameters .
IThread::current().initializePM(); // Initialize PM environment. .
imax=IApplication::current().argc(); //Get number of command line parms .
for (i=1; i < imax; ++i) //Check input command parameters .
{ // .
langOption=IApplication::current() //Get current application and .
.argv(i).upperCase(); // command line argument as upper case.
if (langOption.isAbbreviationFor( //If Portuguese Option Then .
"/PORTUGUESE", 2)) // .
langKey = IString('P'); // Set to load Portuguese DLL .
} /* endfor */ // .
dllName+=langKey; //Add Language Letter to DLL Name .
try //Try to set the user resource DLL .
{ // .
IApplication::current(). //Get current application .
setUserResourceLibrary(dllName); // Set the Name of Resoure DLL .
} // .
catch (IException& exc) //Catch Error trying to load DLL .
{ //DLL probably not in libpath .
DosBeep(750,1000) ; //Report Error via beep .
IFrameWindow * msgWindow=new //Create our main window on the desktop.
IFrameWindow(0x1000); // Pass in our Window ID .
IStaticText * msg=new IStaticText( //Create static text control with .
0x1010, msgWindow, msgWindow); // msgWindow as owner & parent .
msg->setText( //Set the text in Static Text Control .
"Can not load ResourcDLL"); // .
msg->setAlignment( //Set Alignment to Center in both .
IStaticText::centerCenter); // directions .
msgWindow->sizeTo(ISize(400,300)); //Set the size of the window .
msgWindow->setClient(msg); //Set hello control as Client Window .
msgWindow->setFocus(); //Set focus to msg window .
msgWindow->show(); //Set to show msg window .
IApplication::current().run(); //Get the current application and .
exit(3) ; //Exit Program with error .
} // v6
AHelloWindow mainWindow (WND_MAIN); //Create our main window on the
// desktop
IApplication::current().run(); //Get the current application and
// run it
} /* end main */
//**************************************************************************
// AHelloWindow :: AHelloWindow - Constructor for our main window *
//**************************************************************************
AHelloWindow :: AHelloWindow(unsigned long windowId)
: IFrameWindow ( //Call IFrameWindow constructor v2
IFrameWindow::defaultStyle() // Use default plus v2
| IFrameWindow::minimizedIcon // Get Minimized Icon from RC file v2
| IFrameWindow::accelerator // Get Accelerator Table from RC filev4
| IFrameWindow::animated, // Set to show with "animation" v6
windowId) // Main Window ID
{
filename=NULL; //Set to fileName to NULL v6
color=NULL; //Set color window to NULL .
demo=false; //Demo is off .
demoIndex=0; //Set Demo Index to Zero .
demoTicks=3; //Set Ticks per Demo Code v6
setupClient(); //Setup Client Window v5
setupStatusArea(); //Setup Status Area .
setupInfoArea(); //Setup Information Area v5
setupButtons(); //Setup Buttons v4
setupMenuBar(); //Setup Menu Bar v5
setupHelp(); //Setup Help v5
// readProfile(); //Read Profile v6
sizeTo(ISize(500,400)); //Set the size of main window v2
setFocus(); //Set focus to main window
show(); //Set to show main window
ATimeHandler::handleEventsFor(this); //Set self as time handler v6
} /* end AHelloWindow :: AHelloWindow(...) */
//************************************************************************** v6
// AHelloWindow :: AHelloWindow - Destructor for our main window * .
//************************************************************************** .
AHelloWindow :: ~AHelloWindow() //Destructor for AHelloWindow .
{ // .
ATimeHandler::stopHandlingEventsFor(this);//Stop Timer .
} /* end AHelloWindow :: ~AHelloWindow(...) */ //v6
//************************************************************************** v6
// AHelloWindow :: speed() * .
//************************************************************************** .
int AHelloWindow :: speed() // .
{ // .
return demoTicks; // .
} /* end AHelloWindow :: speed() */ //v6
//************************************************************************** v6
// AHelloWindow :: setSpeed() * .
//************************************************************************** .
Boolean AHelloWindow :: setSpeed(int value) //Set Demo Speed .
{ // .
demoTicks=value; //Set the demo ticks .
demoCount=value; //Set the current demo counter .
return true; // .
} /* end AHelloWindow :: setSpeed() */ //v6
//************************************************************************** v4
// AHelloWindow :: setupButtons * .
// Setup Buttons * .
//************************************************************************** .
Boolean AHelloWindow :: setupButtons() //Setup Buttons .
{ // .
ISetCanvas * buttons; //Define canvas of buttons .
IPushButton * helpButton; //Define Help Button .
// .
buttons=new ISetCanvas(WND_BUTTONS, //Create a Set Canvas for Buttons .
this, this) ; // Parent and Owner=me .
buttons->setMargin(ISize()); //Set Canvas Margins to zero .
buttons->setPad(ISize()); //Set Button Canvas Pad to zero .
leftButton=new IPushButton(MI_LEFT, //Create Left Push Button .
buttons, buttons, IRectangle(), // Parent, Owner=Button Canvas .
IPushButton::defaultStyle() | // Use Default Styles plus .
IControl::tabStop); // tabStop .
leftButton->setText(STR_LEFTB); //Set Left Button Text .
centerButton=new IPushButton(MI_CENTER,//Create Left Push Button .
buttons, buttons, IRectangle(), // Parent, Owner=Button Canvas .
IPushButton::defaultStyle() | // Use Default Styles plus .
IControl::tabStop); // tabStop .
centerButton->setText(STR_CENTERB); //Set Center Button Text .
rightButton=new IPushButton(MI_RIGHT, //Create Right Push Button .
buttons, buttons, IRectangle(), // Parent, Owner=Button Canvas .
IPushButton::defaultStyle() | // Use Default Styles plus .
IControl::tabStop); // tabStop .
rightButton->setText(STR_RIGHTB); //Set Right Button Text v4
helpButton=new IPushButton(MI_HELP, //Create Right Push Button v5
buttons, buttons, IRectangle(), // Parent, Owner=Button Canvas .
IPushButton::defaultStyle() | // Use Default Styles plus .
IPushButton::help | // Help Style .
IControl::tabStop); // tabStop .
helpButton->setText(STR_HELPB); //Set Help Button Text v5
addExtension(buttons, //Add Buttons below client area v4
IFrameWindow::belowClient, // below client and .
30UL); // unsigned long height in pixels .
return true; //Return .
} /* end AHelloWindow :: setupButtons() */ //v4
//************************************************************************** v5
// AHelloWindow :: setupHelp() * .
// Setup Help * .
//************************************************************************** .
Boolean AHelloWindow :: setupHelp() //Setup Help Area .
{ // .
help=new IHelpWindow(HELP_TABLE, //Create Help Window Object .
this); //Setup Help info .
help->addLibraries("AHELLOW6.HLP"); // set self, help table filename .
help->setTitle(STR_HTITLE); //Set the Help Window Title .
// .
AHelpHandler* phelpHandler= //Create Custon Help Handler to .
new AHelpHandler(); // handle the Keys Help .
phelpHandler->handleEventsFor(this); //Start Help Handler .
return true; // .
} /* end AHelloWindow :: setupHelp() */ //v5
//************************************************************************** v5
// AHelloWindow :: setupClient() * .
// Setup Client * .
//************************************************************************** .
Boolean AHelloWindow :: setupClient() //Setup Client Window .
{ // .
clientWindow=new ISplitCanvas( //Create Canvas .
WND_CANVAS, this, this); // with Window Id, parent, owner .
setClient(clientWindow); //Set canvas as Client Window .
helloCanvas=new ISplitCanvas( //Create Hello Canvas .
WND_HCANVAS, clientWindow, // with Window Id, parent .
clientWindow); // and owner .
helloCanvas->setOrientation( //Set the orientation .
ISplitCanvas::horizontalSplit); // to horizontal .
hello=new IStaticText(WND_HELLO, //Create Static Text Control
helloCanvas, helloCanvas); // Pass in client as owner & parent v6
earthWindow=new AEarthWindow //Create Earth Graphic Window v5
(WND_EARTH, helloCanvas); // Set Window ID, client-owner/parentv6
AMenuHandler * mh=new AMenuHandler(); //Create Menu Handler v6
mh->handleEventsFor(hello); //Set Menu Handler for hello .
ICommandHandler::handleEventsFor(hello);//Set self as command event handler v6
hello->setText(STR_HELLO); //Set text v2
IFont tempFont("Helv", 16); //Create Temp. Font v6
hello->setFont(tempFont); //Set Font for "Hello, World" Text v6
if (IApplication::current().argc()>1) //Check number of command line parms v6
{ // .
filename= // .
IApplication::current().argv(1); //Get filename for command line .
ifstream infile(filename); //Input file stream .
if (infile) //Does file exist? .
{ // Yes, File does exist .
cin=infile.rdbuf(); // Set cin to infile .
hello->setText(IString().lineFrom(cin));//Set text in Static Text Control.
infile.close(); // Close input file .
} // .
} /* endif */ // v6
hello->setAlignment( //Set Alignment to Center in both
IStaticText::centerCenter); // directions
listBox=new IListBox(WND_LISTBOX, //Create ListBox v5
clientWindow, clientWindow, // Parent/Owner is ClientWindow .
IRectangle(), // .
IListBox::defaultStyle() | // .
IControl::tabStop | // Set Tab Stop .
IListBox::noAdjustPosition); // Allow the Canvas to control size .
listBox->addAsc("Hello, World!"); //Add "Hello, World!" .
listBox->addAsc("Hi, World!"); //Add "Hi, World!" .
listBox->addAsc("Howdy, World!"); //Add "Howdy, World!" .
listBox->addAsc("Alo, Mundo!"); //Add Portuguese Version .
listBox->addAsc("Ola, Mondo!"); //Add Spain .
listBox->addAsc("Hallo wereld!"); //Add Dutch .
listBox->addAsc("Hallo Welt!"); //Add German .
listBox->addAsc("Bonjour le monde!"); //Add French .
ISelectHandler::handleEventsFor(listBox);//Set self as select event handler v5
clientWindow->setSplitWindowPercentage(//Set the Window Percentage for v5
helloCanvas, 60); // the helloCanvas to 60 .
clientWindow->setSplitWindowPercentage(//Set the Window Percentage for .
listBox, 40); // the listBox to 40 v5
return true; // v5
} /* end AHelloWindow :: setupClient() */ //v5
//************************************************************************** v5
// AHelloWindow :: setupInfoArea() * .
// Setup Information Area * .
//************************************************************************** .
Boolean AHelloWindow :: setupInfoArea() //Setup Information Area .
{ // v5
infoArea=new IInfoArea(this); //Create the information area v2
infoArea->setInactiveText(STR_INFO); //Set information area text from RC v2
setExtensionSize(infoArea, // v5
(int)IFont(infoArea).maxCharHeight());//and specify height .
return true; // .
} /* end AHelloWindow :: setupInfoArea() */ //v5
//************************************************************************** v5
// AHelloWindow :: setupMenuBar() * .
// Setup Menu Bar * .
//************************************************************************** .
Boolean AHelloWindow :: setupMenuBar() //Setup Menu Bar .
{ // .
ICommandHandler::handleEventsFor(this);//Set self as command event handler v5
menuBar=new IMenuBar(WND_MAIN, //Create Menu Bar for main window v3
this); // Set self as parent .
menuBar->checkItem(MI_CENTER); //Place Check on Center Menu Item v3
menuBar->disableItem(MI_DEMO_STOP); //Disable Stop Menu Item v6
return true; // v5
} /* end AHelloWindow :: setupMenuBar() */ //v5
//************************************************************************** v5
// AHelloWindow :: setupStatusArea() * .
// Setup Statue Area * .
//************************************************************************** .
Boolean AHelloWindow :: setupStatusArea()//Setup Status Area v5
{ // v6
statusCanvas=new ISplitCanvas //Create Status Canvas with v6
(WND_STATUSCANVAS, this, this); // Parent/Owner=me v6
statusLine = new IStaticText //Create Status Area using Static Textv3
(WND_STATUS, statusCanvas, // Window ID, owner, parent v3
statusCanvas); // v6
statusLine->setText(STR_CENTER); //Set Status Text to "Center" from Resv3
date = new IStaticText //Create Date using Static Text v6
(WND_TIME, statusCanvas, // Window ID, owner, parent .
statusCanvas); // .
date->setText(IDate().asString()); //Set Text to current date v6
time = new IStaticText //Create Time using Static Text v6
(WND_DATE, statusCanvas, // Window ID, owner, parent .
statusCanvas); // .
time->setText(ITime().asString()); //Set Text to current time v6
statusCanvas->setSplitWindowPercentage(//Set the Window Percentage for v6
statusLine, 50); // statusLine .
statusCanvas->setSplitWindowPercentage(//Set the Window Percentage for .
date, 25); // date .
statusCanvas->setSplitWindowPercentage(//Set the Window Percentage for .
time, 25); // time v6
addExtension(statusCanvas, //Add Status Canvas v6
IFrameWindow::aboveClient, // above the client window v3
IFont(statusLine).maxCharHeight()); // and specify height v6
return true; // v6
} /* end AHelloWindow :: setupStatusArea() */ //v6
//************************************************************************** v5
// AHelloWindow :: selected(...) * .
// Handle selected command from list box * .
// * .
// Note: It would be easy to change this selected member function to enter * .
//************************************************************************** .
Boolean AHelloWindow :: selected(IControlEvent & evt) // .
{ // .
IListBox::Cursor lbCursor(*listBox); //List Box Cursor .
lbCursor.setToFirst(); //Set to first item selected .
setText(listBox->elementAt(lbCursor));//Set Hello Text to Selected Item .
return true; //Return Command Processed .
} /* end AHelloWindow :: selected(...) */ //v5
//************************************************************************** v3
// AHelloWindow :: command * .
// Handle menu commands * .
//************************************************************************** .
Boolean AHelloWindow :: command(ICommandEvent & cmdEvent) // .
{ //v3
switch (cmdEvent.commandId()) { //Get command id v3
case MI_CENTER: //Code to Process Center Command Item v3
return setCenterAlignment(); // Set Center Alignment and Return v6
break; // v3
case MI_LEFT: //Code to Process Left Command Item v3
return setLeftAlignment(); // Set Left Alignment and Return v6
break; // v3
case MI_RIGHT: //Code to Process Right Command Item v3
return setRightAlignment(); // Set Right Alignment and Return v6
break; // v3
case MI_TEXT: //Code to Process Text Command v4
return openText(); // Open Text Dialog and Return v6
break; // v4
case MI_GENERAL_HELP: //Code to Process Help for help v5
help->show(IHelpWindow::general); //Show General Help Panel .
return(true); //Return command processed .
break; // v5
case MI_OPEN: //Code to Process Open v6
return openFile(); // Open File and Return .
break; // v6
case MI_DEMO_START: //Code to Process Demo Start v6
return startDemo(); // Call and Return .
break; // v6
case MI_DEMO_STOP: //Code to Process Demo Stop v6
return stopDemo(); // Call and Return .
break; // v6
case MI_DEMO_SPEED: //Code to Process Demo Speed... v6
return openSpeed(); // Call and Return .
break; // v6
case MI_COLOR: //Code to Process Color Menu v6
return openColor(); // Call and Return .
break; // v6
case MI_FONT: //Code to Process Font Menu v6
return openFont(); // Call and Return .
break; // v6
case MI_READ_PROFILE: //Code to Process Read Profile Menu IDv6
return readProfile(); //Read Profile .
break; // v6
case MI_UPDATE_PROFILE: //File Update Profile Menu ID v6
return updateProfile(); // Call and Return .
break; // v6
} /* end switch */ // v3
return(false); //Return command not processed v3
} /* end AHelloWindow :: command(...) */ //v3
//************************************************************************** v6
// AHelloWindow :: setLeftAlignment() * .
// Set Left Alignment * .
//************************************************************************** .
Boolean AHelloWindow :: setLeftAlignment()//Set Left Alignment .
{ // .
hello->setAlignment( //Set alignment of hello text to v3
IStaticText::centerLeft); // center-vertical, left-horizontal .
statusLine->setText(STR_LEFT); //Set Status Text to "Left" from Res .
menuBar->uncheckItem(MI_CENTER); //Uncheck Center Menu Item .
menuBar->checkItem(MI_LEFT); //Place Check on Left Menu Item .
menuBar->uncheckItem(MI_RIGHT); //Uncheck Right Menu Item v3
return true; //Return v6
} /* end AHelloWindow :: setLeftAlignmnet() */ //v6
//************************************************************************** v6
// AHelloWindow :: setCenterAlignment() * .
// Set Center Alignment * .
//************************************************************************** .
Boolean AHelloWindow :: setCenterAlignment()//Set Center Alignment .
{ // .
hello->setAlignment( //Set alignment of hello text to v3
IStaticText::centerCenter); // center-vertical, center-horizontal .
statusLine->setText(STR_CENTER); //Set Status Text to "Center" from Res .
menuBar->checkItem(MI_CENTER); //Place Check on Center Menu Item .
menuBar->uncheckItem(MI_LEFT); //Uncheck Left Menu Item .
menuBar->uncheckItem(MI_RIGHT); //Uncheck Right Menu Item v3
return true; //Return v6
} /* end AHelloWindow :: setCenterAlignmnet() */ //v6
//************************************************************************** v6
// AHelloWindow :: setRightAlignment() * .
// Set Right Alignment * .
//************************************************************************** .
Boolean AHelloWindow :: setRightAlignment()//Set Right Alignment .
{ // .
hello->setAlignment( //Set alignment of hello text to v3
IStaticText::centerRight); // center-vertical, right-horizontal .
statusLine->setText(STR_RIGHT); //Set Status Text to "Right" from Res .
menuBar->uncheckItem(MI_CENTER); //Uncheck Center Menu Item .
menuBar->uncheckItem(MI_LEFT); //Uncheck Left Menu Item .
menuBar->checkItem(MI_RIGHT); //Place Check on Right Menu Item v3
return true; //Return v6
} /* end AHelloWindow :: setRightAlignmnet() */ //v6
//************************************************************************** v5
// AHelloWindow :: setText(...) * .
// Set Text * .
//************************************************************************** .
Boolean AHelloWindow :: setText(const char* text)//Set Text using String .
{ // .
hello->setText(text); //Set Text in Control .
return true; //Return .
} /* end AHelloWindow :: setText(...) */ //v5
//************************************************************************** v6
// AHelloWindow :: setText(...) * .
// Set Text * .
//************************************************************************** .
Boolean AHelloWindow :: setText(const IResourceId& text)//Set Text via RC .
{ // .
hello->setText(text); //Set Text in Control .
return true; //Return v6
} /* end AHelloWindow :: setText(...) */ //v6
//************************************************************************** v6
// AHelloWindow :: openFile() * .
// Open File * .
//************************************************************************** .
Boolean AHelloWindow :: openFile() //Open File .
{ // .
IFileDialog::Settings fsettings; // .
fsettings.setTitle(STR_FILEDLGT); //Set Open Dialog Title from Resource .
fsettings.setFileName("*.hlo"); //Set FileNames to *.hlo .
IFileDialog fd( //Create File Open Dialiog .
(IWindow*)desktopWindow(), // Parent is Desktop .
(IWindow*)this, fsettings); // Owner is me with settings .
if (fd.pressedOK()) //Check if ok from file open dialog .
{
filename=fd.fileName(); // .
if (filename.size()) //Has Filename been specified? .
{ // .
ifstream infile(filename); //Input file stream .
if (infile) //Does file exist? .
{ // Yes, File does exist .
cin=infile.rdbuf(); // Set cin to infile .
setText( //Set text in Static Text Control .
IString().lineFrom(cin)); // from the input file. .
infile.close(); // Close input file .
} // .
else //Can not open input file .
{ // .
IMessageBox mbox(this); // Create Message Box .
IString msgTxt = //Define Message Text .
IApplication::current(). //Get current application .
userResourceLibrary(). // Set the Name of Resoure DLL .
loadString(STR_MSGTXT); // Create message text for rc file .
msgTxt.change( // Change Message Text to add Filename.
"$$$$$$$$$$$$$$$$$$$$", // Pattern, .
filename, // Replacement, .
1, 1); // StartPos, Number of Changes .
mbox.show(msgTxt, // Display Message Box .
IMessageBox::warning); // Set Warning Style .
} // .
} /* endif */ // .
} /* endif */ // .
return true; //Return .
} /* end AHelloWindow :: openFile() */ //v6
//************************************************************************** v6
// AHelloWindow :: openFont() * .
// Open Font * .
//************************************************************************** .
Boolean AHelloWindow :: openFont() //Open Font .
{ // .
IFont curFont(hello); //Define curFont .
IFontDialog::Settings fsettings(&curFont);// .
fsettings.setTitle(STR_FONTDLGT); //Set Open Dialog Title from Resource .
IFontDialog fontd( //Create Font Open Dialiog .
(IWindow*)desktopWindow(), // Parent is Desktop .
(IWindow*)this, // Owner is me .
(IFontDialog::defaultStyle() | // Set default Style with only .
IFontDialog::bitmapOnly), // BitMap Fonts .
fsettings); // settings .
if (fontd.pressedOK()) //Check if ok from Font open dialog .
{ // .
hello->setFont(curFont); //Change hello font to be curFont .
} /* endif */ // .
return true; //Return .
} /* end AHelloWindow :: openFont() */ //v6
//************************************************************************** v6
// AHelloWindow :: openText() * .
// Open Text * .
//************************************************************************** .
Boolean AHelloWindow :: openText() //Open Text Dialog .
{ // v6
IString temp; //String to pass in/out from dialog v4
unsigned short value; //Return value from dialog v4
temp=hello->text(); //Get current Hello text v4
infoArea->setInactiveText( //Set Info Area to Dialog Active .
STR_INFODLG); // Text from Resource File .
ATextDialog * textDialog=new //Create a Text Dialog .
ATextDialog(temp, this); // .
textDialog->showModally(); //Show this Text Dialog as Modal .
value=textDialog->result(); //Get result (eg OK or Cancel) .
if (value != DID_CANCEL) //Set new string if not canceled .
hello->setText(temp); //Set Hello to Text from Dialog .
infoArea->setText(STR_INFO); //Set Info Text to "Normal" from Res .
delete textDialog; //Delete textDialog .
return(true); //Return Command Processed v4
} /* end AHelloWindow :: openText() */ //v6
//************************************************************************** v6
// AHelloWindow :: tick(...) * .
// Timer Tick Message (set to every second in our sample) * .
//************************************************************************** .
Boolean AHelloWindow::tick(IEvent& evt) //Process the Tick Message .
{ // .
time->setText(ITime().asString()); //Set current time .
if ((ITime().asSeconds()) < 3) //Is it just after midnight? .
date->setText(IDate().asString()); // Yes, Set current date .
if (demo) // .
{ // .
demoCount = demoCount - 1; // .
if (demoCount < 1) // .
{ // .
nextDemoCode(); //Execute next Demo Code .
demoCount = demoTicks; //Reset .
} /* endif */ // .
}
return true; //Return true .
} /* end AHelloWindow :: stopTimer() */ //v6
//************************************************************************** v6
// AHelloWindow :: startDemo(...) * .
// Start Demo * .
//************************************************************************** .
Boolean AHelloWindow::startDemo() //Process the Demo Start .
{ // .
demo=true; //Set Start of Demo .
demoIndex = 1; //Set to first index .
demoCount = demoTicks; //Reset .
menuBar->disableItem(MI_DEMO_START); //Disable Start Menu Item .
menuBar->enableItem(MI_DEMO_STOP); //Enable Stop Menu Item .
return true; //Return true .
} /* end AHelloWindow :: demoStart() */ //v6
//************************************************************************** v6
// AHelloWindow :: stopDemo(...) * .
// Stop Demo * .
//************************************************************************** .
Boolean AHelloWindow::stopDemo() //Process the Demo Stop .
{ // .
demo=false; //Set Stop Demo .
menuBar->enableItem(MI_DEMO_START); //
menuBar->disableItem(MI_DEMO_STOP); //
return true; //Return true .
} /* end AHelloWindow :: demoStop() */ //v6
//************************************************************************** v6
// AHelloWindow :: nextDemoCode(...) * .
// Execute the next Demo Code (Case) * .
//************************************************************************** .
Boolean AHelloWindow::nextDemoCode() //Process the Demo Code .
{ // .
IFont tempFont;
switch (demoIndex) //Process the next demo "case" .
{ // .
case 1: // .
leftButton->click(); //"Click" on Left Alignment Button .
break; // .
// .
case 2: // .
rightButton->click(); //"Click" on Right Alignment Button .
break; // .
// .
case 3: // .
centerButton->click(); //"Click" on Center Alignment Button .
break; // .
// .
case 4: // .
listBox->select(1UL); //Select Item One .
break; // .
// .
case 5: // .
listBox->select(3UL); //Select Item Three .
break; // .
// .
case 6: // .
listBox->select(5UL); //Select Item Five .
break; // .
// .
case 7: // .
listBox->select(0UL); //Select Item Zero .
break; // .
// .
case 8: // .
tempFont=IFont("Helv", 12); //Set Temp. Font .
hello->setFont(tempFont); //Set Font for "Hello, World" Text .
break; // .
// .
case 9: // .
tempFont=IFont("Helv", 14); //Set Temp. Font .
hello->setFont(tempFont); //Set Font for "Hello, World" Text .
break; // .
// .
case 10: // .
tempFont=IFont("Helv", 18); //Set Temp. Font .
hello->setFont(tempFont); //Set Font for "Hello, World" Text .
break; // .
// .
case 11: // .
hello->setColor( //Set "Hello, world" text to black .
IStaticText::foreground, // .
IColor(IColor::black)); // .
break; // .
// .
case 12: // .
hello->setColor( //Set "Hello, world" text to blue .
IStaticText::foreground, // .
IColor(IColor::blue)); // .
break; // .
// .
case 13: // .
hello->setColor( //Set "Hello, world" text to red .
IStaticText::foreground, // .
IColor(IColor::red)); // .
break; // .
// .
case 14: // .
hello->setColor( //Set "Hello, world" text to pink .
IStaticText::foreground, // .
IColor(IColor::pink)); // .
break; // .
// .
case 15: // .
hello->setColor( //Set "Hello, world" text to green .
IStaticText::foreground, // .
IColor(IColor::green)); // .
break; // .
// .
case 16: // .
hello->setColor( //Set "Hello, world" text to cyan .
IStaticText::foreground, // .
IColor(IColor::cyan)); // .
break; // .
// .
case 17: // .
hello->setColor( //Set "Hello, world" text to yellow .
IStaticText::foreground, // .
IColor(IColor::yellow)); // .
break; // .
// .
case 18: // .
hello->setColor( //Set "Hello, world" text to blue .
IStaticText::foreground, // .
IColor(IColor::blue)); // .
break; // .
// .
case 19: // .
clientWindow->setSplitWindowPercentage(//Set the Window Percentage for .
helloCanvas, 40); // the helloCanvas to 40 .
clientWindow->setSplitWindowPercentage(//Set the Window Percentage for .
listBox, 60); // the listBox to 60 .
clientWindow->refresh(); // .
break; // .
// .
case 20: // .
clientWindow->setSplitWindowPercentage(//Set the Window Percentage for .
helloCanvas, 60); // the helloCanvas to 60 .
clientWindow->setSplitWindowPercentage(//Set the Window Percentage for .
listBox, 40); // the listBox to 40 .
clientWindow->refresh(); // .
break; // .
// .
case 21: // .
demoIndex=0; //Reset to start .
break; // .
// .
} /* endswitch */ // .
demoIndex = demoIndex + 1; // .
return true; //Return true .
} /* end AHelloWindow :: demoStop() */ //v6
//************************************************************************** v6
// AHelloWindow :: openColor() * .
//************************************************************************** .
Boolean AHelloWindow :: openColor() // .
{ // .
color=new AColorWindow(hello, //Open Color Window .
listBox, this); // .
return true; // .
} /* end AHelloWindow :: openColor() */ //v6
//************************************************************************** v6
// AHelloWindow :: openSpeed() * .
//************************************************************************** .
Boolean AHelloWindow :: openSpeed() // .
{ // .
new ASpeedWindow(this, this); //Open Demo Speed Window .
return true; // .
} /* end AHelloWindow :: openSpeed() */ //v6
//************************************************************************** v6
// AHelloWindow :: readProfile() * .
//************************************************************************** .
Boolean AHelloWindow :: readProfile() // .
{ // .
try // .
{ // .
IProfile profile("HELLO6.INI"); //Define Profile Object .
profile.setDefaultApplicationName( //Define Application Name .
"Hello6"); // .
demoTicks=profile. //Get Demo Speed From Profile .
integerWithKey("Speed"); // .
IString face=profile. //Get Font Face .
elementWithKey("FontFace"); // using "FontFace" Key .
int size=profile. //Get Font Size .
integerWithKey("FontSize"); // using "FontSize" Key .
IFont tempFont(face, size); //Create Temp. Font .
hello->setFont(tempFont); //Set Font for "Hello, World" Text .
} // .
catch (IException& exc) //Catch Error trying to open profile .
{ // .
DosBeep(750,500); //Report Error via beep .
IMessageBox mbox(this); // Create Message Box .
mbox.show(exc); // .
return false; //Return could not open profile .
} // .
return true; // .
} /* end AHelloWindow :: readProfile() */ //v6
//************************************************************************** v6
// AHelloWindow :: updateProfile() * .
//************************************************************************** .
Boolean AHelloWindow :: updateProfile() // .
{ // .
try // .
{ // .
IProfile profile("HELLO6.INI"); //Define Profile Object .
profile.setDefaultApplicationName( //Set Default Application Name to .
"Hello6"); // Hello6 .
profile.addOrReplaceElementWithKey( //Update Profile with .
"Speed", (long)speed()); // Speed from current demo speed .
IFont tempFont(hello); //Get current Font for hello .
profile.addOrReplaceElementWithKey( //Update Profile with .
"FontFace", tempFont.name()); // FontFace from current hello font .
profile.addOrReplaceElementWithKey( //Update Profile with .
"FontSize", // FontSize from .
(long)tempFont.pointSize()); // from current hello font .
} // .
catch (IException& exc) //Catch Error trying to open profile .
{ // .
DosBeep(750,500); //Report Error via beep .
IMessageBox mbox(this); // Create Message Box .
mbox.show(exc); // .
return false; //Return failure .
} // .
return true; // .
} /* end AHelloWindow :: updateProfile() */ //v6
//************************************************************************** v6
// AMenuHandler :: makePopUpMenu * .
//************************************************************************** .
IPopUpMenu * AMenuHandler :: makePopUpMenu(const IMenuEvent& mnEvt) // .
{ // .
IPopUpMenu * popUp; //Define popUp variable .
popUp=new IPopUpMenu(WND_POPUP, //Create PopUp Menu with AutoDelete on .
mnEvt.window()); // .
popUp->show(mnEvt.mousePosition()); //Show PopUp Menu .
return popUp; //Return PopUp Menu .
} /* end AMenuHandler :: makePopUpMenu(...) */ //v6
//************************************************************************** v5
// AHelpHandler :: keysHelpId * .
// Handle the keys help request event * .
// This overrides the default provided by IBMCLASS * .
//************************************************************************** .
Boolean AHelpHandler :: keysHelpId(IEvent& evt) // .
{ // .
evt.setResult(1000); //1000=keys help id in .
// ahellow6.ipf file .
return true; //Return command processed .
} /* end AHelpHandler :: keysHelpId(...) */ //v5