home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: Multimed / Multimed.zip / ssdemo.zip / SSTOOLKT / C / SSNDMSG.C next >
C/C++ Source or Header  |  1993-06-26  |  4KB  |  159 lines

  1.  
  2. /*****************************************************************************\
  3. *  
  4. *  BocaSoft System Sounds interface code 
  5. *
  6. *  Copyright (c) BocaSoft Incorporated 1993
  7. *
  8. *  BocaSoft Incorporated  
  9. *  117 NW 43rd St. 
  10. *  Boca Raton, FL 
  11. *  33431 
  12. *  (407)392-7743  
  13. *  
  14. *  
  15. *  These two routines demonstrate a simple way for an OS/2 PM application 
  16. *  to trigger sounds within the BocaSoft System Sounds product.  By using
  17. *  our product in conjunction with MMPM/2 a developer can take advantage 
  18. *  of high performance audio playback with minimal code.
  19. *  
  20. *  The first routine, "FindSystemSounds", returns a window handle which in
  21. *  turn is used by the second routine, "PlaySound", to post a window message
  22. *  with the appropriate audio index.  The audio index must be associated with
  23. *  an enabled audio file within the BocaSoft product.  We suggest using
  24. *  either the User Events (45-49) or an obscure key combination such as 
  25. *  CTRL-SHIFT-ALT to avoid conflicts with main system events.  Index values
  26. *  for keys can be found in the keys dialog in the "index" field. 
  27. *
  28. *  You must have a PM application to use this technique.  Other application
  29. *  types may use the named-pipe interface.  See the included REXX and batch
  30. *  files for more information. 
  31. *
  32. *  Event Index Values     -> 0 to 49
  33. *  
  34. *  Key Index Values:
  35. *  ----------------
  36. *  
  37. *  No control keys     -> index = 128 + scan code
  38. *  SHIFT        -> index = 128 + scan code + (256 * 1)
  39. *  ALT            -> index = 128 + scan code + (256 * 2)
  40. *  CTRL             -> index = 128 + scan code + (256 * 3)
  41. *  SHIFT | ALT        -> index = 128 + scan code + (256 * 4)
  42. *  SHIFT | CTRL        -> index = 128 + scan code + (256 * 5)
  43. *  ALT | CTRL        -> index = 128 + scan code + (256 * 6)
  44. *  SHIFT | ALT | CTRL    -> index = 128 + scan code + (256 * 7)
  45. *  
  46. \*****************************************************************************/
  47.  
  48. #define        INCL_WIN
  49. #define        INCL_PM                         
  50.  
  51. #include    <os2.h>
  52. #include    <stdio.h>
  53. #include    <stdlib.h>
  54. #include    <string.h>
  55.  
  56. #define    SSND_PROG_NAME    "BocaSoft System Sounds"
  57. #define    SSND_WM_PLAY    0x5000
  58.  
  59. ULONG    PlaySound (HWND, ULONG);
  60. HWND    FindSystemSounds (VOID);
  61.  
  62. main()
  63. {
  64.     HMQ    hmq;    /* Message queue handle */
  65.     HWND    hwnd;    /* System Sounds window handle */    
  66.     HAB    hab;    /* PM anchor block handle */
  67.  
  68.     /* Initialize PM */
  69.  
  70.     if (!(hab = WinInitialize(0))) 
  71.         exit (1);
  72.  
  73.     /* Create a message queue */
  74.  
  75.     if (!(hmq = WinCreateMsgQueue( hab, 0 )))
  76.         exit (1);
  77.  
  78.     /* Find BocaSoft System Sounds */
  79.  
  80.     if (!(hwnd = FindSystemSounds()))
  81.         exit (1);
  82.  
  83.     /* Play "User Event (45)" - (make sure it is enabled) */
  84.  
  85.     PlaySound (hwnd, 45);
  86. }
  87.  
  88.  
  89.  
  90. /*****************************************************************************\
  91. *
  92. *  Subroutine Name:  FindSystemSounds
  93. *
  94. *  Function:  Get the window handle for BocaSoft System Sounds.
  95. *
  96. \*****************************************************************************/
  97.  
  98. HWND    FindSystemSounds (VOID)
  99. {
  100.      HWND      hwndParent;     /* whose child windows are enumed */ 
  101.     HWND      hwndNext;    /* current enumeration handle     */
  102.      HENUM      henum;         /* enumeration handle          */
  103.     CHAR    szWinName[50];  /* window text */
  104.     BOOL    bFound = FALSE;
  105.  
  106.     /* Enumerate all desktop windows and search for 
  107.     BocaSoft System Sounds */
  108.  
  109.     hwndParent = HWND_DESKTOP;
  110.  
  111.     henum = WinBeginEnumWindows (hwndParent);
  112.  
  113.     while ((hwndNext = WinGetNextWindow (henum)) != NULLHANDLE)
  114.     {
  115.         WinQueryWindowText (hwndNext, sizeof(szWinName), szWinName);
  116.  
  117.         if (!(strcmp(szWinName, SSND_PROG_NAME)))
  118.         {
  119.             bFound = TRUE;
  120.             break;
  121.         }
  122.     }
  123.     WinEndEnumWindows (henum);
  124.  
  125.     if (!bFound)
  126.         hwndNext = 0;
  127.  
  128.     return (hwndNext);
  129. }
  130.  
  131.  
  132. /*****************************************************************************\
  133. *
  134. *  Subroutine Name:  PlaySound
  135. *
  136. *  Function:  Post a window message to BocaSoft System Sounds with
  137. *             a sound index.
  138. *
  139. \*****************************************************************************/
  140.  
  141. ULONG    PlaySound (HWND hwnd,
  142.     ULONG ulIndex)
  143. {
  144.     ULONG    ulRc = 0;
  145.  
  146.     /* Send a message to System Sounds */
  147.  
  148.     ulRc = WinPostMsg (hwnd,
  149.         SSND_WM_PLAY,
  150.         0,
  151.         (MPARAM)ulIndex);
  152.  
  153.     return (ulRc);
  154. }
  155.  
  156.  
  157.  
  158.  
  159.