implemented
This commit is contained in:
@@ -2,46 +2,61 @@
|
||||
|
||||
A small system tray API for Racket.
|
||||
|
||||
Version 0.1 implements Windows directly through the Win32 API. It uses the
|
||||
native `HWND` of an existing Racket `frame%`/`dialog%`, `Shell_NotifyIconW`, and
|
||||
`SetWindowSubclass`. No additional native DLL is required.
|
||||
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 frame
|
||||
(new frame%
|
||||
[label "Tray example"]
|
||||
[width 400]
|
||||
[height 250]))
|
||||
(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"
|
||||
(λ ()
|
||||
(send frame show #t))))
|
||||
show-frame
|
||||
#:hide-on-minimize? #t))
|
||||
|
||||
(tray-set-menu!
|
||||
tray
|
||||
(list
|
||||
(list "Open"
|
||||
(λ () (send frame show #t)))
|
||||
(list "Open" show-frame)
|
||||
'separator
|
||||
(list "Exit"
|
||||
(λ ()
|
||||
(tray-close tray)
|
||||
(send frame show #f)))))
|
||||
(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 the native
|
||||
files. PNG transparency is preserved when the image is converted to a native
|
||||
Windows tray icon.
|
||||
|
||||
`tray-set-menu!` also accepts a `popup-menu%` object directly, or `#f` to
|
||||
remove the context menu.
|
||||
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.
|
||||
|
||||
Reference in New Issue
Block a user