<< Back

How To Setup TextPad for Writing C++ Programs

On This Page

  1. Introduction
  2. Before You Begin
  3. Installing TextPad
  4. Adding a Blank Line
  5. Enabling Line Numbers
  6. Configuring Tab Settings
  7. Enabling Syntax Highlighting
  8. Setting the Path on XP and Vista
  9. Compiling C++ Programs
  10. Compiling C++ Graphical Programs
  11. Running C++ Programs
  12. Configuring the Documentation System
  13. Configuring Keyboard Shortcuts (Optional)

syntaxhighlight

A. Introduction

This document describes how to install and configure TextPad for use with CygWin on a Windows home computer for the course CS-11: Introduction to Programming Concepts and Methodology, C++.

TextPad is already installed on CTC and lab machines under the CIS and CS directory. You can download a copy of TextPad for evaluation at home as well. There is no charge for the download, but you must pay for the software if you decide to keep it. A single user license costs only $27 US dollars. Your instructor is a licensed user.

Note that TextPad only runs on computers using Windows. Usually both Linux and OS X (Apple) systems have good text editors already installed.

If you need more help, you can consult TextPad's Support information. Or better yet, ask a classmate if they were able to get it set up.

B. Before You Begin

These instructions assume that you have already installed Cygwin as described in the document: How to Install Cygwin. If not, do so now.

In addition, you need to download and install Horstmann's CCC Libraries (cccfile) files, along with some additional files I wrote, which are available in the file: cccfiles.zip. Step-by-step instructions are:

  1. Download cccfiles.zip into your Cygwin installation directory: C:\cygwin\
  2. Unzip the file and verify the unzip operation created the directory: cccfiles as a subdirectory of cygwin.

Make certain you do not have a cccfiles subdirectory inside another cccfiles subdirectory. This is a common error if you do not extract to the C:\cygwin directory. You will be using the cccfiles files in this location to complete your TextPad setup.

C. Installing TextPad

Download TextPad and install it following the Installation Instructions. Note that there is a both a TextPad 4 and a TextPad 5 and these instructions work for either version.

After installing TextPad, download one of the following syntax definition files and save it in the Samples directory of your TextPad installation.

The Samples directory is usually located at: C:\Program Files\TextPad 5\Samples. Open this directory and unzip the syntax definition file. Then, double-click the file named addRegistryEntries.reg to install syntax highlighting.

Once the installation is complete, you should configure TextPad as described below. Completing the following steps will make your programming easier.

D. Adding a Blank Line

You should have TextPad add a blank line to the end of every file to prevent the warning, "No newline at end of file", when you compile a program.

  1. Click on the Configure menu and then Preferences.
  2. The Preferences dialog appears with a tree on the left side.

  3. Click on Editor
  4. Check the Automatically terminate the last line of the file checkbox
  5. Press either the Apply or OK buttons.

E. Enabling Line Numbers

You should enable line numbers so you can more easily find errors reported by the compiler.

  1. Click on the Configure menu and then Preferences.
  2. The Preferences dialog appears with a tree on the left side.

  3. Click on View
  4. Check the Line Numbers checkbox
  5. Press either the Apply or OK buttons.

F. Configuring Tab Settings

You need to configure tab settings so that your source code files are correctly formatted and you do not loose style points on assignments.

  1. Click on the Configure menu and then Preferences.
  2. The Preferences dialog appears with a tree on the left side.

  3. Expand the Documents Classes by clicking on the '+' sign.
  4. Expand the C/C++ tree
  5. Click on Tabulation
  6. On the right side there should be two checkboxes labeled "Convert new tabs to spaces" and "Convert existing tabs to spaces when saving"; check both of the checkboxes.
  7. Press either the Apply or OK buttons.

G. Enabling Syntax Highlighting

You need to enable syntax highlighting so that your source code files are display in color for keywords and strings.

  1. Click on the Configure menu and then Preferences.
  2. The Preferences dialog appears with a tree on the left side.

  3. Expand the Documents Classes by clicking on the '+' sign.
  4. Expand the C/C++ tree
  5. Click on Syntax
  6. On the right side, check the "Enable syntax highlighting" checkbox.
  7. In the "Syntax definition file" drop down list, select "cpp.syn".
  8. Press either the Apply or OK buttons.

H. Setting the Path on Vista and XP

