January 20, 2022, 08:01:01 AM


Own IWBasic 2.x ? -----> Get your free upgrade to 3.x now.........

Andy's editor - An example of a rich edit control editor & documentation

Started by Andy, September 17, 2020, 04:00:39 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.


Welcome to my rich edit editor example program (BETA) edition.

***** Please go down to the last post here for the latest version ****

Please read the whole post first.

Firstly a warning! before loading any of your files you must make a copy of them first.
Two months ago I had problems with the wrong code being saved to the wrong file, but after
working on the proglem I have had no such issues since.

So what have I got for you here?

The culmination of almost a full year's work to produce this editor.

I have posted it here in the "Tutorials" section as it is a working example of how to
write an editor program using a rich edit control.

If you have time then I need your help!

I am very proud of the fact I was able to keep on going with this program and get it
working - that said, there is only so much testing one person can do.

I don't know exactly how you use an editor, the things you find handy, the things you
you might want - I simply don't know that.

You will I am sure find bugs in it - please tell me so I am aware of them.

The purpose of the editor:

1. To learn about rich edit controls and how they work.
2. To make all IWBasic key words either uppercase or lowercase.
3. To colour all IWBasic key words.
4. To allow editing of a file.
5. To have auto complete of key words included.
6. To be able to find & search for things in the file being viewed.
7. To incorporate an undo & redo function.
8. To load multiple files.
9. To do fast colouring and scrolling.

To that end, it is done.

What this program is not or what you will see:

1. Not an example of the best programming
2. Repeated code - I make no appologies for this
Many times I have changed on part of the program only to find out it has messed
up one or more other things - so for now I have left it as it is.

The attachment:

In the attachment you will have the following

1. Xedit46 V2 . iwb (Bin \ Bin folder)
2. Xeditor    . inc (Bin \ Bin folder)
3. The user guide  (Bin \ Bin \Res folder - can open via the editor)
4. Comctl32  . lib (Copy to your Libs folder please)
5. Ctl        . lib (Copy to your Libs folder please)
6. Ctl        . inc (Copy to your Include folder please)
7. A guide to working with rich edit controls including a detailed
explanation of how to implement the undo & redo functions yourself.
(Think you will find that one interesting!)

How to compile:

1. Create a folder on your C drive.
2. Unzip the attachment.
3. Copy the .lib & .inc files over.
4. Go to the Bin folder & compile Xeditor46 v2.iwb as F8 (a single file compile)

I really do need feedback please, tell me if you like it, hate it, if it's useful or even

Known issues:

Large files can take several seconds to load, this really hasn't been my focus here, but
it's something I will work on.

Future development:

1. Fix any bugs reported.
2. Look into the idea of a pre-compile file check.

I have already started this in a small way by checking how many ( ) [ ] (brackets) there
are on a selected line. I always miss a ")" and get a compile error.

3. To tidy up and use less repeated code.


I have titled the program The 2020 Hindsight Editor, well we all have 20/20 hindsight, and it is the year 2020, if I only knew at the start what I know about rich edit controls now...

With all that said here goes...

Day after day, day after day, we struck nor breath nor motion, as idle as a painted ship upon a painted ocean.


I also wanted to say a very big THANK YOU to all of you who have any any way, shape or form helped me to get this far with the program.

Be it, solutions, hints, tricks, tips & feedback.... Thanks!

I've added a second attachment to the original post which has the exe file included.

I also thought it might be an idea to unpick the program a little for you.

The program unpicked.

The program contains a lot of very standard code such as creating controls,
showing / hiding them, and button clicks. These things will be of little
interest to you.

However, there are certain subroutines, chunks of code that you should home in on.

In the main program:

Subroutine - QuiteMode (wrongly spelt of course - should be QuietMode!)

I'm using

QuiteMode(1) switch before I set sel selections / colour / replace etc.
and when done

It stop visual highlighting, and greatly speeds up the process - recommended.

In the indlude file:

Subroutine - GetAllWordsOnLine.

This is the fastest way I have found to build up words on a line.
I am chaecking each character in that line to see if it is a
delimiter, i.e. anything other than letters A - Z (upper or lower case).

I'm using the ISTRING variable CheckLetter4, it looks like this:

ISTRING CheckLetter4[50] =  CHR$(34) + "' ,0123456789-+()[]=:<>&|.\/%*!<>^_~#?" + CHR$(9) + CHR$(13)  + CHR$(0) + CHR$(10) 'Includes tabs and quotations.

Now it could be argued that it would be faster to check the ASCII value of that character...

IF Letter >= ASC(...) or Letter <= ASC(...)

The answer to that question remains to be seen, as it stands for me, the operation is quick enough, but I should test it one day.

