[futurebasic] RE: What event do you check for on the close button?

Message: < previous - next > : Reply : Subscribe : Cleanse
Home   : January 2002 : Group Archive : Group : All Groups

From: Ken Shmidheiser <k.shmidheiser@...>
Date: Thu, 17 Jan 2002 02:05:42 -0500
John H. Guillory asked:

>I've seen various examples that show in the final loop you use eg.
>
>DO
>UNTIL FN BUTTON
>
>and this closes the application when you click the mouse in the middle of
>the program, but how do you have your program act like a standard Macintosh
>application, in other words, keep the window open until the user clicks on
>the small square in top left corner of the window?

John,

Nice to see you posting to the list.

The convention:

DO
HANDLEEVENTS
UNTIL FN BUTTON

Is a quick way to quick, dirty way to quit a program often used in 
prototyping and demos you see posted here for expediency.

In a real application, you would use the following:

' First build a function to create a window
' This one has:
'   ... a Quit button
'   ... and a few words of text printed in it
LOCAL FN buildWindow
WINDOW #1,   "Test Window",(   0,   0 )-( 400, 250),5
BUTTON  1, 2,"Quit",       ( 340, 220 )-( 390, 240),4
PRINT "Welcome John H. Guillory!"
END FN

' Next build a function to control
' dialog events in the window above.
' In this simple window, we have two
' controls...
LOCAL FN doDialog
DIM AS LONG evnt, id

' (This code tells our program which
' events and controls to watch)
evnt = DIALOG(0)
   id = DIALOG(evnt)

SELECT CASE( evnt )

' ... here is the Window close box you asked about...
CASE _wndClose
SELECT( id )
' Click the close box in WINDOW #1
' and tell the program to end
CASE 1 :  END
END SELECT

'... and the Quit button.
CASE _btnClick
SELECT( id )
' Click the Quit button (BUTTON 1)
' and tell the program to end
CASE 1 : END
END SELECT

END SELECT

END FN

'----Main Event Loop ----

' Turn on our FN doDialog function
' It will run the remainder of the program
' just waiting for us to click the Window
' close box our Quit button
ON DIALOG FN doDialog

' Turn on our Window which will remain
' open until we quit the program
FN buildWindow

' This tells our program to continue
' looping through each event until
' we quit it
DO
HANDLEEVENTS
UNTIL gFBQuit
END