Click here to Skip to main content
Click here to Skip to main content

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

Introduction

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 !

License

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

Comments and Discussions

 
GeneralPuzzle PinmemberJason Hooper19-Apr-02 6:50 
GeneralRe: Puzzle PinmemberRick York19-Apr-02 12:04 
GeneralRe: Puzzle PinmemberJason Hooper19-Apr-02 16:09 
GeneralRe: Puzzle PinmemberJordan Walters5-Apr-05 22:55 

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

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

| Advertise | Privacy | Mobile
Web03 | 2.8.140718.1 | Last Updated 18 Apr 2002
Article Copyright 2002 by Rick York
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid