[racket] Trying to build first GUI executable and the application icon file

From: Jeff C. Britton (jcb at iteris.com)
Date: Fri Nov 18 14:06:39 EST 2011

Thanks Mr. Flatt.  Excellent response and work.

-----Original Message-----
From: Matthew Flatt [mailto:mflatt at cs.utah.edu] 
Sent: Wednesday, November 16, 2011 1:59 PM
To: Jeff C. Britton
Cc: 'users at racket-lang.org'
Subject: Re: [racket] Trying to build first GUI executable and the application icon file

At Wed, 16 Nov 2011 03:18:01 +0000, "Jeff C. Britton" wrote:
> I am on Windows XP.
> I am having trouble with the main window icon and the application icon.
> The following embeds camera.ico into my executable as the application icon.
> raco exe --gui --ico camera.ico gui1.rkt
> On my main window frame I wish to set the icon to this embedded camera.ico.

There's currently not an easy way to extract the application icon.

For the next version, I've made that the default (i.e., frames get the
application's icon by default). Also, I've added a `file/ico' library
for working with ".ico" files and extracting icons from an executable
(since the code existed internal to `raco exe').

> I can set the main window frame icon with this.
> (send frame set-icon icon)
> But there are a couple of problems.  
> icon must be a bitmap and read-bitmap does not read .ico files.
> I don't know how to read a file(resource) from the executable.
> I don't know how to embed a .png file into the executable as a resource and 
> then read this from the application.

If you have the image you want as "camera.png", then in a module whose
source is the same directory as "camera.png", you can use

 (require racket/runtime-path)
 (define-runtime-path camera-png "camera.png")
 (define bm (read-bitmap camera-png))

The `define-runtime-path' form arranges for `raco exe' to carry along
the "camera.png" file and for `camera-png' to be a suitable path at run
time --- whether running from source, from bytecode, or through an
embedding executable.

Posted on the users mailing list.