Subroutine - ColourLineZ.

Basically a variant of the above routine, I use this for key word matching, when we have a complete word I invoke another
subroutine called:


This subroutine checks to see if the word is a key word, if so, it changes it to either uppercase / lowercase or as typed
depending on your preference. Either way, it is then coloured in the rich edit control and the program returns back
to subroutine ColourLineZ.

This process is repeated for every word on the line, and for every line it is told to check.

In the main program:

You will see the above process being called when you look at my now badly named GetTheScrollPos.

GetTheScrollPos was originally used to get the current scroll position first then colour what you can see on screen.

In most circumstances, the variable FirstVisLine is set like this:
FirstVisLine = SENDMESSAGE(rHandle,EM_GETFIRSTVISIBLELINE,0,0) - rHandle is a handle to my rich edit control.

Armed with the first visible line number, GetTheScrollPos will now colour from 2 lines before the first visible
line to the first visible line plus 30. I have 29 lines visible, so I'm just making sure here.

Subroutine - Rich_Edit_Handler.

This is the handler for the sub classed rich edit, it is a must that you sub class your rich edit or you will not
be able to control what happens for certain actions.


Some keys are not detected by WM_CHAR, so this is an important check as it will tell all key presses and what they are.


Probably the most important one, if it's a letter / number / space etc then I record that letter in the Undo array.
But I still need CASE WM_KEYDOWN because key presses like the Delete key are not detected here.

In any case, the important thing to remember here is that there are some things I need to do / record / check before
the Rich_Edit_Handler does a RETURN, and some things I need to do after the Rich_Edit_Handler has returned.

In other cases, I don't want it to do anything else other than what I'm telling it to do.

Subroutines DoUndo & DoRedo.

These, I hope you find of particular interest and it would be better for you to both read the guide help file as you
flick your way through these two routines.

Subroutine - Search_And_Highlight.

For those of you who are interested in how I did the auto complete function, I will try to explain here.

The process:

I'm using a fast timer

CASE 10000 - a control number way out of the other main controls.

In there I am getting all the words for the line you have clicked on.
(sub routine GetAllWordsOnLine - located in the include file).

I am also calling the subroutine GetAllWordsOnLineKeyWord - located in the include file, every time there
is a WM_CHAR action in the Rich_Edit_Handler routine.

All words on that line are stored in pointers called "w" & "m" and I have a global variable called WordCount.

Each word is stored like this:

(GetAllWordsOnLine sub)
WordCount ++
#w[WordCount].aWord    = WordIn
#w[WordCount].StartPos = StartPos
#w[WordCount].EndPos  = EndPos
#w[WordCount].Length  = (EndPos - StartPos)

WordCount ++
#m[WordCount].aWord    = WordIn
#m[WordCount].StartPos = StartPos
#m[WordCount].EndPos  = EndPos
#m[WordCount].Length  = (EndPos - StartPos)

WordCount is zeroed before every call just in case you were wondering.

The #w pointer tells me what the word was before typing a character.
The #m pointer tells me what the word is now.

I then check the edit position, i.e. where you are on that line.
If the edit position has changed I update the word number edit box on screen to display the word number, that is to say
you are on word 1 or word 2 etc.

In the normal handler called main, under

CASE 1 'Rich edit

I get the word number I am on from the word number edit box, and pass that word to the
search and highlight routine like this:

TheWordSelected = VAL(getcontroltext(w1,WordNumberEdit))

Search_And_Highlight will try to find any possible matching key words like

OPENFILE etc when the word we are on is "open".

When key words are being show on screen, I set a global variable called kw to 1, otherwise it's zero.

Finally, should I press the enter key on a highlighted key word (shown in a list view control) and kw = 1
the word that I'm on is replaced with the key word.

The whole line is then re-coloured and key words are set to uppercase / lowercase etc.

Simple yes? - nope!

Hope again, this is a little clearer than mud for you all.
Day after day, day after day, we struck nor breath nor motion, as idle as a painted ship upon a painted ocean.


For those of you who just want to read through the editor user guide, I have added it as a separate attachment so you ca have a look at it and see what the program does, and what the functions / buttons do.

The attachments are at the top of this post.

Day after day, day after day, we struck nor breath nor motion, as idle as a painted ship upon a painted ocean.


November 08, 2020, 04:26:33 AM #3 Last Edit: December 17, 2020, 04:44:43 AM by Andy

***** Please go down to the last post for the latest version *****

Firstly, here is an old proverb...

"A man who is afraid to make mistakes is unlikely to make anything" - wise words.

I'm sure you'll find some bugs somewhere - please reports bugs / questions etc here:


