Staz Software
HomeFutureBasicSharewareOrderContact

FAQs

Why is my window erased as soon as I draw into it? [OS 9]

You should never draw into a window until you have received an update event. Here’s an explanation of how the Mac handles updates and why you should react at the proper time:

When a window is built or brought forward, most often all or part of its content must be refreshed. The window manager collects these clobbered areas in a structure called an update region (sometimes called the clobbered region). You can force pieces of a window to be added to this region by calling FN INVALRECT, and force pieces to be subtracted from the region by calling CALL VALIDRECT.

When nothing else is going on in MacDom, the Window Manager looks around to see what needs to be fixed and sees that it has an update region for your window. It builds a fake event (_updatEvt) and sends it through the event queue.

FutureBASIC sees the update event and calls BEGINUPDATE. This swaps the visible region with the clobbered region. FB then erases the clobbered area, redraws all controls and fields, then calls your program to do its drawing via the _updatEvt. When your program receives the _updatEvt event, you are expected to draw the windows contents. When everything is finished, FB calls ENDUPDATE to reset all regions back to normal.

Remember: anytime a window is built, the Window Manager automatically sends you an update event - without fail. You can count on it.

If you draw into a window when it is first built or when some button is clicked or a menu item is selected, rather than in response to an update event, the update sequence will erase your work; and after the update you'll be looking at a blank window.

Always do your drawing in response to update events.

// build file menu

MENU 1,0,1,"File"
MENU 1,1,1,"Quit/Q"

// set up constants for windows

_circleWnd = 1
_squareWnd = 2

// dialog handler -- this is where update events are handled

LOCAL FN doDialog
 DIM act,ref
 DIM myRect AS RECT
 act = DIALOG(0)
 ref = DIALOG(act)
 LONG IF act = _wndRefresh 
  CALL SETRECT(myRect,0,0,WINDOW(_width),WINDOW(_height))
  CALL INSETRECT(myRect,32,32)
  SELECT ref 
   CASE _circleWnd
   CALL FRAMEOVAL(myRect)
   CASE _squareWnd
   CALL FRAMERECT(myRect)
  END SELECT
 END IF
END FN

// build two windows

WINDOW _circleWnd
WINDOW _squareWnd

// set up dialog vector

ON DIALOG FN doDialog

// loop until user quits

DO
 HANDLEEVENTS
UNTIL 0

FutureBASIC

Demo

Order

Tour

Tech Notes

FAQ

Sample Code

Web Sites

Mailing List

System
Requirements

blank