Link to home
Start Free TrialLog in
Avatar of aa941438
aa941438

asked on

multiple .cpp files in an OWL project

I am using Borland C++ 4.5

What I would like to know is how I should prepare code such that multiple .cpp files can be utilised within a project. Specifically, how should I break up an existing single .cpp file into two parts i.e., so that it becomes two .cpp files, and yet can be compiled within the project environment as one.

As an example, I enclose a program that operates a simple dialog box from a  popup menu. Possibly someone could explain how I might break this into two .cpp files for compilation within the project environment.

your assistance is most appreciated

regards

Richard

 

#include <cstring.h>
#include <windows.h>
#include <owl\edit.h>
#include <owl\window.h>
#include <owl\window.rh>
#include <owl\scroller.h>
#include <fstream.h>
#include <owl\applicat.h>
#include <owl\framewin.h>
#include <owl\dialog.h>
#pragma hdrstop
#include "dialog2.rh"

const UINT MaxEdit = 48;

 ===========================================================
// Sample dialog
// ===========================================================

class MyDialog: public TDialog
{
public:
  MyDialog(TWindow* parent, TResId resId);
  ~MyDialog();

private:
      TEdit *EditControl1;
      TEdit *EditControl2;
      TEdit *EditControl3;
   virtual void SetupWindow();
 
protected:
  void CmCancel();
  void CmOk();
DECLARE_RESPONSE_TABLE(MyDialog);
};

DEFINE_RESPONSE_TABLE1(MyDialog, TDialog)
  EV_COMMAND(CM_CANCEL, CmCancel),
  EV_COMMAND(CM_OK, CmOk),
END_RESPONSE_TABLE;

void MyDialog::SetupWindow()
{
      TDialog::SetupWindow();
      Scroller = new TScroller(this, 5, 5, 300, 300);
      string text;
      ifstream file("Datafile.txt",ios::binary);

      text.read_file(file);
      EditControl1->Insert(text.c_str());
      text.read_file(file);
      EditControl2->Insert(text.c_str());
      text.read_file(file);
      EditControl3->Insert(text.c_str());
}


void MyDialog::CmCancel()
{
 SendMessage(WM_CLOSE);
}

void MyDialog::CmOk()
{
      char buffer[MaxEdit];
      int len = EditControl1->GetText(buffer,MaxEdit);
      ofstream file("Datafile.txt",ios::binary);
      file.write(buffer,len);
      file<<'\0'; // insert null to delimit text
      len = EditControl2->GetText(buffer,MaxEdit);
      file.write(buffer,len);
      file<<'\0'; // insert null to delimit text
      len = EditControl3->GetText(buffer,MaxEdit);
      file.write(buffer,len);
      file<<'\0'; // insert null to delimit text
      file.close();
      SendMessage(WM_CLOSE);
}


// ===========================================================
// The application's main window
// ===========================================================

class TDiagWin: public TFrameWindow {
public:
  TDiagWin(TWindow* parent, const char far* title);
protected:
  void CmTest();
DECLARE_RESPONSE_TABLE(TDiagWin);
};

DEFINE_RESPONSE_TABLE1(TDiagWin, TFrameWindow)
  EV_COMMAND(CM_TEST, CmTest),
END_RESPONSE_TABLE;

// Constructor
TDiagWin::TDiagWin(TWindow* parent, const char far* title)
  : TFrameWindow(parent, title),
    TWindow(parent, title)
{
  AssignMenu(ID_MENU);
}

// Construct and execute a modal dialog box
void
TDiagWin::CmTest()
{
(new MyDialog(this, ID_DIALOG)->Execute());
}

MyDialog::~MyDialog()
{
}

MyDialog::MyDialog(TWindow* parent, TResId resId)
      : TWindow(parent),TDialog(parent, resId)
{

   EditControl1 = new TEdit(this,IDE_FIND1);
      EditControl2 = new TEdit(this,IDE_FIND2);
      EditControl3 = new TEdit(this,IDE_FIND3);
}

// ===========================================================
// The application class
// ===========================================================

class TDiagApp: public TApplication {
public:
  TDiagApp(const char far* name)
    : TApplication(name) {}
  void InitMainWindow();
};

// Initialize the program's main window
void
TDiagApp::InitMainWindow()
{
  EnableBWCC();  // Loads custom control DLL
  MainWindow = new TDiagWin(0, "Sample Dialog Box");
}

#pragma argsused

// Main program
int
OwlMain(int argc, char* argv[])
{
  TDiagApp app("DiagApp");
  return app.Run();
}
ASKER CERTIFIED SOLUTION
Avatar of gaohong
gaohong

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of aa941438
aa941438

ASKER

many thanks

Richard