<!-- Download Links -->
<!-- Article image -->
<!-- Add the rest of your HTML here -->
First I want to point out that this application is primarily for amusement. There are some moderately useful pieces of code for beginners but I mainly wanted to share this app with the Code Project denizens.
In one of my first programming jobs I worked on a Unix-derivative called QNX. It had a little command-line program that displayed fortunes and my original list of fortunes began with their's. Many of those originals are from Robert Heinlein novels and lately I have added several from the signatures of various CP members. Where possible (and I remembered to) I have noted the origin of the saying. Please feel free to send additions by e-mail and I will periodically update this article.
To use this app, place the executable and the fortunes file (Fortunes.txt) into the directory of your choice. The app requires the fortunes file to be in the same directory as it. Once the app is started you can alter the display colors and font. All settings will be kept in a file called Fortune.ini also in the same directory as the application. The app will display a random fortune every time it is started. The current time is used to seed the random number generator. Click the button labelled "New" to see a new fortune.
The fortunes are read from a standard text file. Each fortune occupies one line in the file. Currently the program has definitions that limit it to 2000 fortunes of up to 1020 bytes each. My current list of fortunes has 472 entries in it and the longest is 206 bytes. Note that only the exact amount of text is stored internally. Any standard text editor can be used to add or remove fortunes from the file.
This program was written in straight C using no other libraries. Actually, it is the first application I ever wrote for Windows and it was written many years ago. As such, some of the code is a bit inelegant to put it lightly. I recently went through and cleaned some things up a bit but I do not think that a full re-write was warranted.
There are a few interesting pieces of code in the app. The gradient background fill is one I conjured up myself. It does a simple linear interpolation between the top and bottom color on each shade for each vertical line in the window. An array of brushes is maintained for the entire window and it is updated when the colors are changed or when the window is resized. It uses floating point values to do the interpolation in an attempt to be as smooth as possible. There is also a handy little profile reading and writing library. It includes functions for handling fonts, colors, rectangles, and window position. The text toolbar buttons came from an old MSDN sample.
If you just want to run the app you can grab its zip file. The fortunes and a release build executable are included in that zip. Otherwise, grab the source and you can build it yourself. The fortunes are included in the source zip also. There is a little batch file for building from the command line. It is called _makeme.bat and it will generate a release build.
Well, that's about it. Send me any good sayings you run across and have fun !