[comp.sys.mac] MultiFinder suppend/resume question

bills@cca.CCA.COM (Bill Stackhouse) (01/04/88)

I am have a program that I would like to run in the background of MultiFinder.
I have built an off screen bitmap so that I can continue some of the
processing. When I receive a suppend event, the routine Msuppend is called
and then Mresume is called of course for the resume event. The idea is to
copy what is in the window at the time of the suppend and then restore on
the resume. Sounds simple. In fact when I simulate it under Finder it seems
to work just fine. When under MultiFinder though, only the lower 2/3Us of the
window is refreshed. There doesn't seem to be any relationship between the
part of the screen that is not refreshed and other windows on the screen. 
There is only one window that belongs to this program. Can anyone point 
out what is wrong ??

Thanks.

Bill Stackhouse
Cambridge Ma.
bills@cca.cca.com



    PROCEDURE Msuppend;
    BEGIN
        NowSuppended := true;
        WITH theWindow^ DO
            BEGIN
                OldScreen := Portbits;
                CopyBits(PortBits, OffScreen, PortRect, 
                        OffScreen.bounds, srcCopy, NIL);
            END;
        SetPortBits(OffScreen);
    END; {Msuppend}


    PROCEDURE Mresume;
    BEGIN
        NowSuppended := false;
        SetPort(theWindow);
        SetPortBits(OldScreen);
        WITH theWindow^ DO
            CopyBits(OffScreen, PortBits, OffScreen.bounds, 
                    PortRect, srcCopy, visRgn);
    END; {Mresume}

{----------- open window fragment -------------}

                theWindow := GetNewWindow(1000, NIL, WindowPtr(-1));
                SetPort(theWindow);
                OldScreen := theWindow^.PortBits;
                bRect := theWindow^.PortRect;
                WITH theWindow^.PortRect DO
                    BEGIN
                        OffsetRect(bRect, -left, -top);
                        OffRowBytes := (((right - left - 1) DIV 16) + 1) * 2;
                        OffSize := (bottom - top) * OffRowBytes;
                    END;
                WITH OffScreen DO
                    BEGIN
                        baseAddr := QDPtr(NewPtr(OffSize));
                        rowbytes := OffRowBytes;
                        bounds := bRect;
                    END;
                NowSuppended := false;

{------- event code fragment --------------}

        IF WaitNextEventPresent THEN
            result := WaitNextEvent(EveryEvent, theEvent, 0, NIL)
        ELSE
            result := GetNextEvent(EveryEvent, theEvent);
        IF result THEN
            CASE theEvent.what OF
                UpdateEvt : 
                    BEGIN
                        BeginUpdate(WindowPtr(theEvent.message));
                        EndUpdate(WindowPtr(theEvent.message));
                    END;
                app4Evt : 
                    CASE BitAnd(theEvent.message, $FF000000) OF
                        $01000000 : 
                            IF BitAnd(theEvent.message, $00000001) = 0 THEN
                                Msuppend
                            ELSE
                                Mresume;
                        $FA000000 : 
                            ;
                    END;
                OTHERWISE
            END;


-- 
Bill Stackhouse
Cambridge, MA.
bills@cca.cca.com