home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 10 Tools
/
10-Tools.zip
/
VSCPPv8.zip
/
VACPP
/
IBMCPP
/
samples
/
IOC
/
HELLO3
/
AHELLOW3.CPP
next >
Wrap
C/C++ Source or Header
|
1995-04-07
|
17KB
|
226 lines
/*****************************************************************************
* HELLO WORLD SAMPLE PROGRAM - Version 3: Class Implementation (ahellow3.cpp)*
* *
* 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.
/************************************************************************** V1
* C++ Hello World History and Key Functions: * V1
* Version 1: (lines with V1 in column 79-80) * V1
* - Creates and runs a simple application * V1
* - Creates the main window (IFrameWindow) * V1
* - Creates a static text control set to "Hello, World!!!" as the * V1
* client window * V1
* * V2
* Version 2: (lines with V2 in column 79-80) * V2
* - Creates a main window (AHellowWindow) derived from IFrameWindow * V2
* - Gets the "Hello, World!!!" text string and other items from a * V2
* resource file * V2
* - Sets the window title from a resource file * V2
* - Creates and sets the information area below the client window * V2
* * V3
* Version 3: (lines with V3 in column 79-80) * V3
* - Adds alignment menu bar with left, center, and right menu items * V3
* - Adds command processing for aligning the * V3
* "Hello, World!!!" text * V3
* - Places check mark in front of selected menu item * V3
* - Creates and maintains current alignment status line * V3
**************************************************************************/
//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.
#include <iapp.hpp> //IApplication class V1
#include <ifont.hpp> //IFont class V3
#include "ahellow3.hpp" //Include AHelloWindow class headers v3
#include "ahellow3.h" //Include symbolic definitions v3
/************************************************************************** V1
* main - Application entry point for Hello World Version 3. * v3
* This simple application does the following: * V1
* 1) Creates a new object mainWindow of class AHelloWindow * v2
* 2) Sets Hello World window alignment * V3
* 3) Sets the size of mainWindow * v3
* 4) Sets the window focus to mainWindow * v3
* 5) Displays the mainWindow * v3
* 6) Starts the events processing for the application * v3
**************************************************************************/
int main() //V1
{ //V1
AHelloWindow mainWindow (WND_MAIN); //V2
mainWindow.setAlignment(AHelloWindow::left); //V3
mainWindow.sizeTo(ISize(400,300)); //V1
mainWindow.setFocus(); //V1
mainWindow.show(); //V1
IApplication::current().run(); //V1
return 0;
} /* end main */ //V1
/************************************************************************** V2
* AHelloWindow :: AHelloWindow - Constructor for the main window * V2
* Construct the IFrameWindow using the default style plus minimizedIcon, * V2
* which gets the Icon identified in the resource file and associates it * V2
* with the main window. * V2
* Create a menu bar object for the main window menu bar that was loaded * V3
* from the resource file. menuBar is used by setAlignment to * V3
* manipulate check marks on the menu items. * V3
* Create a static text object for displaying the status of the * V3
* Hello World text alignment. * V3
* Create the hello world static text to be used as the client window. * V2
* Create the Hello World information area object from IInfoArea class. * V2
* The information area is automatically added as an extension below * V2
* the client window of the frame. * V2
* Create a command handler to process command events from menu item * v3
* selections. * v3
**************************************************************************/ //V2
AHelloWindow :: AHelloWindow(unsigned long windowId) //V2
: IFrameWindow(IFrameWindow::defaultStyle() | //V2
IFrameWindow::minimizedIcon, //V2
windowId) //V2
,menuBar(windowId, this) //V3
,statusLine(WND_STATUS, this, this) //V3
,hello(WND_HELLO, this, this) //V2
,infoArea(this) //V2
,commandHandler(this) //V3
{ //V2
/*------------------------- Setup the Client Window ----------------------| V2
| Set the hello world static text window as the client window. | V2
|------------------------------------------------------------------------*/ //V2
setClient(&hello); //V2
/*------------------------- Setup the Status Line ------------------------| V3
| Add the status line as an extension to the frame above the client | V3
| window with the height calculated from the maximum height of a | V3
| character in the current font. | V3
|------------------------------------------------------------------------*/ //V3
addExtension(&statusLine, IFrameWindow::aboveClient, //V3
IFont(&statusLine).maxCharHeight()); //V3
/*---------------------------- Set Text Values ---------------------------| V2
| Set the values for the text controls from strings in the resource file.| V2
| The infoArea inactive text is displayed when no menu item is active. | V2
|------------------------------------------------------------------------*/ //V2
hello.setText(STR_HELLO); //V2
infoArea.setInactiveText(STR_INFO); //V2
/*----------------------- Setup the Command Handler ----------------------| V3
| Have the command handler handle commands sent from the frame window. | V3
| The command handler's command() function is called to process | V3
| menu item selections. | V3
|------------------------------------------------------------------------*/ //V3
commandHandler.handleEventsFor(this); //V3
/*----------------------- Set Default Alignment --------------------------| V2
| Align the static text, set the status line, and set the check mark in | v3
| the menu bar. | v3
|------------------------------------------------------------------------*/ //V2
setAlignment(center); //v3
} /* end AHelloWindow :: AHelloWindow(...) */ //V2
/************************************************************************** V3
* AHelloWindow :: ~AHelloWindow - Destructor for the main window * V3
* Stop handling command events for the frame. * V3
**************************************************************************/ //V3
AHelloWindow :: ~AHelloWindow() //V3
{ //V3
commandHandler.stopHandlingEventsFor(this); //V3
} /* end AHelloWindow :: ~AHelloWindow() */ //V3
/************************************************************************** V3
* AHelloWindow :: setAlignment - Align static text in client window * V3
**************************************************************************/ //V3
AHelloWindow & //V3
AHelloWindow :: setAlignment(Alignment alignment) //V3
{ //V3
/*--------------------- Update Window for New Alignment ------------------| V3
| Depending on the value passed, update the window as follows: | V3
| Set the alignment of the static text control in the client window. | V3
| Set the text of the alignment status line static text control. | V3
| Check the selected menu item; remove check marks from the other two. | V3
|------------------------------------------------------------------------*/ //V3
switch(alignment) //V3
{ //V3
case left: //V3
hello.setAlignment( //V3
IStaticText::centerLeft); //V3
statusLine.setText(STR_LEFT); //V3
menuBar.uncheckItem(MI_CENTER); //V3
menuBar.checkItem(MI_LEFT); //V3
menuBar.uncheckItem(MI_RIGHT); //V3
break; //V3
case center: //V3
hello.setAlignment( //V3
IStaticText::centerCenter); //V3
statusLine.setText(STR_CENTER); //V3
menuBar.checkItem(MI_CENTER); //V3
menuBar.uncheckItem(MI_LEFT); //V3
menuBar.uncheckItem(MI_RIGHT); //V3
break; //V3
case right: //V3
hello.setAlignment( //V3
IStaticText::centerRight); //V3
statusLine.setText(STR_RIGHT); //V3
menuBar.uncheckItem(MI_CENTER); //V3
menuBar.uncheckItem(MI_LEFT); //V3
menuBar.checkItem(MI_RIGHT); //V3
break; //V3
} //V3
return (*this); //Return a reference to the frame V3
} /* end AHelloWindow :: setAlignment(...) */ //V3
/************************************************************************** V3
* ACommandHandler :: ACommandHandler - constructor for the command handler* V3
* Construct the command handler from a pointer to the AHelloWindow * V3
* that events will be handled for. * V3
**************************************************************************/ //V3
ACommandHandler :: ACommandHandler(AHelloWindow *helloFrame) //V3
{ //V3
frame=helloFrame; //Save frame to be handled V3
} /* end ACommandHandler :: ACommandHandler(...) */ //V3
/************************************************************************** V3
* ACommandHandler :: command * V3
* Handle menu commands * V3
**************************************************************************/ //V3
IBase::Boolean //V3
ACommandHandler :: command(ICommandEvent & cmdEvent) //V3
{ //V3
Boolean eventProcessed(true); //Assume event will be processed V3
/*--------------------- Process command events ---------------------------| V3
| Depending on the command event ID, call the AHelloWindow::setAlignment | V3
| function with the appropriate AHelloWorld::Alignment value. | V3
|------------------------------------------------------------------------*/ //V3
switch (cmdEvent.commandId()) { //V3
case MI_CENTER: //V3
frame->setAlignment(AHelloWindow::center); //V3
break; //V3
case MI_LEFT: //V3
frame->setAlignment(AHelloWindow::left); //V3
break; //V3
case MI_RIGHT: //V3
frame->setAlignment(AHelloWindow::right); //V3
break; //V3
default: //Otherwise, V3
eventProcessed=false; // the event wasn't processed V3
} /* end switch */ //V3
return(eventProcessed); //V3
} /* end ACommandHandler :: command(...) */ //V3