home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Visual Basic 4 Unleashed
/
Visual_Basic_4_Unleashed_SAMS_Publishing_1995.iso
/
european
/
simple.cp_
/
simple.cp
Wrap
Text File
|
1995-10-05
|
6KB
|
225 lines
/*---------------------------------------------------------------------------
** module: SIMPLE (Application)
** file: simple.cpp
** description: This is a simple word processor which uses the Text-Contol
** VBX together with the Borland Object Windows Library (OWL).
**
** copyright: ⌐ DBS GmbH 1994
** version: 1.0 /r 1.02
** Text-Control TXL.DLL version 3.3
** VBX Version TX4VBL.VBX 2.10
** compiler: Borland C++ version 4.0
** author: Heiner Suhr
**
** changes:
** 26.06.1994 Hei started
**-------------------------------------------------------------------------*/
#include <owl\owlpch.h>
#include <owl\applicat.h>
#include <owl\framewin.h>
#include <owl\opensave.h>
#include <owl\vbxctl.h>
#include "simple.rc"
// Status Bar, Ruler and ButtonBar height (in pixels)
#define STATUSBAR_HEIGHT 25
#define BUTTONBAR_HEIGHT 30
#define RULER_HEIGHT 35
// Page dimensions (in twips)
#define PAGE_HEIGHT 15840 // 11 inch
#define PAGE_WIDTH 12240 // 8.5 inch
//
// Main window class definition.
//
class TMyWindow : public TWindow, public TVbxEventHandler {
public:
TMyWindow(TWindow *parent = 0);
protected:
TVbxControl *TextControl, *StatusBar, *ButtonBar, *Ruler;
TOpenSaveDialog::TData FilenameData;
void SetupWindow();
// Message response functions
void CmFileNew();
void CmFileOpen();
void CmFileSaveAs();
void CmEditCut();
void CmEditCopy();
void CmEditPaste();
void CmEditDelete();
void EvSize(UINT, TSize&);
void EvErrorCode(VBXEVENT far *event);
DECLARE_RESPONSE_TABLE(TMyWindow);
};
DEFINE_RESPONSE_TABLE2(TMyWindow, TWindow, TVbxEventHandler)
// File menu
EV_COMMAND(CM_FILENEW, CmFileNew),
EV_COMMAND(CM_FILEOPEN, CmFileOpen),
EV_COMMAND(CM_FILESAVEAS, CmFileSaveAs),
// Edit menu
EV_COMMAND(CM_EDITCUT, CmEditCut),
EV_COMMAND(CM_EDITCOPY, CmEditCopy),
EV_COMMAND(CM_EDITPASTE, CmEditPaste),
EV_COMMAND(CM_EDITDELETE, CmEditDelete),
// VBX Events
EV_VBXEVENTNAME(10, "ErrorCode", EvErrorCode),
EV_WM_SIZE,
END_RESPONSE_TABLE;
//
// Constructor for the main window. Creates a Text-Control, status bar,
// button bar and ruler. The final position and size is determined when
// the Size event is processed.
//
TMyWindow::TMyWindow(TWindow *parent)
: FilenameData(OFN_FILEMUSTEXIST|OFN_HIDEREADONLY|OFN_PATHMUSTEXIST,
"TX Files (*.tx)|*.tx|All Files (*.*)|*.*|",
0, "", "*")
{
Init(parent, 0, 0);
StatusBar = new TVbxControl(this, 20, "Tx4vbl.vbx", "TXStatusBar", "", 0, 0, 0, 100, 0);
TextControl = new TVbxControl(this, 10, "Tx4vbl.vbx", "TextControl", "", 0, 0, 100, 100, 0);
ButtonBar = new TVbxControl(this, 30, "Tx4vbl.vbx", "TXButtonBar", "", 0, 0, 100, 100, 0);
Ruler = new TVbxControl(this, 40, "Tx4vbl.vbx", "TXRuler", "", 0, 0, 100, 100, 0);
}
//
// SetupWindow member function of the main window. This is used to connect
// the Text-Control to its tools and set the focus to the Text-Control.
//
void TMyWindow::SetupWindow()
{
TWindow::SetupWindow();
// Connect TextControl to tools
TextControl->SetProp("StatusBar", "TXStatusBar");
TextControl->SetProp("ButtonBar", "TXButtonBar");
TextControl->SetProp("Ruler", "TXRuler");
TextControl->SetFocus();
// Set page size and enable scrollbars
TextControl->SetProp("PageHeight", PAGE_HEIGHT);
TextControl->SetProp("PageWidth", PAGE_WIDTH);
// For Borland C++ versions < 4.5, property values must be
// specified in pixels:
// TextControl->SetProp("PageHeight", VBXTwp2PixX(PAGE_HEIGHT));
// TextControl->SetProp("PageWidth", VBXTwp2PixY(PAGE_WIDTH));
TextControl->SetProp("ScrollBars", 3);
}
//
// File menu commands
//
void TMyWindow::CmFileNew()
{
TextControl->SetProp("Text", "");
}
void TMyWindow::CmFileOpen()
{
HFILE hFile=0;
OFSTRUCT of;
if (TFileOpenDialog(this, FilenameData).Execute() != IDOK) {
if (FilenameData.Error != 0) { // 0 value means user selected Cancel
char msg[50];
wsprintf(msg, "File Open Error #%ld", FilenameData.Error);
MessageBox(msg, "WARNING", MB_OK|MB_ICONSTOP);
}
} else {
hFile = OpenFile(FilenameData.FileName, &of, OF_READ);
TextControl->SetProp("Load", hFile);
_lclose(hFile);
}
}
void TMyWindow::CmFileSaveAs()
{
HFILE hFile=0;
OFSTRUCT of;
if (TFileSaveDialog(this, FilenameData).Execute() != IDOK) {
if (FilenameData.Error != 0) { // 0 value means user selected Cancel
char msg[50];
wsprintf(msg, "File Save Error #%ld", FilenameData.Error);
MessageBox(msg, "WARNING", MB_OK|MB_ICONSTOP);
}
} else {
hFile = OpenFile(FilenameData.FileName, &of, OF_CREATE);
TextControl->SetProp("Save", hFile);
_lclose(hFile);
}
}
//
// Edit menu commands
//
void TMyWindow::CmEditCut() { TextControl->SetProp("Clip", 1); }
void TMyWindow::CmEditCopy() { TextControl->SetProp("Clip", 2); }
void TMyWindow::CmEditPaste() { TextControl->SetProp("Clip", 3); }
void TMyWindow::CmEditDelete() { TextControl->SetProp("Clip", 4); }
//
// Size event. Move and resize all of the 4 controls so that
// they fill the entire window.
//
void TMyWindow::EvSize(UINT SizeType, TSize& Size)
{
ButtonBar->SetWindowPos(NULL, 0, 0,
Size.cx, BUTTONBAR_HEIGHT, SWP_NOZORDER);
Ruler->SetWindowPos(NULL, 0, BUTTONBAR_HEIGHT,
Size.cx, RULER_HEIGHT, SWP_NOZORDER);
TextControl->SetWindowPos(NULL, 0, BUTTONBAR_HEIGHT + RULER_HEIGHT,
Size.cx, Size.cy - (BUTTONBAR_HEIGHT + RULER_HEIGHT + STATUSBAR_HEIGHT),
SWP_NOZORDER);
StatusBar->SetWindowPos(NULL, 0, Size.cy - STATUSBAR_HEIGHT,
Size.cx, STATUSBAR_HEIGHT, SWP_NOZORDER);
}
void TMyWindow::EvErrorCode(VBXEVENT far *event)
{
char sz[50];
WORD wErrorCode;
wErrorCode = VBX_EVENTARGNUM(event, short, 0);
wsprintf(sz, "Text-Control Error Code %x", wErrorCode);
MessageBox(sz);
}
//
// Application class.
//
class TMyApp : public TApplication {
public:
TMyApp() : TApplication() {}
void InitMainWindow()
{
MainWindow = new TFrameWindow(0, "Text-Control Demo", new TMyWindow);
MainWindow->AssignMenu("COMMANDS");
}
};
int OwlMain(int /*argc*/, char* /*argv*/ [])
{
TBIVbxLibrary vbxLib; // constructing this loads & inits the library
return TMyApp().Run();
}