/* 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 ""