Path: utzoo!utgpu!news-server.csri.toronto.edu!mailrus!cs.utexas.edu!usc!snorkelwacker!apple!well!wdh From: wdh@well.sf.ca.us (Bill Hofmann) Newsgroups: comp.sys.mac.programmer Subject: Re: How do you find a window's location? Summary: GlobalToLocal the topLeft of the portRect Keywords: window Message-ID: <18229@well.sf.ca.us> Date: 30 May 90 17:31:55 GMT References: <3258@usceast.UUCP> <22352@dartvax.Dartmouth.EDU> Reply-To: wdh@well.sf.ca.us (Bill Hofmann) Distribution: na Organization: Whole Earth 'Lectronic Link, Sausalito, CA Lines: 31 In article <22352@dartvax.Dartmouth.EDU> mjm@eleazar.dartmouth.edu (Michael McClennen) writes: >jwwalker@usceast.UUCP (Jim Walker) writes: >>I know how to set a window's location with MoveWindow and >>SizeWindow, but how do you *find* a window's location? If the >>window is visible, I can use >> (**((WindowPeek)window_ptr)->contRgn).rgnBBox >>but that seems to contain garbage when the window is invisible. >>Yet the Window Manager somehow keeps track of the locations of >>invisible windows. >How about checking the grafPort's portRect? The portRect of a grafPort is the top,left,bottom,right of the window in LOCAL coordinates, that is, the coordinate system of the window. (Note that the top,left need not be 0,0). What you want is the position of the top,left in GLOBAL coordinates. So, looking at Inside Mac Vol I-193: Point getWindowLocation(WindowPtr wp) { Point where; GrafPtr curPort; where.v = wp->portRect.top; where.h = wp->portRect.left; GetPort(&curPort); SetPort(wp); GlobalToLocal(&where); SetPort(curPort); return(where); } If you want to include the title bar, which is above and to the left of the content, you'll have to look at the strucRgn of the window. -Bill Hofmann