Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

multiple .cpp files in an OWL project

Posted on 1997-09-08
2
Medium Priority
?
332 Views
Last Modified: 2012-06-27
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();
}
0
Comment
Question by:aa941438
2 Comments
 
LVL 3

Accepted Solution

by:
gaohong earned 400 total points
ID: 1169204
good programming style could save you troubles and leads to easy
maintaining.

In general, for each class, say "MyClass"
you should have a header file called myclass.h, in which
you put class declaration and necessary header files and other
variables, if globals or static or control ID used.

It is nothing wrong to stuck all into one file, only cause you
difficulties.

You put your class definition in myclass.cpp file.

For your codes above.

It should have mydialog.h mydialog.cpp for class MyDialog
myframe.h myframe.cpp for class TDiagWin
myapp.h myapp.cpp for class TDiagApp

Put .h files in include directory, .cpp files in aother directory.

After you generate a new project, .ide file
right click to add .cpp files, while specify the include path
in project options.

good luck
gaohong xie

                 
0
 

Author Comment

by:aa941438
ID: 1169205
many thanks

Richard
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
Suggested Courses

885 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question