C (58/254)

From:Stephen Illingworth
Date:10 Apr 00 at 18:24:09
Subject:Re: GadTools event loop problem

Hello Donald

On 10-Apr-00, you wrote:

> Normally my programs enter a Wait state until a message arrives at the
> window`s message port. When it arrives they get the required information out
> of the message, reply to it and then deal with whatever has occurred. How do
> I code my Wait statement so that it waits for an event in more than one
> window, identifies which window the event occurred in and then takes the
> appropriate action?

Your code contains the following.

Wait (1 << mywin->UserPort->mp_SigBit);

To wait for more than one event simply bitwise OR different wait events together

Wait (
1 << mywin->UserPort->mp_SigBit
| 1 << totherwin->UserPort->mp_SigBit
);

(BTW, You can combine anything in the Wait() - Rexx Events, Timer Events,
Commodity Events, and so forth.)

Once the OS returns control to your program, you need to know where the
event occured. We can do this by saving the result from Wait() and bitwise
ANDing it with the shifted SigBits, and running the appropriate code for
that window.

waitResult = Wait (
1 << mywin->UserPort->mp_SigBit
1 << totherwin->UserPort->mp_SigBit
| 1 << rexxPort->mp_SigBit
);

if ( waitResult & (1 << mywin->UserPort->mp_SigBit) )
handleMyWinMsgs();
if ( waitResult & (1 << mywin->UserPort->mp_SigBit) )
handleTotherWinMsgs();

Respect, Steve

PS.

It might be worth storing the results of the shifting in a local variable.

ULONG myWinMask = 1 << mywin->UserPort->mp_SigBit,
totherWinMask = 1 << totherwin->UserPort->mp_SigBit;

------------------------------------------------------------------------
Now the best and coolest websites come right to you based on your
unique interests. eTour.com is surfing without searching.
And, it's FREE!
http://click.egroups.com/1/3013/1/_/451227/_/955391694/
------------------------------------------------------------------------