Guidance
指路人
g.yi.org
Software / Reginald / Examples / playcd.rex

Register 
注册
Search 搜索
首页 
Home Home
Software
Upload

  
/*
GUIBEGIN
WINDOW , 33, 94, 179, 100, POPUP|CAPTION|SYSMENU|MINBOX|MAXBOX|THICK, , Music CD Player
	FONT 8, 400, MS Shell Dlg
	PUSH 70, 14, 40, 14, TABSTOP, , PlayButton, , Play
	TEXT 7, 44, 64, 8, RIGHT|GROUP, , , , Number of Tracks:
	TEXT 75, 44, 43, 8, GROUP, , NumOfTrks
DEND
GUIEND
*/

/* An example of FUNCDEF'ing various Windows MCI high level
 * functions to play an Audio CD.
 */

OPTIONS "C_CALL LABELCHECK WINFUNC NOSOURCE"

DO
	RXFUNCADD('rexxgui')

	/* Register the Windows OS function mciSendString() */
	FUNCDEF("mciSendString", "32u, str, void, 32u, void", "winmm")

	/* Register the Windows OS function mciSendString() callable as
	 * mciGetInfo() to return upto 260 characters of info.
	 */
	FUNCDEF("mciGetInfo", "32u, str, str[260] stor, 32u, void", "winmm", "mciSendString")

	/* Register the Windows OS function mciGetErrorString(). We
	 * register it to return an error message with a maximum
	 * length of 260 characters.
	 */
	FUNCDEF("mciGetErrorString", "32u, 32u, str[260] stor, 32u", "winmm")

	CATCH FAILURE

		CONDITION("M")
		RETURN
END

guierr = "SYNTAX"
guiheading = 1
guicreatewindow('NORMAL')

/* Initially not playing */
play = 0

/* Open a CDAudio device and use the alias cd */
err = mcisendstring('open cdaudio alias cd', 0, 0, 0)

/* Check for an error */
IF err \= 0 THEN DO
mcierr:
	mcigeterrorstring(err, buf, 260) 
	guisay(buf)
	RETURN
END

/* Ask it how many audio tracks are on it. Wait for it to return
 * this info in "buf" and display it in our TEXT control associated
 * with the variable "NumOfTrks".
 */
err = mcigetinfo("status cd number of tracks wait", buf, 260, 0)
IF err \= 0 THEN DO
mcierr2:
	mcisendstring("close cd wait", 0, 0, 0)
	SIGNAL mcierr
END
guiaddctltext("NumOfTrks", buf)

/* Set the time format to Tracks (default is milliseconds) */
err = mcisendstring("set cd time format tmsf", 0, 0, 0)
IF err \= 0 THEN SIGNAL mcierr2

/* Close the device and wait for that to complete */
mcisendstring("close cd wait", 0, 0, 0)

again:
DO FOREVER

	guigetmsg()

	CATCH SYNTAX
		CONDITION('M')
		SIGNAL again

	CATCH HALT
	FINALLY
		/* Close the cdaudio device if it's playing, and wait for this operation to complete */
		IF play \== 0 THEN DO
			mcisendstring("stop cd wait", 0, 0, 0)
			mcisendstring("close cd wait", 0, 0, 0)
		END

		guidestroywindow()
END
RETURN

/* =============== WM_CLICK_PlayButton ===============
 * This handles the CLICK event for my button
 * associated with the "PlayButton" variable.
 *
 * Reginald calls this when the user clicks the button.
 */
 
wm_click_playbutton:

	/* Are we stopped? If so, put it into play */
	IF play == 0 THEN DO

		/* Open a CDAudio device and use the alias cd */
		err = mcisendstring('open cdaudio alias cd', 0, 0, 0)

		/* Check for an error */
		IF err \= 0 THEN DO
			 mcigeterrorstring(err, buf, 260) 
			 guisay(buf)
		END

		ELSE DO

			/* Play the first track ("from 1 to 2"), but don't
			 * wait for this operation to complete. Instead
			 * pass the handle of our main window, so we'll
			 * receive an MM_MCINOTIFY message when play is
			 * done.
			 */
			err = mcisendstring("play cd from 1 to 2 notify", 0, 0, guiwindow)
			IF err \= 0 THEN DO
				mcigeterrorstring(err, buf, 260) 
				guisay(buf)
			END

			/* It's in play now */
			ELSE DO
				play = 1
				guiaddctltext("PlayButton", "Stop")
			END
		END
	END /* play == 0 */

	/* We're in play, so stop it */
	ELSE DO

		/* Stop the play */
		mcisendstring("stop cd wait", 0, 0, 0)

		/* Close the cdaudio device, and wait for this operation to complete */
		play = 0
		mcisendstring("close cd wait", 0, 0, 0)

		/* Indicate that we're stopped, and ready to play again */
		guiaddctltext("PlayButton", "Play")

	END

	RETURN

/* ===================== WM_EXTRA ========================
 * This handles all events for our window which REXX
 * GUI doesn't know about. REXX GUI doesn't know about
 * any of the MCI events, so any MCI event causes
 * Reginald to call this handler.
 */

wm_extra:

	/* Figure out what to do based on the message number */
	SELECT ARG(3)

		/* Is it the MM_MCINOTIFY event? MM_MCINOTIFY is not an
		 * event that REXX GUI knows about, so our WM_EXTRA event handler is
		 * called. ARG(3) is the message number, which in this case, happens to
		 * be 953 for MM_MCINOTIFY.
		 *
		 * The OS gives us this message when MCI is notifying us
		 * of some problem with the CD playback.
		 *
		 * ARG(1) is one of the following:
		 *
		 * 1 = The command was successfully completed.
		 *
		 * 2 = The device received another mciSendString() command with
		 * the "notify" flag set and so this command has been superseded.
		 *
		 * 4 = The device received another mciSendString() command that
		 * prevented this command from being met. If a new command
		 * interrupts the current command and the former also requests
		 * notification, the device sends this message only and not an
		 * MM_MCINOTIFY with ARG(3) of 2.
		 *
		 * 8 = The device had an error while executing the command.
		 *
		 * ARG(2) is the ID number of the MCI device that sent this message.
		 */
		WHEN 953 THEN DO

			/* Stop the play */
			mcisendstring("stop cd wait", 0, 0, 0)

			/* Close the cdaudio device, and wait for this operation to complete */
			play = 0
			mcisendstring("close cd wait", 0, 0, 0)

			/* Indicate that we're stopped, and ready to play again */
			guiaddctltext("PlayButton", "Play")

		END /* MM_MCINOTIFY */

		OTHERWISE

	END /* SELECT message number */

	/* Don't let Rexx Gui process this event. */
	RETURN ""
掌柜推荐
 
 
 
 
 
 
 
 
 
 
 
 
© Sat 2024-4-20  Guidance Laboratory Inc.
Email:webmaster1g.yi.org Hits:0 Last modified:2013-06-18 23:35:16