[comp.sys.mac.programmer] MultiFinder Weirdness

rj0z+@andrew.cmu.edu (Robert George Johnston, Jr.) (09/29/88)

    I have written a program that I would like to make compatable
with MultiFinder. Actually, the program runs just fine, but when the
application is first launched, the application window opens underneath
all other open windows (such as the Finder's).
    What does one have to do to get around this? Or, what have I done
wrong?

    Rob Johnston.

nopuklic@ndsuvax.UUCP (Blayne Puklich) (09/29/88)

In article <cXEHD6y00Uw9Qvc0hV@andrew.cmu.edu> rj0z+@andrew.cmu.edu
	(Robert George Johnston, Jr.) writes:
>
>    I have written a program that I would like to make compatable
>with MultiFinder. Actually, the program runs just fine, but when the
>application is first launched, the application window opens underneath
>all other open windows (such as the Finder's).
>    What does one have to do to get around this? Or, what have I done
>wrong?
>
>    Rob Johnston.

	Check your GetNewWindow() or NewWindow call, you probably are
passing NIL for the behind parameter.  You need to pass WindowPtr(-1)
rather than NIL.  Passing NIL will cause the window to appear behind
all others, passing WindowPtr(-1) will cause it to appear in front.

	Hope this helps.

||+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++||
||	Blayne Puklich			nopuklic@plains.NoDak.edu	   ||
||	NDSU Student ACM     		NU087763@NDSUVM1.bitnet		   ||
||	Chairperson		  North Dakota State University, Fargo, ND ||
||									   ||
||		"Everyone should have a Corvette, I think."		   ||
||	NOTE: If nopuklic@plains.NoDak.edu bounces, revert to		   ||
||		nopuklic@ndsuvax.BITNET.				   ||
||-------------------------------------------------------------------------||

emb1354@uxf.cso.uiuc.edu (09/30/88)

What I've heard is that that is the expected behavior under MultiFinder.
Windows are opened in back and are brought to front if Pointer(-1) was sent
in the behind parameter of the GetNewWindow(), NewWindow(), GetNewDialog(),
etc. call.  There really isn't anything you can do to correct it, just try
to work around it.

*****************************************************************
*  Eric M. Berdahl            *  "Y'know, there's alot of air"  *
*  PsiWare Software, not inc. *       -Robert Miller            *
*  emb1354@uxf.cso.uiuc.edu   *                                 *
*****************************************************************

denn@violet.berkeley.edu (Leonard Rosenthol) (10/02/88)

In article <1234600007@uxf.cso.uiuc.edu> emb1354@uxf.cso.uiuc.edu writes:
>
>What I've heard is that that is the expected behavior under MultiFinder.
>Windows are opened in back and are brought to front if Pointer(-1) was sent
>in the behind parameter of the GetNewWindow(), NewWindow(), GetNewDialog(),
>etc. call.  There really isn't anything you can do to correct it, just try
>to work around it.
>
	Eric is right that this is standard behaivor - however there are
work arounds.  The most commonly used one (and the one that Apple recommends)
is to just call GetNextEvent (don't worry about the return value!) after doing
the ShowWindow on your dialog.  This works just fine and maintains compat.

Leonard Rosenthol
LazerWare, inc.

wdh@well.UUCP (Bill Hofmann) (10/04/88)

In article <cXEHD6y00Uw9Qvc0hV@andrew.cmu.edu> rj0z+@andrew.cmu.edu
	(Robert George Johnston, Jr.) writes:
>
>    I have written a program that I would like to make compatable
>with MultiFinder. Actually, the program runs just fine, but when the
>application is first launched, the application window opens underneath
>all other open windows (such as the Finder's).
>    What does one have to do to get around this? Or, what have I done
>wrong?

Multifinder maintains the windows for an application in a "layer", which
allows it to isolate them from other windows. TN180 p.10 describes the
problem you (and others, myself included) have run into, which implies
that the layer for a launched application isn't brought to the front until
WaitNextEvent or GetNextEvent or EventAvail is called a few times.

The solution is painless but annoying: before bringing up a window at
the start (say, a dialog or alert, or a window representing a doc double
clicked by the user), call one of these routines a few times (I call 
WaitNextEvent 4 times).

-Bill Hofmann

anson@spray.CalComp.COM (Ed Anson) (10/05/88)

In article <1420@ndsuvax.UUCP> nopuklic@ndsuvax.UUCP (Blayne Puklich) writes:
>In article <cXEHD6y00Uw9Qvc0hV@andrew.cmu.edu> rj0z+@andrew.cmu.edu
>	(Robert George Johnston, Jr.) writes:
>>
>>the program runs just fine, but when the
>>application is first launched, the application window opens underneath
>>all other open windows (such as the Finder's).
>
>	Check your GetNewWindow() or NewWindow call, you probably are
>passing NIL for the behind parameter.  You need to pass WindowPtr(-1)
>rather than NIL.

I don't think that's the problem, for two reasons:

1. Window ordering parameters are effective only within the application's
   layer. Supposedly, the current application's layer is always on top.
2. I have seen the same (or similar) phenomena in commercially available
   software.

NCSA Telnet does this to me. When it starts up, it opens a window full of
information, which goes away when I first click the mouse. It opens behind
the windows opened by the Finder and other applications, and then comes
forward. Unfortunately, it doesn't repaint the part that was obscured, so
what I see is a mostly empty window.

ResEdit (v 1.1b3) does something similar. When I open a DLOG resource and
double click to see the DITL info, I get a bizarre result. Windows behind
the edit window show through! But only the windows from other applications!
That is, ResEdit's windows stay behind it like they should. When I move 
the edit window, the show-through stuff moves with it. It appears as though 
the system isn't aware of anything out of order. If I manage to force an 
update of the window, everything goes back to normal.

Until now, I just assumed my own copy of the system is a bit strange (It is.)
But now that I see someone else with a similar problem, I think it is a bit
more general. I don't have any insight into what's happening. In particular,
I haven't been able to replicate the problem in my own code. Maybe someone
on the net has better insight.

For the record: I'm running System 6.0 on a Mac II. I'm also running several
INITs, which may or may not be related to the problem.
-- 
=====================================================================
   Ed Anson,    Calcomp Display Products Division,    Hudson NH 03051
   (603) 885-8712,      anson@elrond.CalComp.COM

lsr@Apple.COM (Larry Rosenstein) (10/06/88)

In article <2449@spray.CalComp.COM> anson@spray.UUCP (Ed Anson) writes:
>NCSA Telnet does this to me. When it starts up, it opens a window full of
>information, which goes away when I first click the mouse. It opens behind
>the windows opened by the Finder and other applications, and then comes

This was mentioned in Tech Note 180.  If the application has the
canBackground bit set, then the layer won't be made frontmost until
GetNextEvent/WaitNextEvent is called several times.

>ResEdit (v 1.1b3) does something similar. When I open a DLOG resource and
>double click to see the DITL info, I get a bizarre result. Windows behind

This is not the same problem.  ResEdit is doing something unusual that's not
MultiFinder compatible.  I think versions of ResEdit before 1.2 are known
not to be MultiFinder compatible.

		 Larry Rosenstein,  Object Specialist
 Apple Computer, Inc.  20525 Mariani Ave, MS 46-B  Cupertino, CA 95014
	    AppleLink:Rosenstein1    domain:lsr@Apple.COM
		UUCP:{sun,voder,nsc,decwrl}!apple!lsr