home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #19 / NN_1992_19.iso / spool / comp / sys / mac / programm / 14958 < prev    next >
Encoding:
Text File  |  1992-09-03  |  3.0 KB  |  100 lines

  1. Newsgroups: comp.sys.mac.programmer
  2. Path: sparky!uunet!cs.utexas.edu!oakhill!jolt.sps.mot.com!user
  3. From: Jim_Holt@aprdlgtr.sps.mot.com (Jim Holt)
  4. Subject: Re: Sound Loop in a with a Modal Dialog?
  5. Message-ID: <Jim_Holt-030992141455@jolt.sps.mot.com>
  6. Followup-To: comp.sys.mac.programmer
  7. Sender: news@oakhill.sps.mot.com
  8. Nntp-Posting-Host: 222.20.248.206
  9. Organization: Motorola
  10. References: <1992Sep3.145524.8874@utkux1.utk.edu>
  11. Date: Thu, 3 Sep 1992 19:21:14 GMT
  12. Lines: 86
  13.  
  14. In article <1992Sep3.145524.8874@utkux1.utk.edu>, danny@utkux1.utk.edu
  15. (Danny W. McCampbell) wrote:
  16. > Hi.  I want to play a sound continuously while a modal dialog is 
  17. > present on the screen.  I have successfully go the loop to work
  18. > without the modal dialog statement but the loop is only executed
  19. > twice when I call modal dialog.  Here is  some sample code:
  20. > dialogtrue := true;
  21. > while dialogtrue do
  22. > begin
  23. >   FlushSndChannel(mySndChan);
  24. >   if SoundisStopped(mySndChan) then
  25. >   begin
  26. >     PlaytheSound(mySndChan);
  27. >   end;
  28. >   ModalDialog(nil, itemHit);            {Call Modal Dialog until the user clicks in the dialog}
  29. >   if itemHit = 1 then
  30. >     dialogtrue := false;
  31. > end;
  32. > StoptheSound(mySndChan);
  33. > DisposDialog(AboutDialog);                {Dispose of the Dialog}
  34. > The sound plays only twice then stops playing.  Any ideas how I can
  35. > do this successfully?  Thanks in advance.
  36.  
  37. The problem is that when you call ModalDialog, you don't get control back
  38. until the user does something (mouse click, etc).  What you have to do is
  39. simulate a modal dialog by setting up an event loop.  Here is a 
  40. C example of how I have done this in the past ...
  41.  
  42. /*------------------*/
  43.  
  44. DialogPtr        dPtr,dummy;
  45. GrafPtr            old_port;
  46. Boolean            done = FALSE;
  47. short            which;
  48.  
  49.     GetPort(&old_port);
  50.     PositionDialog('DLOG',SOME_DLOG);
  51.     dPtr = GetNewDialog(SOME_DLOG, NULL, (WindowPtr)-1L);
  52.     if(dPtr == NULL)
  53.     {
  54.         /* handle the error, we didn't get our dialog rsrc ... */
  55.         return;
  56.     }
  57.     DrawDialog(dPtr);
  58.     SetPort(dPtr);
  59.     while (!done)
  60.     {
  61.         while ((!GetOSEvent(everyEvent, &localEvent)) && (!done))
  62.         {
  63.       /* do whatever it is you need to do to keep your snd playing */
  64.         }
  65.         if (IsDialogEvent(&localEvent))
  66.         {
  67.             if (DialogSelect(&localEvent,&dummy,&which))
  68.             {
  69.                 GlobalToLocal(&localEvent.where);
  70.                 switch (which)
  71.                 {
  72.                     case OK_ITEM:
  73.                         done = TRUE;
  74.       /* handle the OK button */
  75.                         break;                
  76.                     case CANCEL_ITEM:
  77.                         done = TRUE;
  78.       /* handle the CANCEL button */
  79.                         break;
  80.      default : break;
  81.             }
  82.         }
  83.     }
  84.     DisposDialog(dPtr);
  85.     
  86.     SetPort(old_port);
  87.  
  88.  
  89. Hope this helps ...
  90. -jh
  91. +-------------------------------------------------------------------------+
  92. |   I used to have a catchy signature, but I forgot what it was ...       |
  93. |                                                                         |
  94. |   Jim Holt                                                              |
  95. |   Motorola, Inc    Jim_Holt@aprdlgtr.sps.mot.com                        |
  96. +-------------------------------------------------------------------------+
  97.