home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C Programming Starter Kit 2.0
/
SamsPublishing-CProgrammingStarterKit-v2.0-Win31.iso
/
tybc4
/
clsxprt1
/
clsxpr1a.cpp
< prev
next >
Wrap
C/C++ Source or Header
|
1993-12-05
|
8KB
|
329 lines
/* Project clsxprt1
Copyright ⌐ 1993. All Rights Reserved.
SUBSYSTEM: clsxprt1.exe Application
FILE: clsxpr1a.cpp
AUTHOR:
OVERVIEW
========
Source file for implementation of clsxprt1App (TApplication).
*/
#include <owl\owlpch.h>
#pragma hdrstop
#include "clsxpr1a.h"
#include "clsxp1ad.h" // Definition of about dialog.
#include <stdio.h>
#include <string.h>
#include <dos.h>
//{{clsxprt1App Implementation}}
//
// Build a response table for all messages/commands handled
// by the application.
//
DEFINE_RESPONSE_TABLE1(clsxprt1App, TApplication)
//{{clsxprt1AppRSP_TBL_BEGIN}}
EV_COMMAND(CM_FILENEW, CmFileNew),
EV_COMMAND(CM_FILEOPEN, CmFileOpen),
EV_COMMAND(CM_FILECLOSE, CmFileClose),
EV_COMMAND(CM_HELPABOUT, CmHelpAbout),
EV_COMMAND(CM_UPPERCASE, CmUppercase),
EV_COMMAND(CM_LOWERCASE, CmLowercase),
EV_COMMAND(CM_INSDATE, CmInsertDate),
EV_COMMAND(CM_INSTIME, CmInsertTime),
EV_COMMAND(CM_INSDATETIME, CmInsertDateTime),
EV_COMMAND(CM_REVERSE, CmReverse),
//{{clsxprt1AppRSP_TBL_END}}
END_RESPONSE_TABLE;
//
// FrameWindow must be derived to override Paint for Preview and Print.
//
class SDIDecFrame : public TDecoratedFrame {
public:
SDIDecFrame (TWindow *parent, const char far *title, TWindow *clientWnd, BOOL trackMenuSelection = FALSE, TModule *module = 0) :
TDecoratedFrame(parent, title, clientWnd, trackMenuSelection, module)
{ }
~SDIDecFrame ()
{ }
};
//////////////////////////////////////////////////////////
// clsxprt1App
// =====
//
clsxprt1App::clsxprt1App () : TApplication("clsxprt1")
{
// Common file file flags and filters for Open/Save As dialogs. Filename and directory are
// computed in the member functions CmFileOpen, and CmFileSaveAs.
FileData.Flags = OFN_FILEMUSTEXIST | OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT;
FileData.SetFilter("All Files (*.*)|*.*|");
// INSERT>> Your constructor code here.
}
clsxprt1App::~clsxprt1App ()
{
// INSERT>> Your destructor code here.
}
//////////////////////////////////////////////////////////
// clsxprt1App
// =====
// Application intialization.
//
void clsxprt1App::InitMainWindow ()
{
Client = new TEditFile(0, 0, 0);
SDIDecFrame *frame = new SDIDecFrame(0, GetName(), Client, FALSE);
nCmdShow = nCmdShow != SW_SHOWMINIMIZED ? SW_SHOWNORMAL : nCmdShow;
//
// Assign ICON w/ this application.
//
frame->SetIcon(this, IDI_SDIAPPLICATION);
//
// Menu associated with window and accelerator table associated with table.
//
frame->AssignMenu(SDI_MENU);
//
// Associate with the accelerator table.
//
frame->Attr.AccelTable = SDI_MENU;
MainWindow = frame;
}
//////////////////////////////////////////////////////////
// clsxprt1App
// ===========
// Menu File New command
void clsxprt1App::CmFileNew ()
{
Client->NewFile();
}
//////////////////////////////////////////////////////////
// clsxprt1App
// ===========
// Menu File Open command
void clsxprt1App::CmFileOpen ()
{
//
// Display standard Open dialog box to select a file name.
//
*FileData.FileName = 0;
if (Client->CanClose())
if (TFileOpenDialog(MainWindow, FileData).Execute() == IDOK)
OpenFile();
}
void clsxprt1App::OpenFile (const char *fileName)
{
if (fileName)
lstrcpy(FileData.FileName, fileName);
Client->ReplaceWith(FileData.FileName);
}
//////////////////////////////////////////////////////////
// clsxprt1App
// =====
// Menu File Close command
void clsxprt1App::CmFileClose ()
{
if (Client->CanClose())
Client->DeleteSubText(0, UINT(-1));
}
//////////////////////////////////////////////////////////
// clsxprt1App
// ===========
// Menu Help About clsxprt1.exe command
void clsxprt1App::CmHelpAbout ()
{
//
// Show the modal dialog.
//
clsxprt1AboutDlg(MainWindow).Execute();
}
int OwlMain (int , char* [])
{
clsxprt1App App;
int result;
result = App.Run();
return result;
}
void clsxprt1App::CmUppercase ()
{
UINT startPos, endPos;
int numChars;
char* pszStr;
Client->GetSelection(startPos, endPos);
// is there selected text
if (startPos < endPos) {
numChars = endPos - startPos + 1;
pszStr = new char[numChars+1];
Client->GetSubText(pszStr, startPos, endPos);
strupr(pszStr);
Client->Insert(pszStr);
Client->SetSelection(startPos, endPos);
delete [] pszStr;
}
else {
numChars = Client->GetWindowTextLength();
pszStr = new char[numChars+1];
Client->GetSubText(pszStr, 0, (UINT)numChars);
strupr(pszStr);
Client->DeleteSubText(0, (UINT)numChars);
Client->SetSelection(0, 0);
Client->Insert(pszStr);
delete [] pszStr;
}
}
void clsxprt1App::CmLowercase ()
{
UINT startPos, endPos;
int numChars;
char* pszStr;
Client->GetSelection(startPos, endPos);
// is there selected text
if (startPos < endPos) {
numChars = endPos - startPos + 1;
pszStr = new char[numChars+1];
Client->GetSubText(pszStr, startPos, endPos);
strlwr(pszStr);
Client->Insert(pszStr);
Client->SetSelection(startPos, endPos);
delete [] pszStr;
}
else {
numChars = Client->GetWindowTextLength();
pszStr = new char[numChars+1];
Client->GetSubText(pszStr, 0, (UINT)numChars);
strlwr(pszStr);
Client->DeleteSubText(0, (UINT)numChars);
Client->SetSelection(0, 0);
Client->Insert(pszStr);
delete [] pszStr;
}
}
void clsxprt1App::CmInsertDate ()
{
struct date dt;
char szStr[41];
getdate(&dt);
sprintf(szStr, "%02d/%02d/%4d",
dt.da_mon, dt.da_day, dt.da_year);
Client->Insert(szStr);
}
void clsxprt1App::CmInsertTime ()
{
struct time tm;
char szStr[41];
gettime(&tm);
sprintf(szStr, "%02d:%02d:%02d",
tm.ti_hour, tm.ti_min, tm.ti_sec);
Client->Insert(szStr);
}
void clsxprt1App::CmInsertDateTime ()
{
struct date dt;
struct time tm;
char szStr[41];
getdate(&dt);
sprintf(szStr, "%02d/%02d/%4d ",
dt.da_mon, dt.da_day, dt.da_year);
Client->Insert(szStr);
gettime(&tm);
sprintf(szStr, "%02d:%02d:%02d",
tm.ti_hour, tm.ti_min, tm.ti_sec);
Client->Insert(szStr);
}
void clsxprt1App::CmReverse ()
{
UINT startPos, endPos;
int numChars;
char* pszStr;
char swapChar;
Client->GetSelection(startPos, endPos);
// is there selected text
if (startPos < endPos) {
numChars = endPos - startPos + 1;
pszStr = new char[numChars+1];
Client->GetSubText(pszStr, startPos, endPos);
for (int i = 0, j = strlen(pszStr)-1; i < j ; i++, j--) {
swapChar = pszStr[i];
pszStr[i] = pszStr[j];
pszStr[j] = swapChar;
}
Client->Insert(pszStr);
Client->SetSelection(startPos, endPos);
delete [] pszStr;
}
else {
numChars = Client->GetWindowTextLength();
pszStr = new char[numChars+1];
Client->GetSubText(pszStr, 0, (UINT)numChars);
for (int i = 0, j = strlen(pszStr)-1; i < j ; i++, j--) {
swapChar = pszStr[i];
pszStr[i] = pszStr[j];
pszStr[j] = swapChar;
}
Client->DeleteSubText(0, (UINT)numChars);
Client->SetSelection(0, 0);
Client->Insert(pszStr);
delete [] pszStr;
}
}