[plt-scheme] Proper way to close windows

From: Matthew Flatt (mflatt at cs.utah.edu)
Date: Thu Oct 6 12:40:28 EDT 2005

At Thu, 6 Oct 2005 12:05:57 -0400 (GMT-04:00), Dale Hurtt wrote:
> I have noticed that if I simply click the Close icon on a frame% instance 
> (which is an mdi-child), I lose the ability to use the Alt key to select 
> menus. 

I haven't been able to reproduce this behavior in 299.X. My test
program is below; both the parent and child have menu bars, but I also
tried with just a parent menu bar.

Does closing the child window in this test program prevent Alt from
working right on your machine?

> Looking through the documentation, it seems like clicking the Close 
> icon only turns the window's visibility to #f. Is that correct?

It also makes the frame available for GC, if the frame is not otherwise
reachable. There's no way to close the frame more finally, except to
shut down the frame's eventspace's custodian --- which you wouldn't
want to do, because that's also the mid-parent frame's custodian.

> Also, if I want to react to an event, is it more like JavaScript or
> like Java?
> In JavaScript, I would simply add a function to the event property, like so:
> [...]
> Whereas with Java, I would need to sub-class the window and override the 
> appropriate methods:

It's more like Java, except that a few specific callbacks (such as the
paint callback for a canvas%) can be supplied when constructing an



(define f (new frame%
               [label "Parent"]
               [width 200][height 200]
               [style '(mdi-parent)]))

(define (make-mb f name)
  (define mb (new menu-bar%
                  [parent f]))
  (define m (new menu%
                 [parent mb]
                 [label name]))
  (new menu-item%
       [parent m]
       [label "Hello"]
       [callback void]))

(make-mb f "Parent")

(define c (new frame%
               [parent f]
               [label "Child"]
               [x 10][y 10][width 100][height 100]
               [style '(mdi-child)]))

(make-mb c "Child")

(send c show #t)

(send f show #t)

Posted on the users mailing list.