Solved

multiple .cpp files in an OWL project

Posted on 1997-09-08
2
324 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 3

Accepted Solution

by:
gaohong earned 200 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.

623 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