Files
racket-tray/README.md
T
2026-08-29 01:09:49 +02:00

63 lines
1.6 KiB
Markdown

# racket-tray
A small system tray API for Racket.
Version 0.1.1 implements Windows directly through the Win32 API. It uses the
native `HWND` of an existing Racket `frame%` or `dialog%`, `Shell_NotifyIconW`,
and `SetWindowSubclass`. No additional native DLL is required.
```racket
#lang racket/gui
(require racket-tray)
(define tray-frame%
(class frame%
(super-new [label "Tray example"]
[width 400]
[height 250])
;; Close [X] to the tray instead of destroying the frame.
(define/override (on-close)
(send this show #f))))
(define frame (new tray-frame%))
(define (show-frame)
(send frame show #t)
(when (send frame is-iconized?)
(send frame iconize #f)))
(define tray
(mk-tray frame
"example.png"
show-frame
#:hide-on-minimize? #t))
(tray-set-menu!
tray
(list
(list "Open" show-frame)
'separator
(list "Exit"
(λ ()
(tray-close tray)
(exit)))))
(send frame show #t)
```
`mk-tray` and `tray-set-icon!` accept both Windows `.ico` files and `.png`
files. PNG transparency is preserved when the image is converted to a native
Windows tray icon.
With `#:hide-on-minimize? #t`, minimizing the associated window hides it from
the taskbar while keeping its native window handle alive. Closing a window to
the tray does not need a separate tray API: override `frame%`'s `on-close` and
call `(send this show #f)`.
`tray-set-menu!` accepts a `popup-menu%` object directly, a simple menu list,
or `#f` to remove the context menu.
At the moment non-Windows platforms report that the operation is unsupported.