Blog  ||  Projects  ||  Google Hacks  ||  Artificial Life  ||  Search  ||  About

Canned laughter

Canned laughter box is a small executable consisting of one button that when clicks, plays a laughter sound. The idea is that you can install this program and anytime somebody tells a joke, press the button. In comedies they use canned laughter to make jokes seem funnier. Why not in real life.

Apart from the practical (or not so practical) side of the program, the source illustrates two programming techniques, embedding sounds in an exe and the use of hot keys.

Sounds are embedded by creating a simple .rc script and compiling that using the Borland Resource Compiler, i.e. if sounds.rc contains:

SOUND1 SOUND "Laugh.wav"

Then type brc32.exe from the command line. Include the resulting res file with {$R Sounds.RES}. The sound is played with:

    h1:=FindResource(HInstance, 'SOUND1', 'SOUND');
    h2:=LoadResource(HInstance,h1);
    p:=LockResource(h2);
    sndPlaySound(p, SND_ASYNC or SND_MEMORY);

Hot keys are done by RegisterHotkey and then responding to the WMHotKey message. RegisterHotkey is passed an Atom value, created with GlobalAddAtom. If you press Ctrl-F11, the sound is player.

I compressed the exe using upx, a utility that compresses .exes.


downloadable files:

Laughter.exe Executable ready to run.
source.zip Source code including the sound file.

(c) Douwe Osinga 2001-2011, douwe.webfeedback@gmail.com Brazil travel guide for Android