So let's begin.

As I said previously, even if you are not remotely interested in rich edit controls at all you should still have a look.

There's lots of interesting code in here I'm sure you will agree.

To help you along I have added a help file "Code of interest". It hopefully tells you what you may find interesting and where to look.

What's new?

Well lots.

1. I have rationalised the main screen.
2. Made it much easier to find & replace things.
3. Auto complete of key words now included when you are typing in the find edit box etc.
4. The ability to find controls, both creation point & case statement.
5. A refresh button so you can work with both editors at the same time.

My findings:

1. My original gut feeling was correct all along, the ability to move around code quickly helps you program.
2. You can do this even faster if you run both my editor and LarryMc's IWB editor together - a pleasing discovery! - you get the best of both worlds.
3. You may never use this as an editor, more of a code finder - it's up to you.


This program is provided as-is without any guarantees of fitness of purpose either expressed or implied,
by using this program you accept this and use it completely at your own risk.

Before loading any of your files, make a copy!

Screen resolution - 1366 x 768 or greater.
The icons are kindly provided by Open Icon Library
Please read the license file for more information. 

How to:


Before running the editor for the first time, you need to amend one of it's files.

Please see bug fix 1:


After that, follow the steps below and everything should be okay...

1. Create a folder.
2. Extract all files to that folder.
3. Copy lib files to your IWB lib folder.
4. Copy any inc file to your IWB Include folder.
5. Compile as single file (F8) option.

Both the source file & the exe file are in the "Bin" folder.

There is a ready made exe file (Andy's Editor46 v4.exe) if you just want a look BUT - you must extract all files / folders first before running it.

This really is now a full years work - bugs and all.

"Lest we never forget" - to all those who lost there lives in conflicts, we remember you always.  :'(

Attached is the file.

Day after day, day after day, we struck nor breath nor motion, as idle as a painted ship upon a painted ocean.


December 17, 2020, 04:33:40 AM #4 Last Edit: December 18, 2020, 05:08:12 AM by Andy

 Here is the new version for download (all 26,000 lines of code!)

But I must tell you this first:

"I was once offered a job as a contortionist, but I managed to wriggle out of it", (Hope that made you smile a little).

I hope as well that I have managed to wriggle out of my last release, which fixed many things but also had a start up issue.

As always, ask your questions here please:


This program has almost become an "how to do ... " in IWBasic, so please when you get some time, have a look at the code - and ask questions!!!

This program is much more than simply an editor, use it and you'll find it's a huge time saver too.

Thanks to all of you who have helped, whatever you did.

This is what you can do when you work around 8 hours a day, for almost 365 days on a program...

A gift from me to you, happy Christmas.

Attached is the download and exe file.

Day after day, day after day, we struck nor breath nor motion, as idle as a painted ship upon a painted ocean.



Quite a few people have asked for just the runtime (exe) file of the editor.

Here it is...

1. Create a folder.
2. Unzip the exe file to it.
3. Run it (first time use) as administrator.

It will create the folders it needs, copy files to these folders then run.

Due to the self setup it does, there may be a delay of 3 or 4 seconds before you see the editor screen, this is normal so be patient!

Any problems, please ask here:

Day after day, day after day, we struck nor breath nor motion, as idle as a painted ship upon a painted ocean.



      The 2020 Final version source code:


"I once got lost in the desert with a compass, but at least I was able to draw perfect circles in the sand..."

Moving swiftly on from that gem:

What's new?

I've added in some great new features to help you code faster, try them and you'll see I'm sure.

1. You can now quickly generate code for controls including your own user defined commands.
2. You can even group controls from different windows together, you can then create some code for them, for example show / hide them - very handy especially in larger programs.

I have also made the buttons / tool tips much more interactive with what you are currently doing / viewing.

Here is the source code for you all, included is the new help file located in the "Res" folder if you just want to have a look at it.

I have changed this now to a project so it can now be run as a stand alone exe file.

What you need to do:

1. Create a folder.
2. Unzip the files to it.
3. Add the new project to your IWB editor.
4. Accept that the location has changed.

You now need to build (compile) the resource file - I could not include the resource file as the zip file would have been much larger (far too large to upload).

You will probably get an error at this stage - if so save everything and close the IWB editor.

Go back to the zip file and in the "Bin" folder copy the .rc file to the "Bin" sub folder of your new folder - it seems to get emptied so over write it.

You should now be able to compile the resource file.

Finally, compile / build / run etc.

As with the run time version, there may be a delay for a few seconds before the editor screen appears for the first time.

Any problems / questions etc please ask them here:

Day after day, day after day, we struck nor breath nor motion, as idle as a painted ship upon a painted ocean.