home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 10 Tools
/
10-Tools.zip
/
owf.zip
/
template
/
pm1
/
pm1.cpp
< prev
next >
Wrap
C/C++ Source or Header
|
1997-02-14
|
4KB
|
145 lines
#include "pm1.h"
#include XRect_i
#include XString_i
#include XMenuBar_i
#include XControlEvent_i
#include XResourceLibrary_i
#include XFileDialog_i
#include XColor_i
#include <stdlib.h>
//create a window out of the resource-file, the last parameter tells the library
//to build the window with the ID given in XResource.
pm1Window :: pm1Window( XResource * r ): XFrameWindow( r, "pm1", XFrameWindow::defaultStyle | FRM_ICON | FRM_TASKLIST | FRM_CENTER /MENU | FRM_MENU | FRM_ACCELTABLEMENU/)
{
//Set background-color
XColor color( COL_WHITE);
SetBackgroundColor( &color );
//Set size
XRect rect( 100,100, 400, 300);
SetSize(&rect);
/HELP
//create a helpinstance
help = new XHelpInstance( "pm1.hlp", GetProcess(), "pm1 - Help");
//associate the help with this function
help->AssociateWindow( this );HELP/
//Activate the window
Activate();
}
pm1Window :: ~pm1Window()
{
}
//draw the window-content
void pm1Window :: Draw( void )
{
//fill the background
FillBackground( );
}
/* here the commands of the menu are posted */
BOOL pm1Window :: DoCommand( LONG command)
{
switch( command )
{
//which menuitem was selected?
case IDM_OPEN:
/MENU {
/*File/Open selected */
/* display the file-dialog defined by the system */
/* set the file-suffix and title of the dialog */
XFileDialog fileDlg(this, "*.TXT", NULL, NULL, FD_OPEN | FD_CENTER | FD_MULTIPLESEL);
/* the user selected a file */
if( fileDlg.GetCommand() == USER_OK)
{
XString fileName;
SHORT i, files = fileDlg.GetFileCount(); //how much files are selected?
for(i=0; i < files; i++)
{
fileDlg.GetFileName( &fileName, i ); //get filename and path for every file
//perfor your loading of the selected file(s) here
}
}
}MENU/
break;
case IDM_SAVEAS:
/MENU {
/*File/Open selected */
/* display the file-dialog defined by the system */
/* set the file-suffix and title of the dialog */
XFileDialog fileDlg(this, "*.TXT", NULL, NULL, FD_SAVEAS | FD_CENTER );
/* the user selected a file */
if( fileDlg.GetCommand() == USER_OK)
{
XString fileName;
fileDlg.GetFileName( &fileName); //get filename and path where to save
//perfor your save_as code here
}
}MENU/
break;
/MENU/HELP
case IDM_HELP_HELP:
help->ShowHelpForHelp();/HELP
break;
case IDM_HELP_INDEX:
help->ShowHelpIndex();
break;
case IDM_HELP_GENERAL:
help->ShowHelpForId( 100 );
break;HELP/ MENU/
default:
break;
}
return TRUE;
}
//here the control-events of our window-contents are posted
void pm1Window :: DoControl( XControlEvent * event)
{
switch( event->GetEventID()) //what type of event?
{
case WIN_CHANGED: //window-content changed!
{
switch( event->GetWindowID()) //which window posted the event?
{
default:
break;
}
}
}
}
pm1 :: pm1(): XApplication()
{
//create a resource wich is used to load the menu
XResource r( IDM_MENU, GetResourceLibrary());
//create the window
window = new pm1Window( &r );
}
void main ( void)
{
//create a new application
pm1 * app = new pm1();
//let the application work
app->Start();
}