home *** CD-ROM | disk | FTP | other *** search
/ PCMania 34 / PCMania CD34.iso / sharewar / util / midas / demo.cpp next >
Encoding:
C/C++ Source or Header  |  1994-11-09  |  2.6 KB  |  106 lines

  1. // *************************************************************************
  2. // *                         Cinematix Studios                             *
  3. // *                     Brain Dead MOD Player Code                        *
  4. // *                             demo.cpp                                  *
  5. // *************************************************************************
  6.  
  7. #include <windows.h>
  8. #include <mmsystem.h>
  9.  
  10. // *********************************
  11. // * Some Easy MIDAS MCI functions *
  12. // *********************************
  13.  
  14. // Note:
  15. //
  16. // There are currently NO extra messages or parameters defined for the MIDAS
  17. // MCI driver.  MIDAS currently responds to only the basic ELEMENT (i.e. file)
  18. // based MCI commands, including MCI_OPEN, MCI_SET, MCI_STATUS, etc.
  19.  
  20. static int moddevice = 0;
  21. static BOOL modplaying = FALSE;
  22.  
  23. BOOL PlayMIDAS(char *file, HWND notifyhwnd = NULL)
  24. {
  25.     MCI_OPEN_PARMS mciOpenParms;
  26.     MCI_PLAY_PARMS mciPlayParms;
  27.  
  28.     if (modplaying)
  29.     {
  30.         mciSendCommand(moddevice, MCI_CLOSE, 0, NULL);
  31.         modplaying = FALSE;
  32.         return FALSE;
  33.     }
  34.  
  35.   // Open device
  36.     mciOpenParms.lpstrDeviceType = "modplayer";
  37.     mciOpenParms.lpstrElementName = file;
  38.     if (mciSendCommand(NULL, MCI_OPEN,
  39.       MCI_OPEN_TYPE | MCI_OPEN_ELEMENT, (DWORD)(LPVOID)&mciOpenParms))
  40.         return FALSE;
  41.  
  42.   // Get device id
  43.     moddevice = mciOpenParms.wDeviceID;
  44.  
  45.   // Begin playing
  46.     mciPlayParms.dwCallback = (DWORD)notifyhwnd;
  47.     DWORD flags;
  48.     if (notifyhwnd)
  49.         flags = MCI_NOTIFY;
  50.     else
  51.         flags = 0;
  52.     if (mciSendCommand(moddevice, MCI_PLAY, flags,
  53.         (DWORD)(LPVOID) &mciPlayParms))
  54.     {
  55.         mciSendCommand(moddevice, MCI_CLOSE, 0, NULL);
  56.         return FALSE;
  57.     }
  58.  
  59.     modplaying = TRUE;
  60.     return TRUE;
  61. }
  62.  
  63. void StopMIDAS()
  64. {
  65.     if (modplaying)
  66.     {
  67.         mciSendCommand(moddevice, MCI_CLOSE, 0, NULL);
  68.         modplaying = FALSE;
  69.     }
  70. }
  71.  
  72. BOOL IsMIDASPlaying()
  73. {
  74.     return modplaying;
  75. }
  76.  
  77. // *************************************
  78. // * A Sample Brain Dead Module Player *
  79. // *************************************
  80.  
  81. int PASCAL WinMain(HINSTANCE, HINSTANCE, LPSTR lpCmdLine, int)
  82. {
  83.     char buf[80];
  84.  
  85.     if (lpCmdLine == NULL || *lpCmdLine == NULL)
  86.     {
  87.         MessageBox(NULL, "Please specify a module file on the command line!",
  88.             "Brain Dead MOD Player", MB_ICONEXCLAMATION | MB_OK);
  89.     }
  90.     else
  91.     {
  92.         if (!PlayMIDAS(lpCmdLine))
  93.         {
  94.             MessageBox(NULL, "Can't open MIDAS (Where are you MIDAS)",
  95.                 "Brain Dead Error", MB_ICONEXCLAMATION | MB_OK);
  96.             return 1;
  97.         }
  98.         wsprintf(buf, "Now playing %s", lpCmdLine);
  99.         MessageBox(NULL, buf, "Brain Dead MOD Player", MB_OK);
  100.         StopMIDAS();
  101.     }
  102.  
  103.     return 0;
  104. }
  105.  
  106.