Refresh Basic Windows with ON DIALOG GOSUB or SetWindowPic (40083)
The information in this article applies to:
- Microsoft QuickBASIC Compiler for the Apple Macintosh 1.0
- Microsoft QuickBASIC Compiler for the Apple Macintosh 1.0a
- Microsoft QuickBASIC Compiler for the Apple Macintosh 1.0b
- Microsoft BASIC Interpreter for Apple Macintosh 3.0
- Microsoft BASIC Compiler
This article was previously published under Q40083 SUMMARY
Microsoft QuickBasic for Macintosh and the earlier Microsoft Basic
versions for Macintosh do not automatically refresh the contents of
the output window if covered by any other window. Therefore,
manipulating multiple windows in a program involves continually
updating the contents of various windows.
There are two alternatives that make your program refresh windows:
- When a window in a program needs to be refreshed, an event occurs
that can be trapped with the ON DIALOG GOSUB statement. Example 1
below demonstrates trapping the refresh event and then refreshing
the screen in the event-handling subroutine. When the current
output window needs to be refreshed, the DIALOG(0) function returns
a value of 5. Subsequently, the DIALOG(5) function returns the
number of the window that needs to be refreshed. You then can
execute any graphics statements to refresh the window any way you
desire.
- If your picture on a window will not be changing during the
program, you can invoke the SetWindowPic routine to automatically
handle refreshing, thus saving you from writing a window refresh
handler for that window. Example 2 below gives a demonstration of
using SetWindowPic to automatically refresh a window. An
advantage of SetWindowPic is that it refreshes any window, even
windows that are not the current output window.
This information applies to Microsoft QuickBasic versions 1.0, 1.0a,
and 1.0b for Apple Macintosh, to Microsoft Basic Compiler version 1.0
for Macintosh, and to Microsoft Basic Interpreter version 3.0 for
Macintosh.
MORE INFORMATION
A window may need to be refreshed after various events, such as the
following:
- An alert box, window, or desk accessory was opened and closed on
top of the window.
- A window that has just been activated and brought to the front
needs to be updated.
- Another window was moved onto and then off of the window.
- You sized the window larger in either the X or Y dimension, or you
zoomed the window larger by clicking the zoom box. (The currently
active output window does not need refreshing when zoomed smaller,
and no refresh event occurs for it when zooming smaller.)
- The window was moved partially off the screen, and then back on.
SetWindowPic is a very useful routine that lets you assign a static,
unchanging picture to be refreshed automatically whenever necessary.
SetWindowPic saves you from writing a window-refresh handler. In the
QuickBasic environment, SetWindowPic refreshes the output window if
overlaid by the List window, even when the program is stopped.
However, SetWindowPic is not suitable for refreshing a picture that
will change as the program progresses because it only refreshes an
unchanging, static picture.
SetWindowPic is an MBLC routine built into QuickBasic. SetWindowPic is
a LIBRARY routine in the "ToolLib" file in the earlier Microsoft Basic
Compiler version 1.0 and Microsoft Basic Interpreter version 3.0 for
Macintosh.
Example 1: Refreshing with ON DIALOG GOSUB, Handling Event 5
Example 1 below is a sample QuickBasic program that demonstrates using
the DIALOG function to maintain the appearance of two output windows.
The program allows you to move the windows over the top of each other,
and so on, to cause refresh requests and see how the Basic program
reacts to them.
Note: A window generates a refresh event when it is initially opened.
ON DIALOG GOSUB DoDialog
DIALOG ON
WINDOW 1, "1", (1,40)-(220,180), 1
WINDOW 2, "2", (222,40)-(440,180), 1
f$=FILES$(1) ' Invokes file dialog box which overlays windows
WHILE INKEY$="":WEND ' Press any key to end program.
END
' The following is the event-handler subroutine:
DoDialog:
event%=DIALOG(0) ' Don't invoke DIALOG(0) more than once in handler
' or else the event sequence will be confused.
SELECT CASE event%
CASE 3 ' If DIALOG(0) returned 3, a new window was clicked.
WINDOW DIALOG(3) ' Activate the clicked window.
CASE 5 ' If DIALOG(0) returned 5, a window needs refreshing.
w=DIALOG(5) ' Returns the number of window needing refreshing
WINDOW OUTPUT w ' Makes window w the current output window.
' Alternative idea here: IF condition THEN refresh differently.
CLS
PRINT "Refresh"; w
FOR t=4 TO 100 STEP 2
LINE (4,15)-(t*2, t+15),,b
NEXT t
CASE ELSE
END SELECT
RETURN
Note: SELECT CASE (used above) is supported in QuickBasic (interpreter
and compiler) and in the earlier Microsoft Basic Compiler 1.0, but is
not supported in the earlier Microsoft Basic Interpreter version 2.0,
2.1, or 3.0 for the Macintosh. You can always replace a SELECT CASE
statement with multiple IF...THEN statements.
Example 2: Refreshing with SetWindowPic
' Example using SetWindowPic for auto-refreshing of static picture.
' This program works in Microsoft QuickBasic version 1.0, Basic
' compiler version 1.0, and Basic interpreter version 3.0.
' (Interpreter versions 2.0 and 2.1 do not support this program.)
' LIBRARY "TOOLLIB" ' Add this statement only for Basic compiler 1.0
' or Basic interpreter 3.0, not for QuickBasic.
ON DIALOG GOSUB handle
DIALOG ON
DIM a%(3) ' Array of coordinates of the static picture's frame.
SetArray a%(0),1,1,110,245 ' Initialize coordinates of picture frame.
pic&=0 ' Handle to the static picture in heap space.
w&=0 ' Pointer to the window (2) which will contain static picture
WINDOW 1,"Overlaying window",(1,40)-(300,200)
WINDOW 2,"Auto-refresh Window",(20,60)-(320,220),5
GetWindow w& ' Get pointer to currently active window (window 2).
OpenPicture a%(0),pic& ' Subsequent graphics will define picture:
SHOWPEN ' Lets you see the picture as it is drawn.
TEXTFONT 4 : TEXTSIZE 9
FOR J=1 TO 9
FOR K=1 TO 4
DrawText "1234567890" ' DrawText is much faster than PRINT.
NEXT
PRINT ' DrawText doesn't give carriage returns, so do a PRINT.
NEXT
DrawText "You can overlay window, and picture" : PRINT
DrawText "will auto-refresh. Press any key to end."
LINE (1,1)-(245,110)
ClosePicture ' End of picture definition.
SetWindowPic w&,pic&; ' Sets up picture pic& to be auto-refreshed.
WHILE INKEY$="" : WEND ' Wait for key press.
SetWindowPic w&,0& ' Turn off auto-refreshing.
DisposePicture pic& ' Remove the picture from memory (heap).
END
' Below is an event handler subroutine to activate clicked window:
Handle:
Event=DIALOG(0)
IF Event=3 THEN WINDOW DIALOG(3) ' Activates clicked window.
RETURN
Modification Type: | Minor | Last Reviewed: | 8/16/2005 |
---|
Keywords: | KB40083 |
---|
|