From: Lyle Johnson Date: 2002-05-04T08:10:24+09:00 Subject: Re: [FXRuby] - How to capture close on the main window This is a multi-part message in MIME format. ------=_NextPart_000_0010_01C1F2CD.2C5D6420 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable When you click the "Close" button (the X in the upper right-hand corner) = on the main window, the main window will send SEL_CLOSE to its target. = So you need to catch that, something like: class MyWindow < FXMainWindow def initialize(app) super(app, "Steve's Window", nil, nil, DECOR_ALL, 0, 0, 200, = 200) # .. other stuff to fill up the window ... # This is important! # Associate the SEL_CLOSE message from the main window (i.e. = self) # with this handler method self.connect(SEL_CLOSE, method(:onClose)) end # Handles SEL_CLOSE from the main window def onClose(sender, sel, event) response =3D FXMessageBox.question(self, MBOX_YES_NO, "Close = Window", "Are you sure?") if response =3D=3D MBOX_CLICKED_YES return 0 else return 1 end end def create super show(PLACEMENT_SCREEN) end end This gives you a chance to do application cleanup before the application = bails out. A typical example would, say, check to see if the document = had been modified and if so, ask the "Are you sure?" question. If your = SEL_CLOSE handler returns zero then the application will go ahead and = exit. If your handler returns 1, however, the main window does not get = closed after all. Hope this helps, Lyle "Steve Tuckner" wrote in message = news:007b01c1f2ea$94a0cdc0$6904a8c0@multitech.prv... If my main window class is defined as follows class MyWindow < FXMainWindow def create super show(PLACEMENT_SCREEN) end end I tried defining=20 def onDestroy end and=20 def onCmdDestroy end and neither got called. Steve Tuckner =20 ------=_NextPart_000_0010_01C1F2CD.2C5D6420 Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable
When you click the "Close" button (the = X in the=20 upper right-hand corner) on the main window, the main window will send = SEL_CLOSE=20 to its target. So you need to catch that, something like:
 
    class MyWindow <=20 FXMainWindow
        = def=20 initialize(app)
       =20     super(app, "Steve's Window", nil, nil, DECOR_ALL, 0, = 0, 200,=20 200)
 
       =20     # .. other stuff to fill up the window = ....
 
       =20     # This is important!
       =20     # Associate the SEL_CLOSE message from the main = window (i.e.=20 self)
       =20     # with this handler method
       =20     self.connect(SEL_CLOSE, = method(:onClose))
       =20 end
 
        # = Handles=20 SEL_CLOSE from the main window
        = def=20 onClose(sender, sel, event)
          &nbs= p; response=20 =3D FXMessageBox.question(self, MBOX_YES_NO, "Close Window", "Are you=20 sure?")
           =20 if response =3D=3D MBOX_CLICKED_YES
    =    =20         return 0
   =20         else
   =20             return=20 1
           =20 end
        end
 
        = def=20 create
       =20     super
       =20     show(PLACEMENT_SCREEN)
       =20 end
    end
 
This gives you a chance to do = application cleanup=20 before the application bails out. A typical example would, say, check to = see if=20 the document had been modified and if so, ask the "Are you sure?" = question. If=20 your SEL_CLOSE handler returns zero then the application will go ahead = and exit.=20 If your handler returns 1, however, the main window does not get closed = after=20 all.
 
Hope this helps,
 
Lyle
 
"Steve Tuckner" <STUCKNER@MULTITECH.COM> = wrote in=20 message news:007b01c1f= 2ea$94a0cdc0$6904a8c0@multitech.prv...
If=20 my main window class is defined as follows
 
class MyWindow=20 < FXMainWindow
   =20 def create
       =20 super
       =20 show(PLACEMENT_SCREEN)
    end
end
I = tried defining=20
    def onDestroy
    end
 
and=20
    def onCmdDestroy
    end
 
and = neither got=20 called.
 
Steve=20 Tuckner
 
 
   
------=_NextPart_000_0010_01C1F2CD.2C5D6420--