Chaos Project

Game Development => Sea of Code => Topic started by: G_G on October 30, 2009, 05:49:55 pm

Title: Stopping Program from Closing?
Post by: G_G on October 30, 2009, 05:49:55 pm
Well you know how in notepad or paint or whatever program you go to close it and it asks if you want to save first right?

Well if you click yes, it saves, no it just closes, and cancel which cancels the close. How would I do this?
Title: Re: Stopping Program from Closing?
Post by: fugibo on October 30, 2009, 06:26:00 pm
I'm guessing you'd use C's signal(<SIGNAL>, <HANDLER>) function, but I could be wrong.

EDIT:
Looks like I was: Linky (http://www.geekpedia.com/KB9_How-do-I-stop-the-form-from-closing-or-How-do-I-prompt-the-user-to-confirm-the-closing-of-the-application-when-he-presses-the-X-button.html)
Title: Re: Stopping Program from Closing?
Post by: Ryex on October 30, 2009, 06:31:41 pm
this is the code I used to stop the RMX-OS GUI from closing and untill it kew if you wanted to run in the task bar


 this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.rmxos_closing);



private void rmxos_closing(object sender, FormClosingEventArgs e)
       {
           if (runingintaskbar == false)
           {
               DialogResult result = MessageBox.Show("Do you want to keep running in the task bar?", "Closing", MessageBoxButtons.YesNo);
               if (result == DialogResult.Yes)
               {
                   e.Cancel = true;
                   minimize_to_tray();
                   
               }
               else
               {
                   if (cfg_saved == false)
                   {
                       DialogResult result2 = MessageBox.Show("The configuration data has not been saved \r\n would you like to save now?", "CFG Not Saved!", MessageBoxButtons.YesNo);
                       if (result2 == DialogResult.Yes)
                       {
                           save_data();
                       }
                   }
                   if (serverRunState == true)
                   {
                       RmxosProcess.Kill();
                   }
               }
           }
           else
           {
               if (cfg_saved == false)
               {
                   DialogResult result2 = MessageBox.Show("The configuration data has not been saved \r\n would you like to save now?", "CFG Not Saved!", MessageBoxButtons.YesNo);
                   if (result2 == DialogResult.Yes)
                   {
                       save_data();
                   }
               }
               if (serverRunState == true)
               {
                   RmxosProcess.Kill();
               }
           }
           
           
       }


"this" being the Form insistence
Title: Re: Stopping Program from Closing?
Post by: Blizzard on October 30, 2009, 06:33:09 pm
There's an event called FormClosing. Just define a method that is called at that moment and abort it. I can't remember how exactly I did it, but if you still have the Blizz-ABS Config source, I did it in there to make the saving before closing dialog possible.

Ryex beat me to it. >8U

@LF: That's for C in Unix. He's using C# in Windows. -_-
Title: Re: Stopping Program from Closing?
Post by: fugibo on October 30, 2009, 06:35:35 pm
Quote from: Blizzard on October 30, 2009, 06:33:09 pm
There's an event called FormClosing. Just define a method that is called at that moment and abort it. I can't remember how exactly I did it, but if you still have the Blizz-ABS Config source, I did it in there to make the saving before closing dialog possible.

Ryex beat me to it. >8U

@LF: That's for C in Unix. He's using C# in Windows. -_-


Holy crap, Windows doesn't support signal()?
Holy crap, C# doesn't support C functions?
Title: Re: Stopping Program from Closing?
Post by: Blizzard on October 30, 2009, 06:47:23 pm
Windows doesn't have signals. Interrupts are handled in a different way.
Title: Re: Stopping Program from Closing?
Post by: G_G on October 31, 2009, 06:55:10 pm
Thanks guys! Got it working *lv's up ryex*