Click here to Skip to main content
15,868,141 members
Articles / Desktop Programming / MFC
Article

Brainchild, A syntax coloring edit control

Rate me:
Please Sign up or sign in to vote.
4.85/5 (64 votes)
16 Jun 2005CPOL5 min read 700.6K   26.8K   263   237
Syntax coloring, multi-level undo/redo editor control.

Image 1

Image 2

Notes

The search and replace dialogs in version 2.4 and higher of the brainchild control are non-modal. This will require you to call the newly introduced API IsNonModalDialogMessage() in the main message loop of your application. Old code using the control should be updated. Failure to do so will result in shortcut keys and tab/shift tab navigation not working.

The compiled binaries archive contains the compiled versions of brainchild.dll, bcc.cpl, BCDemo.exe and brainchild.ocx. Please note that the setup as explained below is still needed to make it all work.

Introduction

Brain child is an editor control which supports all the bells like syntax coloring, multi-level undo/redo etc. The editor control comes in three parts.

  1. Brainchild.dll which is the editor control. It is the core component which is written in C.
  2. BCC.cpl which is the configuration control panel applet. This is written in C++ and depends on my ClassLib library.
  3. Brainchild.ocx which is an ActiveX wrapper for the control. It is written in C++ using MFC. This OCX makes it possible to used the brainchild control in VB or .NET applications.

In addition, I have included a simple MDI editor demonstration program called BCDemo which is written in C++ and also depends on my ClassLib library.

Features

Brainchild supports most modern editor capabilities including:

  • Syntax-coloring, fully configurable. Syntax coloring is supported both on screen and on printer output.
  • Multi-level undo/redo. Maximum number of hops configurable.
  • Bookmarks.
  • Line numbers.
  • Fully configurable keyboard mappings.
  • OLE drag and drop support.
  • Automatic/smart indentation.
  • Automatic case fixing.

How to get started

I have not included an installer package. This means that you must follow several steps to get the editor up and running.

  1. Download the source code (DLL, CPL, OCX (optional), BCDemo) or the compiled binaries. If you decide to use the compiled binaries, you still need to download the DLL source code. It contains necessary setup files which you will need to get things running. If you use the compiled binaries only, you can go to step 7.
  2. Download, setup and compile the ClassLib C++ library.
  3. Compile the brainchild DLL.
  4. Compile the brainchild CPL.
  5. Compile and register the brainchild OCX (optional).
  6. Compile the BCDemo demonstration program.
  7. Create a directory on your hard disk where you can put the brainchild configuration files.
  8. Copy the directory Defaults, which you can find in the DLL source zip, including all its contents to the created directory.
  9. Open RegEdit.
  10. Add the key HKEY_LOCAL_MACHINE\Software\BCDLL\CurrentVersion. (Be careful using the registry editor!)
  11. In the key, add the string value Settings and set its value to the directory you created for the brainchild configuration files.

To get the demonstration program up and running, copy the branchild.dll, brainchild.ocx and bcc.cpl files to the directory containing the BCDemo executable and you should be able to run the demonstration program. Do not forget to register the OCX if you want to use it. You can use RegSvr32 to register the OCX. Once you get it up and running, you might also want to download the HTMLHelp docs. It will explain, how to use brainchild in your own programs and how to use the configuration tool.

What's New

Version 2.4

  • Enhanced the Find and Replace dialogs.
  • Much better printer support.
  • Added support for background colors.
  • Added bracket and line highlighting.
  • Added an ActiveX wrapper so that brainchild can be used in VB and .NET apps.
  • Added support for hyperlinks.
  • Fixed some bugs.

Version 2.3

  • Fixed a couple of nasty bugs.
  • Support for loading and saving Unicode files (limited support for loading and saving only).
  • Added case-fixing. When turned on, this will automagically fix keyword casing. Suggested by Zodiakon.

Version 2.2

This version includes a WTL wrapper and a small WTL demonstration program (VS6 workspace only) by Ernest Laurentin which you can download using the links above. For this release, only the Brainchild_dll.zip and Brainchild_help.zip were updated. The Brainchild_wtl.zip was added. The BCC.cpl and BCDemo source were not updated so version 2.1 users do not have to download these. Also note that the VS7 solution is a Visual Studio .NET 2002 solution. I presume you can load this into Visual Studio .NET 2003 without any problems.

  • The control now loads if the registry keys are not set. If they are, the directory configured must have the "Defaults" directory including contents copied into it.
  • Added the LoadParserFromFile() and LoadParserFromMemory() APIs including corresponding messages. These will allow you to add parser files at run time.
  • Fixed a nasty bug which could crash brainchild after receiving a WM_DESTROY. This has been fixed.

Version 2.1

  • Line numbers. The control now supports the possibility to show line numbers.
  • WM_PRINTCLIENT support.
  • WM_MOUSEWHEEL support.
  • Some bug fixes. Mostly small rendering bugs when run under Windows XP.

Version 2.0

  • Initial release on the CodeProject.

Thanks

The control has been re-written several times over the last years. To get it to where it is now, I have based some of the code on the work of Andrei Stcherbatchenko's CrystalEdit component. The code which was based on his work mostly covers the undo/redo and text buffer stuff.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer (Senior)
Netherlands Netherlands
I have been programming for a hobby since 1985. I have started programming on the C= 64. After that I migrated to the C= Amiga which I traded in for a PC back in 1997 I believe. Back in 2000 I decided to lose a hobby and start developing software for a living.

Currently I am working mainly in developing software for building security and access control systems.

