FUNCTION

The MUI system itself does not wait for any user input. It just tells your application which signal bits it has allocated, then it's up to you to call MUIs input handle function when one of these signals gets set.

In a simple MUI application you would just Wait() for these signals and call MUI when one is received. However, you can perfectly allocate some signal bits yourself and include them in your Wait() command. You needn't even Wait(), your application could maybe calculate some fractal graphics or copy disks, the only important thing is that you call MUI's input method when one of the MUI allocated signals arrives.

The usual way of communication with your user interface is via return ids. Every action happening to the GUI can create return ids, e.g. pressing a button or trying to close a window. MUI buffers these ids and uses them as result codes for the input method. Thats where you can get it from and take the appropriate actions.

Now lets have a look on a usual input loop of a MUI application. Imagine you have an Play and a Cancel button and have previously told them to return ID_PLAY and ID_CANCEL when pressed. (see MUIM_Notify and MUIM_Application_ReturnID on information about these topics). Your input loop would look like this:

   while (running)
   {
      ULONG signals;

      switch (DoMethod(app,MUIM_Application_Input,&signals))
      {
         case ID_PLAY:
            PlaySound();
            break;

         case ID_CANCEL:
         case MUIV_Application_ReturnID_Quit:
            running = FALSE;
            break;
      }

      if (running && signals) Wait(signals);
   }

So what is happening here?

First, you have to call the MUIM_Application_Input method. You supply the address of a ULONG as parameter, thats where MUI fills in the signals it needs. Note that you can call the input method at any time, regardless of signal setting. MUI will simply return when there is nothing to do.

In case the user pressed the Play or the Cancel button, MUIM_Application_Input will return ID_PLAY or ID_CANCEL. Otherwise you will receive a 0, that's why you cannot use 0 as one of your id values.

There is one predefined id called MUIV_Application_ReturnID_Quit. This will be sent to you when someone tried to quit your application from outside, e.g. via commodities exchange or the ARexx ''quit'' command. It is required that your application handles this id, just treat as if the user clicked on a ''Quit'' button or selected a ''Quit'' menu item.

After handling the return value, you have to examine if MUI wants you to wait for any signals. If this is the case (signals != 0), just wait for it. If MUI puts a 0 into signals it wants to tell you to immediately call the input method again, maybe some other return ids have received and need to be handled. You *must* check this because Wait()ing on a zero signal mask is not a good idea!