# FXRuby question

**URL:** <https://rubytalk.org/t/fxruby-question/3353>\
**Category:** ruby-talk\
**Created:** [5 December 2002 23:50 UTC](https://rubytalk.org/t/fxruby-question/3353 "2002-12-05T23:50:22Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Rich\_Kilmer](https://avatars.discourse-cdn.com/v4/letter/r/85f322/32.png) [@Rich\_Kilmer](https://rubytalk.org/u/Rich_Kilmer)\
**Post date:** [5 December 2002 23:50 UTC](https://rubytalk.org/t/fxruby-question/3353/1 "2002-12-05T23:50:22Z")

</div>

Does anyone know how to capture the event generated when one clicks on  
the X button in the uppper right corner? I want to perform some  
verifications and cleanup prior to closing.

Thanks,

Rich

> **···**
>
> * * *
> 
> Rich Kilmer, InfoEther LLC  
> trap(“SIGINT”) { raise [104, 101, 108, 108].pack(“cccc”) }

---

<div class="post-metadata">

**Author:** ![Lyle\_Johnson6](https://avatars.discourse-cdn.com/v4/letter/l/bb73d2/32.png) [@Lyle\_Johnson6](https://rubytalk.org/u/Lyle_Johnson6)\
**Post date:** [6 December 2002 00:16 UTC](https://rubytalk.org/t/fxruby-question/3353/2 "2002-12-06T00:16:37Z")

</div>

Rich Kilmer wrote:

> Does anyone know how to capture the event generated when one clicks on  
> the X button in the upper right corner? I want to perform some  
> verifications and cleanup prior to closing.

When you click the kill button on the main window, it (the FXMainWindow  
object) first sends a SEL\_CLOSE message to its message target, if any.  
If that target handles the message then life goes on (i.e. the  
application doesn’t shut down). If the main window doesn’t have a  
message target, or if it does but the target doesn’t handle the  
SEL\_CLOSE message, then the main window sends a SEL\_COMMAND message  
(with identifier FXApp::ID\_QUIT) to the application (FXApp) object. And  
that more or less terminates the main FOX event loop.

So for what you’re describing, I think I’d try something like this:

```
 theMainWindow.connect(SEL_CLOSE) do
   # Do fun things
   verify_things
   clean_up_things

   if ok_to_quit?

     # All is well to shut down, so go ahead
     # and send the ID_QUIT message to the
     # application.

     theMainWindow.app.handle(theMainWindow,
       MKUINT(FXApp::ID_QUIT, SEL_COMMAND), nil)
   else

     # We've decided not to shut down after all

   end
 end

```

Hope this helps,

Lyle

---

<div class="post-metadata">

**Author:** ![Rich\_Kilmer](https://avatars.discourse-cdn.com/v4/letter/r/85f322/32.png) [@Rich\_Kilmer](https://rubytalk.org/u/Rich_Kilmer)\
**Post date:** [6 December 2002 03:23 UTC](https://rubytalk.org/t/fxruby-question/3353/3 "2002-12-06T03:23:11Z")

</div>

That solved my problem perfectly. The FreeRIDE project thanks you 😉

-rich

> **···**
>
> > -----Original Message-----  
> > From: Lyle Johnson [[mailto:lyle@users.sourceforge.net](mailto:lyle@users.sourceforge.net)]  
> > Sent: Thursday, December 05, 2002 7:17 PM  
> > To: ruby-talk ML  
> > Subject: Re: FXRuby question
> > 
> > Rich Kilmer wrote:
> > 
> > > Does anyone know how to capture the event generated when  
> > > one clicks on  
> > > the X button in the upper right corner? I want to perform some  
> > > verifications and cleanup prior to closing.
> > 
> > When you click the kill button on the main window, it (the  
> > FXMainWindow  
> > object) first sends a SEL\_CLOSE message to its message  
> > target, if any.  
> > If that target handles the message then life goes on (i.e. the  
> > application doesn’t shut down). If the main window doesn’t have a  
> > message target, or if it does but the target doesn’t handle the  
> > SEL\_CLOSE message, then the main window sends a SEL\_COMMAND message  
> > (with identifier FXApp::ID\_QUIT) to the application (FXApp)  
> > object. And  
> > that more or less terminates the main FOX event loop.
> > 
> > So for what you’re describing, I think I’d try something like this:
> > 
> > ```
> > theMainWindow.connect(SEL_CLOSE) do
> > # Do fun things
> > verify_things
> > clean_up_things
> > 
> > if ok_to_quit?
> > 
> > # All is well to shut down, so go ahead
> > # and send the ID_QUIT message to the
> > # application.
> > 
> > theMainWindow.app.handle(theMainWindow,
> > MKUINT(FXApp::ID_QUIT, SEL_COMMAND), nil)
> > else
> > 
> > # We've decided not to shut down after all
> > 
> > end
> > end
> > 
> > ```
> > 
> > Hope this helps,
> > 
> > Lyle
