[comp.sys.mac.programmer] Forcing a screen update.

lshupe@milton.u.washington.edu (Larry Shupe) (09/04/90)

How does one force a mac to redraw the entire desktop (under Multifinder)?
Screen savers and Stuffit Deluxe do this, but I can't figure it out.

Eternal gratefulness,

Larry Shupe
lshupe@milton.u.washington.edu

lemke@radius.com (Steve Lemke) (09/04/90)

lshupe@milton.u.washington.edu (Larry Shupe) writes:

>How does one force a mac to redraw the entire desktop (under Multifinder)?
>Screen savers and Stuffit Deluxe do this, but I can't figure it out.

How about this little gem?  I use this to invalidate the screen, and since
"bigRect" is soooo big, it should basically invalidate the entire desktop.
Now that I look at it, I'm not sure why the GetPort and SetPort are there
since I didn't change the port anywhere, but I'm too lazy to take it out
and see if it still works...  Have fun.

 procedure InvalScreen; { invalides the whole screen }
  var
   oldPort: GrafPtr;
   bigRgn: RgnHandle;
   bigRect: Rect;
 begin
  GetPort(oldPort);
  bigRgn := NewRgn;
  SetRect(bigRect, -32000, -32000, 32000, 32000);
  RectRgn(bigRgn, bigRect);
  PaintBehind(WindowPeek(FrontWindow), bigRgn);
  DisposeRgn(bigRgn);
  SetPort(oldPort);
 end;

>Eternal gratefulness,

No problem - in fact, I didn't write the above - it was borrowed/translated
from assembly language that somebody else wrote.

>Larry Shupe
>lshupe@milton.u.washington.edu

--Steve
-- 
----- Steve Lemke, Engineering Quality Assurance, Radius Inc., San Jose -----
----- Reply to: lemke@radius.com     (Note: NEW domain-style address!!) -----

ccc_ldo@waikato.ac.nz (Lawrence D'Oliveiro, Waikato University) (09/04/90)

Here's an FKEY I wrote in my pre-MPW days (it's in MDS Assembler),
which forces a redraw of the screen, apart from the menu bar.
If you want to update that as well, just add a call to _DrawMenuBar
somewhere.

;+
; This simple FKEY forces the desktop and all windows to
; be redrawn. It is useful after running non-MultiFinder-
; friendly programs which write directly to the screen.
;
; Written by Lawrence D'Oliveiro 1988 August 6.
; Modified 1988 October 17 to save and restore current grafPort
; (zapped by PaintOne, which is called by PaintBehind)
;-
	include	ToolEquX.D
	include	Traps.D

	Resource 'FKEY' 9 'Refresh screen' 32

	clr.l	-(sp)		; space to save current port
	pea	(sp)		; pointer to space
	_GetPort
	clr.l	-(sp)
	_FrontWindow
	move.l	GrayRgn, -(sp)
	_PaintBehind
	_SetPort
	rts

	end

Lawrence D'Oliveiro                       fone: +64-71-562-889
Computer Services Dept                     fax: +64-71-384-066
University of Waikato            electric mail: ldo@waikato.ac.nz
Hamilton, New Zealand    37^ 47' 26" S, 175^ 19' 7" E, GMT+12:00
"Look! We're being attacked by hostile pipe-welders!"
				 -- John Candy in "It Came From Hollywood"

d88-jwa@dront.nada.kth.se (Jon W{tte) (09/05/90)

In article <1320@radius.com> lemke@radius.com (Steve Lemke) writes:

>>How does one force a mac to redraw the entire desktop (under Multifinder)?
>>Screen savers and Stuffit Deluxe do this, but I can't figure it out.

>How about this little gem?  I use this to invalidate the screen, and since
>"bigRect" is soooo big, it should basically invalidate the entire desktop.

You could, of course, use the Apple supplied routines to
get the desktop size with better compatibility...

> procedure InvalScreen; { invalides the whole screen }

void
RedrawScreen(void)
{
	PaintBehind((WindowPeek) FrontWindow(), GetGrayRgn());
}

Maybe you should clone the GetGrayRgn region and then dispose
of the clone when you're done with it. I haven't seen that
PaintBehind _should_ change the region passed to it, but who
knows ?

							h+
	Jon W{tte, Stockholm, Sweden, h+@nada.kth.se