To configure TextPad to compile C++ under Cygwin, you must add the Cygwin bin directory to your path. This is because you need the various Cygwin DLL's located in the bin directory to compile and run programs. Setting the path on Windows is a potentially dangerous operation and could temporarily disable your computer if done incorrectly. If you follow these instructions carefully, you and your computer will be fine. If this warning makes you too nervous, then get someone to double-check you as you perform these steps.

  1. Click the Start button in the lower left corner of the screen.
  2. From the Start menu right click on Computer or My Computer and select Properties.
  3. Click on the Advanced button or tab.
  4. In the Advanced tab of System Properties, click the Environment Variables button.
  5. In the Environment Variables dialog locate the Systems Variables section, highlight the Path variable and click the Edit button.

    You will see the Edit System Variable dialog shown below.

  6. In the Edit System Variable dialog, add the path to the Cygwin bin (usually C:\cygwin\bin) to the end of the Variable value: line.
    ;C:\cygwin\bin;

    Note that you must separate each path with a semicolon like the set of paths shown below. Do NOT copy the following path as it may break some programs on your computer. This is just an example. You must follow directions exactly when performing operations like this on a computer.

    C:\WINDOWS\system32;C:\WINDOWS;C:\cygwin\bin;

    After adding the path, press the OK button in the Edit System Variable dialog as shown below.

    Adding Cygwin to the path

  7. In the Environment Variables dialog, press the New button.

    You will see the Edit System Variable dialog shown below.

  8. In the New User Variable dialog, add an environment variable named CYGWIN with the value nodosfilewarning as shown in the image below.

    Adding Cygwin environment variable

    Adding this variable prevents warnings from Cygwin about the MS-DOS file path.

  9. Press the OK button in the New User Variable, the Environment Variables and the System Variables dialog boxes.

I. Compiling C++ Programs

After you have set the path, you can set up TextPad to compile programs.

  1. Click on the Configure menu and then Preferences.
  2. The Preferences dialog appears with a tree on the left side.

  3. Click on the Tools node of the tree.
  4. You will see a Tools dialog with an Add drop-down menu.

  5. Click on the Add button and then Program....
  6. The Select a file dialog appears.

  7. Browse to the Cygwin bin directory (probably C:\cygwin\bin), select the g++-3.exe (or g++-4.exe) file and press the Open button.

    Note: do NOT click on g++.exe. Always use g++-3.exe or g++-4.exe.

  8. Press the Apply button.
  9. G++ should now appear as a choice in the Tools tree.

  10. Expand the Tools tree and click on the G++ tool.
  11. You should see a dialog like the following appear:

  12. Make sure the Command text field is like the one shown.
  13. Set the Parameters text field to be:
  14. -W -Wall -pedantic -o $BaseName -I c:\cygwin\cccfiles $File

  15. Check the checkboxes as shown.
  16. Set the Regular expression to match output text field to:
    ^\(\(\(.[^:]\)\|\([A-Za-z]:\)\)[^:]+\):\([0-9]+\):
  17. Set the Registers as shown.
  18. Click the Tools node in the tree and you will see a list of tools. (1)

  19. Click slowly two times on the G++ label on the right-hand side, which will allow you to change the tool name. (2)

    Note: do NOT click on the G++ label under Tools on the left side.

  20. Rename G++ to something like Compile C++
  21. Press the OK button.

You can now compile C++ programs by selecting Compile C++ from the Tools menu. You can test the configuration by saving the following program as hello.cpp and then compiling. Verify that the file hello.exe is created when you compile.

#include <iostream>
using namespace std;

int main() {
    cout << "Hello, World!\n";
    return 0;
}

J. Compiling C++ Graphical Programs

To compile graphical programs, you need to add a graphics library to your Cygwin installation. For this course, we will use the Horstmann's CCC Graphics Libraries (cccfile) which you installed in step: B. Before You Begin.

  1. In TexpPad, click on the Configure menu and then Preferences.
  2. The Preferences dialog appears with a tree on the left side.

  3. Click on the Tools node of the tree.
  4. You will see a Tools dialog with an Add drop-down menu.

  5. Click on the Add button and then Program....
  6. The Select a file dialog appears.

  7. Browse to the Cygwin bin directory (probably C:\cygwin\bin), select the g++.exe (or g++-3.exe) file and press the Open button.
  8. Press the Apply button.
  9. G++ should now appear as a choice in the Tools tree.

  10. Expand the Tools tree and click on the new G++ tool you created.
  11. You should see a dialog like the following appear:

  12. Make sure the Command text field is like the one shown.
  13. Set the Parameters text field to be:
  14. -D CCC_MSW -I c:\cygwin\usr\include\w32api -I c:\cygwin\cccfiles -Wextra -pedantic -o $BaseName $File c:\cygwin\cccfiles\ccc_msw.cpp c:\cygwin\cccfiles\ccc_shap.cpp -luser32 -lgdi32

  15. Check the checkboxes as shown.
  16. Set the Regular expression to match output text field to:
    ^\(\(\(.[^:]\)\|\([A-Za-z]:\)\)[^:]+\):\([0-9]+\):
  17. Set the Registers as shown.
  18. Click the Tools node in the tree and you will see a list of tools
  19. Click slowly two times on the G++ tool, which will select the tool name and allow you to change it.
  20. Rename G++ to something like Compile C++ Graphics
  21. Press the OK button.

