74 lines
2.1 KiB
Racket
74 lines
2.1 KiB
Racket
#lang racket/gui
|
|
|
|
;(require racket-tray)
|
|
(require "../main.rkt")
|
|
|
|
;; This example demonstrates the two common "close to tray" behaviours:
|
|
;;
|
|
;; * minimize: handled by racket-tray through #:hide-on-minimize?
|
|
;; * close [X]: handled by frame%'s normal on-close callback
|
|
;;
|
|
;; The frame remains alive in both cases because the tray icon uses its HWND.
|
|
(define simple%
|
|
(class frame%
|
|
(super-new [label "Racket Tray"]
|
|
[width 400]
|
|
[height 250])
|
|
|
|
(define lbl
|
|
(new message%
|
|
[label "Counting tray clicks"]
|
|
[parent this]
|
|
[auto-resize #t]
|
|
[stretchable-width #t]))
|
|
|
|
(define count 0)
|
|
|
|
(define/public (count-next)
|
|
(set! count (add1 count))
|
|
(send lbl set-label
|
|
(format "Counting tray clicks: ~a" count)))
|
|
|
|
;; Clicking the window's close button hides the frame instead of
|
|
;; destroying it. The tray menu's Exit item terminates the application.
|
|
(define/override (on-close)
|
|
(send this show #f))))
|
|
|
|
(define frame (new simple%))
|
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
; goal : Show and restore the example frame from the tray.
|
|
; pre : frame has been created and has not been destroyed.
|
|
; post : frame is visible and no longer iconized.
|
|
; result : Unspecified.
|
|
; internals:
|
|
; A frame hidden in response to SIZE_MINIMIZED can still retain its
|
|
; iconized state, so show #t is followed by iconize #f when needed.
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
(define (show-frame)
|
|
;; A frame hidden after a minimize can still be iconized. Make sure it is
|
|
;; restored when it is opened from the tray.
|
|
(send frame show #t)
|
|
(when (send frame is-iconized?)
|
|
(send frame iconize #f)))
|
|
|
|
(define tray
|
|
(mk-tray frame
|
|
"simple.png"
|
|
(λ ()
|
|
(send frame count-next)
|
|
(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)
|