Comments and Discussions

 
GeneralAccess Violation in UpdateSettings Pin
ReorX17-Aug-05 5:34
ReorX17-Aug-05 5:34 
GeneralRe: Access Violation in UpdateSettings Pin
Jan van den Baard17-Aug-05 19:58
professionalJan van den Baard17-Aug-05 19:58 
GeneralRe: Access Violation in UpdateSettings Pin
ReorX23-Aug-05 5:08
ReorX23-Aug-05 5:08 
GeneralRe: Access Violation in UpdateSettings Pin
Jan van den Baard14-Sep-05 22:57
professionalJan van den Baard14-Sep-05 22:57 
GeneralOCX and VB6 Pin
SlackerDev28-Jul-05 11:26
SlackerDev28-Jul-05 11:26 
GeneralRe: OCX and VB6 Pin
Jan van den Baard28-Jul-05 23:34
professionalJan van den Baard28-Jul-05 23:34 
GeneralRe: OCX and VB6 Pin
Shakti Goel18-Aug-05 10:02
Shakti Goel18-Aug-05 10:02 
GeneralRe: OCX and VB6 Pin
Jan van den Baard18-Aug-05 19:48
professionalJan van den Baard18-Aug-05 19:48 
Shakti Goel wrote:
THe control looks great and it seems to do all I want for SQL scripts. My question is regarding using the control in VB6. If I understand it correctly, I need to do the following

1. Create a folder C:\VBProject
2. Save the dll, cpl and ocx in this folder.
3. Copy the Defaults folder in VBProject folder.
4. Update the registry to point to the location of the Default Folder
5. Register the ocx control
6. Reference the control in teh VB project
7. Add the control to a Form.



Actually you can do not need to copy the brainchild stuff into the VB project directory. You can copy it into it's own directory anywhere on your hard disk. You need update the registry to point to the settings folder in which the Defaults directory is located. I.E. if you have a directory structure like this:

C:\
    Brainchild
        Settings
            Defaults


you should point the registry key to "C:\Brainchild\Settings". For the rest (registering, referencing etc.) should work as you described.

Shakti Goel wrote:
At this point, how do I set the langauge to be SQL, set linenumbering to true, add bracematching etc.? Do I need to bring up the configuration editor? How can I do that?

You do not need to do any setup to load SQL files. When you load a file into the control with the ".sql" file extention the control will automatically choose T-SQL highlighting. For extra settings like line numbering etc. you need to use the control panel applet.


Shakti Goel wrote:
The help file states

"The brainchild package includes next to the control itself also a program to configure brainchild. This program, when installed, will add an entry in your control panel called "Brainchild Configurator". With this program you can control the options and settings of the brainchild control."

While I can invoke the config editor from the demo program, I am not sure how to link the Configurator to the control on the Form in my VB6 application. Also, I do not see the configurator in the Control Panel.

Please suggest.


That line from the documentation is left over from the time brainchild still was distributed as an install package. This install package automatically installed the CPL into the system32 directory. If you want to be able to configure brainchild using the control panel you can copy the CPL and DLL in the System32 directory.

If you simply want to use the control panel applet from you VB application a simple call to the SettingsDialog() method of the OCX should suffice.

Enjoy,
Jan




We are the all singing, all dancing crap of the world. - Tyler Durden
GeneralRe: OCX and VB6 Pin
Shakti Goel19-Aug-05 4:29
Shakti Goel19-Aug-05 4:29 
GeneralRe: OCX and VB6 Pin
Shakti Goel19-Aug-05 4:33
Shakti Goel19-Aug-05 4:33 
GeneralRe: OCX and VB6 Pin
Jan van den Baard14-Sep-05 23:48
professionalJan van den Baard14-Sep-05 23:48 
GeneralRe: OCX and VB6 Pin
Jan van den Baard14-Sep-05 23:16
professionalJan van den Baard14-Sep-05 23:16 
GeneralRe: OCX and VB6 Pin
SlackerDev21-Sep-05 11:50
SlackerDev21-Sep-05 11:50 
GeneralRe: OCX and VB6 Pin
Jan van den Baard21-Sep-05 19:52
professionalJan van den Baard21-Sep-05 19:52 
GeneralCould not download ClassLib file Pin
hulinning18-Jul-05 4:51
hulinning18-Jul-05 4:51 
GeneralRe: Could not download ClassLib file Pin
Jan van den Baard18-Jul-05 19:34
professionalJan van den Baard18-Jul-05 19:34 
GeneralRe: Could not download ClassLib file Pin
hulinning19-Jul-05 10:28
hulinning19-Jul-05 10:28 
GeneralBugs with brainchild Pin
asdf50030-Jun-05 1:31
asdf50030-Jun-05 1:31 
GeneralRe: Bugs with brainchild Pin
Jan van den Baard30-Jun-05 2:13
professionalJan van den Baard30-Jun-05 2:13 
GeneralRe: Bugs with brainchild Pin
asdf50030-Jun-05 3:01
asdf50030-Jun-05 3:01 
GeneralRe: Bugs with brainchild Pin
Jan van den Baard30-Jun-05 3:50
professionalJan van den Baard30-Jun-05 3:50 
GeneralRe: Bugs with brainchild Pin
asdf50030-Jun-05 3:56
asdf50030-Jun-05 3:56 
GeneralDLL Source zip file updated Pin
Jan van den Baard19-Jun-05 20:07
professionalJan van den Baard19-Jun-05 20:07 
GeneralRe: DLL Source zip file updated Pin
h.lee7-Dec-05 8:49
h.lee7-Dec-05 8:49 
GeneralRe: DLL Source zip file updated Pin
Jan van den Baard8-Dec-05 19:36
professionalJan van den Baard8-Dec-05 19:36 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.