You can now compile C++ programs with the graphics libraries by selecting Compile C++ Graphics from the Tools menu. You can test the configuration by saving the following program as hellowin.cpp and then compiling. Verify that the file hellowin.exe is created when you compile.

#include "ccc_win.h"

int ccc_win_main() {
    Point p(1, 3);
    Message greeting(p, "Hello, Window!");
    cwin << greeting;

    return 0;
}

K. Running C++ Programs

After you have set the Vista and XP path, you can set up TextPad to run programs after compiling with the following steps:

  1. Click on the Configure menu and then Preferences.
  2. The Preferences dialog appears with a tree on the left side.

  3. Click on the Tools node of the tree.
  4. You will see a Tools dialog with an Add drop-down menu.

  5. Click on the Add button and then DOS Command....
  6. The Tool dialog appears.

  7. In the Tools dialog type: cmd.exe
  8. Press the Apply button.
  9. cmd.exe should now appear as a choice in the Tools tree.

  10. Rename the cmd.exe to Run C++ by clicking on the Tools node of the tree and then double-clicking on the cmd.exe tool.
  11. Expand the Tools tree and click on the Run C++ tool.
  12. Change the Parameters to: $BaseName
  13. Make sure the Initial folder is set to $FileDir
  14. Uncheck the Capture Output checkbox.
  15. Press the OK button.

You can now run C++ programs by selecting Run C++ from the Tools menu. You must compile the program before you try to run it.

L. Configuring the Documentation System

Doxygen is a tool for generating API documentation in HTML format from documentation comments in source code. To configure the tool to run with TextPad, use the following instructions:

  1. Download the following files and save them anywhere in your system path. I suggest that you save them in your Cygwin directory: C:\cygwin\bin.
  2. From TextPad's Configure menu, choose Preferences.
  3. The Preferences dialog appears with a tree on the left side.

  4. Click on the Tools node of the tree.
  5. You will see a Tools dialog with an Add drop-down menu.

  6. Click on the Add button and then Program....
  7. The Select a file dialog appears.

  8. Browse to the bin directory of where you saved doxygen.exe, select the doxygen.exe file and press the Open button.
  9. Press the Apply button.
  10. Doxygen should now appear as a choice in the Tools menu.

  11. Expand the Tools menu and click on the Doxygen tool.
  12. Change the Parameters line to:

    C:\cygwin\bin\Doxyfile.cfg

    If you saved the files somewhere else, you will need to change the path shown above.

  13. Set the Regular expression to match output to:
    ^\(\(\(.[^:]\)\|\([A-Za-z]:\)\)[^:]+\):\([0-9]+\):
  14. Set the Registers as follows:
  15. Check the checkbox labeled Capture output
  16. Also, check the checkbox labeled Sound alert when completed
  17. Press either the Apply or OK buttons.

After configuring the documentation system, you should run a sample program to verify the installation works correctly. One simple program you can run is the commented version of hello.cpp shown below:

/**
 * The hello.cpp program for checking Doxygen.
 *
 * @file hello.cpp
 * @author Ed Parrish
 * @version 1.1 06/22/06
 */
#include <iostream>
using namespace std;

/**
 * The main method for the application.
 */
int main() {
    cout << "Hello, World!\n";
    return 0;
}

To test the documentation configuration:

  1. From the File menu, choose New.
  2. Copy the above program to the new document page of TextPad.
  3. From the File menu, choose Save and save the file using the name hello.cpp to a convenient location like the Desktop.
  4. From the Tools menu, choose Doxygen.
  5. If there are no errors or warnings, you will return to the file document: hello.cpp. If there are errors or warnings, you will see a list of them in the Command Results page of TextPad.

  6. Open the html folder and find the file named: index.html.
  7. Open the index.html file in a web browser to view the generated documentation.

M. Configuring Keyboard Shortcuts (Optional)

After compiling and running programs many times, people get tired of using the menus. You can create shortcut keys for TextPad's tools to make compiling and running programs faster and easier as follows:

  1. Click on the Configure menu and then Preferences.

    The Preferences dialog appears with a tree on the left side.

  2. Click on the Keyboard node of the tree.

    You will see Categories and Commands as shown below.

  3. Select the Tools category from the list, and the tools commands will be displayed.
  4. Select the Tools command you wish to set a shortcut for.
  5. Type the keyboard shortcut combination in the "Press new shortcut key" box.

    Typically, tools are two key combinations using the Ctrl key and a number.

  6. Click the Assign button to set the shortcut.
  7. After assigning all the keyboard shortcuts, press the OK button.

TextPad shortcuts

Since I use TextPad for both Java and C++, I have set up the shortcuts as shown below:

Ctrl+1 Compile Java
Ctrl+2 Run Java Application
Ctrl+3 Run Java Applet
Ctrl+4 CheckStyle
Ctrl+5 Javadoc
Ctrl+6 Compile C++
Ctrl+7 Compile C++ Graphics
Ctrl+8 Run C++
Ctrl+9 Doxygen

<< Back