[comp.sys.amiga.tech] How to peek at queued Intution msgs?

cunniff@hpfcdc.HP.COM (Ross Cunniff) (04/15/89)

What is the best way to look for a SPECIFIC message
on a window's UserPort?   For example, say I have an
application that has the standard event loop:

EventLoop()
{
    while( !Done ) {
	Wait( 1 << MyWindow->UserPort.mp_SigBit );
	while( Msg = GetMsg( MyWindow->UserPort ) ) {
	    if( Class = WHATEVER )
		DoSomeLongAndComplicatedThing();
	    else
		DoSomethingElse();
	    ReplyMsg( Msg );
	}
    }
}

Further, assume DoSomeLongAndComplicatedThing() wants
to allow the user to abort the action by, say, pressing
the ESC key or something.  Now, I can have the simple-
minded approach:

CheckForEscapeKey()
{
    while( Msg = GetMsg( MyWindow->UserPort ) ) {
	if( (Msg->Class == VANILLAKEY) && Msg->Code == '\033' ) {
	    /* Aha! */
	    ReplyMsg( Msg );
	    return 1;
	}
	ReplyMsg( Msg );
    }
    return 0;
}

However, this eats ALL pending events that happen before the abort,
including potentially important ones such as NEWSIZE.

The question is, therefore: is there a supported way of peeking at the
UserPort queue and finding a specific IDCMP message without deleting
all messages before it?  Or am I stuck doing significantly smarter
processing in CheckForEscapeKey() in order not to miss the *REALLY*
important messages?

				Ross Cunniff
				Hewlett-Packard Colorado Languages Lab
				...{ucbvax,hplabs}!hpfcla!cunniff
				cunniff%hpfcrt@hplabs.HP.COM

walker@sas.UUCP (Doug Walker) (04/28/89)

In article <11640015@hpfcdc.HP.COM> cunniff@hpfcdc.HP.COM (Ross Cunniff) writes:
>What is the best way to look for a SPECIFIC message
>on a window's UserPort?   For example, say I have an

Messages in a MsgPort are simply items in a linked list, linked with a
Node structure by Exec.  For your application, you can simply do a Forbid()
(to prevent task switches), walk the linked list looking for the appropriate
cancellation code, then Permit().  If you found the cancel code, you would
then GetMsg() until you get it.

Anybody know why this wouldn't work?  How safe is it from DOS upgrades, etc?

--- Doug