[comp.sys.mac.programmer] Help figuring screen size in a DA!

jbritt@shumv1.ncsu.edu (Joe Britt) (02/16/90)

I tried posting a message like this one yesterday, but never saw it
appear in the newsgroup...forgive me if this is redundant!

I am writing my first DA and need to figure out the size of the screen.
I realize that DA's don't have an A5 World, and so also don't have a set
of QD globals with goodies like screenBits.  What I'm looking for is
help on a good way to go about figuring out the screen size.  From the
stuff I've read, it looks like I have 2 possibilities:

	1. an assembly language glue routine to save a5, load a5 with
	   the value in CurrentA5, grab screenBits.bounds from below a5,
	   then reset a5 to the old saved value.

	2. Allocate 206 bytes, then call InitGraf with it pointing to
	   to the 203rd so as to create a fake set of QD globals, then 
	   pull screenBits out of them.

Is either of these methods "better"?  I'm writing the DA in LS Pascal,
but am not using the LS stuff that lets you keep globals off a4.  I'm
keeping a block in the host app heap.  I tried to do the first method
mentioned above via a routine I wrote in LSC (inline asm), but it didn't
work.  I must be hosing something up.  When I tried the InitGraf
approach, LSP complained that I was calling InitGraf without @thePort.

Any help would be greatlt appreciated!!
Thanks in advance!

-joe :-)

jbritt @shumv1.ncsu.edu

kingman@tci.bell-atl.com (Matt Kingman) (02/17/90)

jbritt@shumv1.ncsu.edu (Joe Britt) writes:

>I am writing my first DA and need to figure out the size of the screen.
>I realize that DA's don't have an A5 World, and so also don't have a set
>of QD globals with goodies like screenBits.  What I'm looking for is
>help on a good way to go about figuring out the screen size.

One quick and dirty way is to open a GrafPort and look at the portRect.
This is a method I used in a couple of cdevs I wrote to center dialog
boxes on the screen.  Here's an excerpt...

----
Rect screenBounds;
GrafPort gp;

	/*
	** Get the size of the screen by opening a phony port
	** because we can't access screenBits.bounds.
	*/
	OpenPort(&gp);
	screenBounds = gp.portRect;
	ClosePort(&gp);
----

/Matt
-- 
Matt Kingman - Systems Engineer		kingman@tci.bell-atl.com
Technology Concepts Inc.		...!uunet!tci!kingman
Sudbury, MA. 01776			(508)443-7311
  TCI is not responsible for my opinions, nor I for theirs...

lefty@twg.com (David N. Schlesinger) (02/21/90)

In article <1990Feb15.164818.24121@ncsuvx.ncsu.edu> jbritt@shumv1.ncsu.edu 
(Joe Britt) writes:
> I am writing my first DA and need to figure out the size of the screen.
> I realize that DA's don't have an A5 World, and so also don't have a set
> of QD globals with goodies like screenBits.  What I'm looking for is
> help on a good way to go about figuring out the screen size.

What I'd do is use the GrafPort pointed to by the low-memory global 
WMgrPort (at location 0x9DE).  Something like the following:

#define   WMgrPort    (*((GrafPort *) 0x9DE))

wmPort = WMgrPort;
BlockMove(wmPort->portRect, myBounds, sizeof(Rect));

This probably won't work on multiple-screen systems, but it's worked for 
me in the past.  Specifically, I've used it for centering dialog windows 
from Control Panel devices...

Hope this helps...

Lefty

===========================================================================
          David N. Schlesinger   || "There's a word for it: words don't
          The Wollongong Group   ||  mean a thing.  There's a name for it;
Internet: Lefty@twg.com          ||  names make all the difference in the
POTS:     415/962-7219           ||  world..." -- David Byrne
===========================================================================

lefty@twg.com (David N. Schlesinger) (02/21/90)

In article <168@gollum.twg.com> I wrote:
> What I'd do is use the GrafPort pointed to by the low-memory global 
> WMgrPort (at location 0x9DE).

As Tom Dowdy of Apple (dowdy@apple.COM) has pointed out to me, there's a 
perfectly good ROM call, GetWMgrPort(), which will return a pointer to the 
Window Manager's GrafPort.  As Tom says, "Using low memory when there is a 
ROM call available is a really bad idea."

I agree.

Mea culpa, mea maxima culpa...

Lefty

===========================================================================
          David N. Schlesinger   || "There's a word for it: words don't
          The Wollongong Group   ||  mean a thing.  There's a name for it;
Internet: Lefty@twg.com          ||  names make all the difference in the
POTS:     415/962-7219           ||  world..." -- David Byrne
===========================================================================