Solved

multiple .cpp files in an OWL project

Posted on 1997-09-08
2
313 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 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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

744 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now