On a second look, I noticed this still allowed the upper-right X button to close the form with no consequence...

So change this function...
 Code:
Function RegainFocus()
   $Form1.WindowState = 1
   $Form1.WindowState = 0
EndFunction
To this...
 Code:
Function RegainFocus()
   If $Form1.Visible
      $Form1.WindowState = 1
      $Form1.WindowState = 0
   Else
      ExitingApp()
   Endif
EndFunction