Click here to Skip to main content
13,356,318 members (63,864 online)
Click here to Skip to main content
Add your own
alternative version


20 bookmarked
Posted 17 Apr 2002

Windows Fortune Application

, 17 Apr 2002
Rate this:
Please Sign up or sign in to vote.
This application will display a random fortune in the font and colors of your choice.
<!-- Download Links --> <!-- Article image -->

Sample Image - Fortune.gif

<!-- 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 !


This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


About the Author

Rick York
Software Developer (Senior)
United States United States
No Biography provided

You may also be interested in...


Comments and Discussions

GeneralPuzzle Pin
Jason Hooper19-Apr-02 7:50
memberJason Hooper19-Apr-02 7:50 
GeneralRe: Puzzle Pin
Rick York19-Apr-02 13:04
memberRick York19-Apr-02 13:04 
GeneralRe: Puzzle Pin
Jason Hooper19-Apr-02 17:09
memberJason Hooper19-Apr-02 17:09 
GeneralRe: Puzzle Pin
Jordan Walters5-Apr-05 23:55
memberJordan Walters5-Apr-05 23:55 
Generalwoohoo! Pin
Chris Maunder18-Apr-02 15:01
adminChris Maunder18-Apr-02 15:01 
I haven't seen fortune in years!

Just some thoughts on the gradient (I've not looked at the code - just having a brain dump). I did a project once that required 256 colours to be repeatedly drawn (landscape shading). One of the issues was the time it took to create and destroy the brushes, so I took your approach of caching brushes between draws. The problem was that if I had 4 windows open at once (it was MDI, with different shading in each window) the system would quickly run out of pens. I ended up doing creating the brushes in one hit pre draw, then tearing down post-draw. Not elegant, not as fast as it could be, but at least it kept working. Then I went to OpenGL Wink | ;)

Anyway, you just tweaked a memory about brush creation for shading and at the time I remember thinking 'Ah - if only that had a gradient brush!'

Chris Maunder
GeneralRe: woohoo! Pin
Rick York18-Apr-02 15:52
memberRick York18-Apr-02 15:52 
GeneralRe: woohoo! Pin
Chris Losinger19-Apr-02 8:05
memberChris Losinger19-Apr-02 8:05 
GeneralRe: woohoo! Pin
Chris Losinger19-Apr-02 8:02
memberChris Losinger19-Apr-02 8:02 

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.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.180111.1 | Last Updated 18 Apr 2002
Article Copyright 2002 by Rick York
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid