Path: utzoo!utgpu!water!watmath!clyde!att!osu-cis!tut.cis.ohio-state.edu!husc6!huma1!fry From: fry@huma1.HARVARD.EDU (David Fry) Newsgroups: comp.sys.mac.programmer Subject: Re: Centering alerts vs. centering dialogs Message-ID: <4800@husc6.harvard.edu> Date: 21 Jun 88 01:34:13 GMT References: Sender: news@husc6.harvard.edu Reply-To: fry@huma1.UUCP (David Fry) Organization: Harvard Math Department Lines: 66 In article lipa@POLYA.STANFORD.EDU (William Lipa) writes: >As far as I can tell, centering alerts is much harder than centering dialogs. >Try it sometime, you'll like it! Centering alerts is very simple. You simply read in the Handle of the ALRT resource, center it and immediately call Alert(). Here's an example in C. A similar technique can be used to center StdFile dialogs. /* The variables ScreenHeight and ScreenWidth are calculated at runtime and mean what you think they mean. They should take into account variable menuBar heights and multiple screens on Mac IIs. */ CenterAlert(ID) short ID; { AlertTHndl aboutALRT; aboutALRT = GetResource('ALRT',ID); CenterRBox(aboutALRT); Alert(ID, 0L); ReleaseResource(aboutALRT); } CenterRBox(boxHandle) Handle boxHandle; { /* given a Handle to a block (usually a resource) whose first 8 bytes represent a box on the screen, this function changes that rectangle to be positioned nicely on the screen */ int w,h; Rect temp; temp = *(Rect *)*boxHandle; h = temp.bottom - temp.top; CenterRect(&temp); temp.top = menuH + (ScreenHeight - h)/3; temp.bottom = temp.top + h; *(Rect *)*boxHandle = temp; } CenterRect(r) Rect *r; { /* "centers" a rectangle on the screen */ int w,h; w = r->right - r->left; h = r->bottom - r->top; r->left = (ScreenWidth - w)/2; r->right = r->left + w; r->top = (ScreenHeight - h - menuH)/2 + menuH; r->bottom = r->top + h; } David Fry fry@huma1.harvard.EDU Department of Mathematics fry@huma1.bitnet Harvard University ...!harvard!huma1!fry Cambridge, MA 02138