Do you still have old DOS-Programs based on CA-Clipper running on your system? This Howto shows you, how to speed up those programs by compiling them with hmg.
Since the introduction of Windows XP, you probably get a 100% CPU-Usage as soon as you start your exe.
Even if your application is only waiting for user-input, it keeps your computer busy.
I can not fully explain the reason. But Clipper was not designed to be run in a multitasking environment and windows goes through great trouble to emulate a DOS-environment. So now as soon as your old program runs, even the fastest core duo system slows down to a creep. If you run it on a laptop, your batteries are empty quicker than you can say uncle.
Solution: Compile a Windows-friendly exe
But it does not have to be this way.
If you still have your source-code, you are lucky. You can compile it almost without any changes and turn it into an application that looks exactly the same, but runs much quicker and consumes only CPU-cycles when it is doing something.
There are many Clipper compilers out there. Some of them are even free.
The compiler: Harbour
Harbour is a great compiler. It will take your Clipper source-code and turn it into C-Code that can be compiled into a binary. You can choose your compiler and there are many libraries that add functions to your program you never dreamt of. It will even run on Linux and Mac-OS.
HMG: A harbour-compiler with batteries included
If you are not interested in Linux and Mac-OS and all the fancy features, you just want an application that installs everything you need. A C-Compiler, binaries and batch files and even a lot of
Such a program exists. It is called "Harbour MiniGUI", or just "hmg" for short. Visit the developers website:
You can grab the latest version here:
At the time of writing this post, 3.0.22 is the latest version. It is a 20 MB download. Users at hmgforum.com confirm, that it runs well with Windows Vista and Windows 7.
Update: Right now, the current stable version is 3.0.39 if you don't need postgresql-suppprt.
hmg 4.0 ist still in alpha-state. It's goal is to port the windows-api based gui to Qt and make it platform-independent. Be patient. It is not ready, yet.
After you downloaded, the setup file, you can run a regular installer.
I recommend installing it into c:\hmg
Starting the IDE
The installation takes a few seconds. After it is finished, you have everthing you need. Compiler, Linker, Include-Files, etc.
You could compile your prg-files on the command-line, but I prefer the graphical IDE. It gives you a glipse into the many additional features you get with HMG.
Launch the hmg-ide either from the shortcut on your desktop or the startmenu.
Start a new Project.
You can place the project into your existing source-code directory on your harddrive. Make sure, you have a copy in case anything goes wrong.
The IDE creates a new "Main.Prg" and a new emty form "Main.Fmg".
Removing Main.Prg and Main.Fmg
HMG is a great tool to build real Windows-Applications. It is abolutely amazingly simple to turn an existing Clipper-Program into a Windows-Program. But for now, we resist the urge to look at all the shiny features.
All we want to do is compile our console application.
So for now, we don't need the Main.Fmg and Main.Prg. Delete them by selecting them in the Project-Browser and clicking Project - Delete File from the Menu.
Adding your Source-Code to the IDE
Now you have an empty Project. Choose "Modules" in the Project Browser and click on "Project" - "Import File" in the Menu to import your all your prg-files.
The first one you choose will be your main-module. That means, it includes the procedure or function that starts the program. You can declare a module as main by clicking "Project" - "Set Module As Main" in the menu.
By default, HMG wants to build a Windows-Application. But your old CA-Clipper-code is a console application.
So you have to tell the compiler to run in "Console Mode". You do that in the Project Browser in the Configuration-Tab.
Update: If you are using Version 3.0.39, there is noc "Console mode" any more in the "Configuration"-Tab. Don't panik. It still works. Simply add this line to your main .prg-file:
To be more precise, you now have a mixed-mode program. That means, you can already use windows-gui elements wherever you like.
Edit your Code
In some cases, you have to make little adjustments to your code.
Most importantly, harbour looks for a function or procedure "Main". If it does not find it, it will not do anything, because it does not know where to start.
Clipper also supported the first function to be named like the .prg-file. So open your prg-file with an editor of your choice and rename the main function.
The old prg-file will be saved in the codepage 850.
My favorite editor is jEdit. It calls the codepage IBM850. If some characters (umlauts, accents, box-drawing-characters, etc.) look funny, click "File" - "Reload with Encoding" - "IBM850".
Do not change the encoding. Keep it 850 for your console application!
Compile your code by clicking "Project" - "Run" in the Menu.
HMG will build an .exe-file and launch it. So if all goes well, your program starts.
The new exe-File is rather large (1-2 MB) compared to an original clipper-exe. But who cares nowadays, right?
Here is a screenshot of a sample console application. As you can see, the wait-command does not keep the Processor busy.
This howto demonstrated, that you don't have to through away your old Clipper code and write it in a new language if you want an application that works well on Windows.
With hmg you can turn it into a modern harbour-console-program for windows within a few minutes.
You can now incrementally modernize your program. You might mant to start by replacing ALERT() with msgbox() to see how well it mixes.
HMG opens a lot of possibilities to really take old application to the 21st century.
I find it very impressive, that Roberto Lopez managed to extend the xBase Language, so that modern GUI-Controls can be defined in an easy to understand way.
Code looks like this:
AT 0,0 ;
WIDTH 400 ;
HEIGHT 200 ;
TITLE 'Tutor 10 - Picture Button Test' ;
@ 10,10 BUTTON PictureButton_1 ;
PICTURE 'button.bmp' ;
ACTION MsgInfo('Picture Button Clicked!!') ;
WIDTH 27 ;
HEIGHT 27 ;
TOOLTIP 'Picture Button Tooltip'
ACTIVATE WINDOW Win_1
The IDE helps you build this code by designing your forms in a gui-designer.
If you want to know more about HMG, take a look at C:\hmg\SAMPLES and c:\hmg\DOC\hmgdoc.htm (also available online).
I found the people over at hmgforum.com very nice and helpful. They helped me when I got stuck and reading the forum gives a lot of insights.