Performing a Series of Commands

The final illustration shows how an application can remotely control a demo for a title. This version of MENUDEMO changes the timer example from Petzold's version of the program so it sends change-topic commands and plays audio segments in the USA Tour sample title at regular intervals. The Start command on the Guide menu starts this demo; the Stop command stops it.

The IDM_START message handler performs the initialization procedure as follows:

case IDM_START:
    CheckLoadUsa(hwnd) ;
    lstrcpy(Topic,"tx_nickname");
    wsprintf(str, (LPSTR)JITemplate, (LPSTR)BookPath,
             MVAPI(hwnd, BookPath, cmdMacro, (DWORD)(LPSTR)str);

The handler sets up the Texas Nickname topic as the first topic to be displayed, then creates the JI command for displaying that topic and executes that command. This code is similar to the earlier code for displaying a topic.

Next, the handler sets up the timer interval for the change-topic and change-sound timers, as shown in the following code fragment:

if (SetTimer (hwnd, TIMER_TOPIC, 3000, NULL))
      {
           EnableMenuItem (hMenu, IDM_START, MF_GRAYED) ;
           EnableMenuItem (hMenu, IDM_STOP,  MF_ENABLED) ;
      }
      SetTimer (hwnd, TIMER_SND, (WORD)10000, NULL);
      SendMessage (hwnd, WM_TIMER, TIMER_SND, 0L) ;
      return 0 ;

The WM_TIMER handler displays the topics and plays the audio using the following code:

case WM_TIMER:
    switch (wParam) {
         case TIMER_TOPIC: 
              MVAPI(hwnd, BookPath, cmdMacro,
                    (DWORD)(LPSTR) "Next()");
              return 0 ;
         case TIMER_SND:
             if  (!(--soundsCount)) {
             soundsCount = NUM_SOUNDS;
             lpszSound = Sounds[0];
             }
             wsprintf(str, (LPSTR)AUDTemplate, lpszSound);
             MVAPI(hwnd, BookPath, cmdMacro,(DWORD)(LPSTR)str);
             lpszSound += lstrlen(lpszSound)+1;
             return 0 ;
               }

Just as it earlier constructed a template for Viewer commands, the application here uses a template named AUDTemplate for playing audio using the HAudioCommand DLL call. It created this template earlier in the application as follows:

static BYTE AUDTemplate[]= "HAudioCommand(hwndContext,qchPath,\"%s\",\"PLAY\")";

The application continues displaying topics until the user selects Stop from the Guide menu. This selection sends an IDM_STOP message, which kills the timer and stops the demo display, as shown in the following code fragment:

case IDM_STOP:
    KillTimer (hwnd, TIMER_TOPIC) ;
    KillTimer (hwnd, TIMER_SND) ;
    EnableMenuItem (hMenu, IDM_START, MF_ENABLED) ;
    EnableMenuItem (hMenu, IDM_STOP,  MF_GRAYED) ;
    return 0 ;