home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.sys.mac.programmer
- Path: sparky!uunet!cs.utexas.edu!oakhill!jolt.sps.mot.com!user
- From: Jim_Holt@aprdlgtr.sps.mot.com (Jim Holt)
- Subject: Re: Sound Loop in a with a Modal Dialog?
- Message-ID: <Jim_Holt-030992141455@jolt.sps.mot.com>
- Followup-To: comp.sys.mac.programmer
- Sender: news@oakhill.sps.mot.com
- Nntp-Posting-Host: 222.20.248.206
- Organization: Motorola
- References: <1992Sep3.145524.8874@utkux1.utk.edu>
- Date: Thu, 3 Sep 1992 19:21:14 GMT
- Lines: 86
-
- In article <1992Sep3.145524.8874@utkux1.utk.edu>, danny@utkux1.utk.edu
- (Danny W. McCampbell) wrote:
- >
- > Hi. I want to play a sound continuously while a modal dialog is
- > present on the screen. I have successfully go the loop to work
- > without the modal dialog statement but the loop is only executed
- > twice when I call modal dialog. Here is some sample code:
- >
- > dialogtrue := true;
- > while dialogtrue do
- > begin
- > FlushSndChannel(mySndChan);
- > if SoundisStopped(mySndChan) then
- > begin
- > PlaytheSound(mySndChan);
- > end;
- > ModalDialog(nil, itemHit); {Call Modal Dialog until the user clicks in the dialog}
- > if itemHit = 1 then
- > dialogtrue := false;
- > end;
- > StoptheSound(mySndChan);
- > DisposDialog(AboutDialog); {Dispose of the Dialog}
- >
- > The sound plays only twice then stops playing. Any ideas how I can
- > do this successfully? Thanks in advance.
-
- The problem is that when you call ModalDialog, you don't get control back
- until the user does something (mouse click, etc). What you have to do is
- simulate a modal dialog by setting up an event loop. Here is a
- C example of how I have done this in the past ...
-
- /*------------------*/
-
- DialogPtr dPtr,dummy;
- GrafPtr old_port;
- Boolean done = FALSE;
- short which;
-
- GetPort(&old_port);
- PositionDialog('DLOG',SOME_DLOG);
- dPtr = GetNewDialog(SOME_DLOG, NULL, (WindowPtr)-1L);
- if(dPtr == NULL)
- {
- /* handle the error, we didn't get our dialog rsrc ... */
- return;
- }
- DrawDialog(dPtr);
- SetPort(dPtr);
- while (!done)
- {
- while ((!GetOSEvent(everyEvent, &localEvent)) && (!done))
- {
- /* do whatever it is you need to do to keep your snd playing */
- }
- if (IsDialogEvent(&localEvent))
- {
- if (DialogSelect(&localEvent,&dummy,&which))
- {
- GlobalToLocal(&localEvent.where);
- switch (which)
- {
- case OK_ITEM:
- done = TRUE;
- /* handle the OK button */
- break;
- case CANCEL_ITEM:
- done = TRUE;
- /* handle the CANCEL button */
- break;
- default : break;
- }
- }
- }
- DisposDialog(dPtr);
-
- SetPort(old_port);
-
-
- Hope this helps ...
- -jh
- +-------------------------------------------------------------------------+
- | I used to have a catchy signature, but I forgot what it was ... |
- | |
- | Jim Holt |
- | Motorola, Inc Jim_Holt@aprdlgtr.sps.mot.com |
- +-------------------------------------------------------------------------+
-