john@basho.uucp (John Lacey) (06/04/91)
I am trying to write code to splash a window on the screen when the application is launched, as ResEdit 2.x does, and as many other applications do with their About boxes. (As with ResEdit, my startup and about boxes are the same.) I am having all kinds of trouble. I changed from GetNextEvent to GetOSEvent, to get around activate events under MultiFinder. I tried using the windowPic field of the window record, and I can't get that to work. So, I get an update event I don't want, or know how to deal with for that matter. Is there some simple method for doing this that I am missing? I would appreciate any hints. -- John Lacey, Schemer, TeXnician, and MacHacker "It's hard to tell you how I feel without hurting you." --Soho
smoke@well.sf.ca.us (Nicholas Jackiw) (06/05/91)
In article <1991Jun3.182417.2897@basho.uucp> john@basho.uucp (John Lacey) writes: >Is there some simple method for doing this that I am missing? I would >appreciate any hints. > >-- >John Lacey, Schemer, TeXnician, and MacHacker >"It's hard to tell you how I feel without hurting you." --Soho This seems to work for me. OrientWindow() is a procedure which centers a (hidden) window on the main screen, or on the monitor with the mouse on it, or whatever. Substitute your own code there. This code accesses two different PICT resources, one of which is assumed to be a B&W version of your splash page, the other a full-color one. If you're running under Multifinder on 6.x systems (or even if you're not), the 10 calls to GetNextEvent() make sure that your window and process are brought frontmost--an intermittent problem. Sorry it's not formatted properly for an 80-column device. Depending on where this occurs in your initialization code, you should beware that the WindowRecord may leave a hole smack in the bottom of your heap when you dispose it. You could allocate a relocatable block, move it high, lock it, and then stuff the window record there--though this would leave you with a hole in the *top* of your heap (slightly better, but not much). Caveat emptor. function ShowSplashPage (fullColor: boolean; WindowID, PictID: integer; CenterToScreen: boolean): WindowPtr; {ShowSplashPage brings up the specified splash page window, installs the PICT resource} {which defines its contents, and calls GetNextEvent to force Toolbox to auto-update it.} {The function returns a WindowPtr to the window, which is always allocated on the} {heap, or NIL if either the WIND or PICT resource couldnUt be read. The WIND should be} {specified as invisible in its resource; ShowSplashPage will make it visible after installing} {the PICT and possibly centering the window.} {Pass fullColor true if we are going to display the 8-bit splashpage picture instead of the} {oldColor model one.} var SplashPage: WindowPtr; {Function result} thePict: PicHandle; {Handle to Splash Page picture} SplashUpdate: EventRecord; {For forcing ToolBox to update SplashPage} bool: boolean; wPeek: windowPeek; i, ctop, cleft: integer; {For centering calculations} aPt: point; begin if fullColor then SplashPage := GetNewCWindow(WindowID, nil, pointer(-1)) else SplashPage := GetNewWindow(WindowID, nil, pointer(-1)); if (SplashPage <> nil) then begin {GOOD WINDOW} thePict := PicHandle(GetResource('PICT', PictID)); if thePict = nil then begin {BAD PICT} DisposeWindow(SplashPage); SplashPage := nil end {BAD PICT} else begin {GOOD PICT} SetWindowPic(SplashPage, thePict); {Install the PICT} SetPort(SplashPage); OrientWindow(SplashPage, false); if fullColor then {Adjust the color image to be flushleft because PixelPaint* is} SetOrigin(thePict^^.PicFrame.Left, thePict^^.PicFrame.top); {the cheeziest drawing program there ever was and it} {can't do it for you!} ShowWindow(SplashPage); {Show window + force its auto-update} for i := 1 to 10 do bool := GetNextEvent(updateMask, SplashUpdate) end {GOOD PICT} end; {GOOD WINDOW} ShowSplashPage := SplashPage; {Return result} end; -- --- * --- Nick Jackiw Smoke@well.sf.ca.us | Jackiw@cs.swarthmore.edu Key Curriculum Press, Inc. Applelink:KEY.EDUSOFT | (415) 548-2304 --- * ---