home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / SSNDREXX.ZIP / SSNDREXX.C < prev    next >
C/C++ Source or Header  |  1993-04-27  |  4KB  |  164 lines

  1.  
  2. /*****************************************************************************\
  3. *
  4. *  Module Name:  SSNDREXX.C
  5. *
  6. *  Rexx Interface for BocaSoft System Sounds
  7. *
  8. *  Copyright (c) BocaSoft Incorporated 1993
  9. *
  10. *  Entry Points:
  11. *
  12. *       FindSystemSounds
  13. *    PlaySound 
  14. *
  15. \*****************************************************************************/
  16.  
  17. #define  INCL_WIN                        
  18. #define  INCL_PM                         
  19. #define  INCL_WINHELP                    
  20. #define  INCL_WINWINDOWMGR
  21. #define  INCL_MMIO                       
  22. #define  INCL_DOS
  23. #define  INCL_COMMON
  24.  
  25. #include    <os2.h>
  26. #include    <os2me.h>
  27. #include    <stdio.h>
  28. #include    <stdlib.h>
  29. #include    <string.h>
  30. #include    <math.h>
  31. #include    <bsememf.h>
  32. #include    <bseerr.h>    
  33. #include    <rexxsaa.h>
  34.  
  35.  
  36. #define    SSND_SUCCESS            0
  37. #define    SSND_ERROR_NOT_PM        1
  38. #define    SSND_ERROR_SSND_NOT_FOUND    2
  39. #define    SSND_ERROR_INVALID_HANDLE    3
  40.  
  41.  
  42. #define    SSND_PROG_NAME    "System Sounds for OS/2"
  43. #define    SSND_WM_PLAY    0x5000
  44.  
  45. ULONG    FindSystemSounds (PSZ, LONG, PRXSTRING, PSZ, PRXSTRING);
  46. ULONG    PlaySound (PSZ, LONG, PRXSTRING, PSZ, PRXSTRING);
  47.  
  48. HWND    hwndSSnd;
  49. HAB    hab;
  50.  
  51. /*****************************************************************************\
  52. *
  53. *  Subroutine Name:  FindSystemSounds
  54. *
  55. *  Function:  Get the window handle for BocaSoft System Sounds.
  56. *
  57. *  Returns:
  58. *              0 - Success
  59. *              1 - Not a PM Session
  60. *              2 - System Sounds not Found
  61. *
  62. \*****************************************************************************/
  63.  
  64. ULONG    FindSystemSounds (PSZ pszFuncName,
  65.     LONG lArgc,
  66.     RXSTRING Argv[], 
  67.     PSZ QueueName,
  68.     PRXSTRING pRetStr)
  69. {
  70.      HWND      hwndParent;     /* whose child windows are enumed */ 
  71.     HWND      hwndNext;    /* current enumeration handle     */
  72.     HMQ    hmq;
  73.      HENUM      henum;         /* enumeration handle          */
  74.     CHAR    szWinName[50];  /* window text */
  75.     BOOL    bFound = FALSE;
  76.     ULONG    ulRc = 0;
  77.  
  78.     /* Enumerate all desktop windows and search for 
  79.     BocaSoft System Sounds */
  80.  
  81.     hab = WinInitialize ( 0 );
  82.  
  83.     if (!(hmq = WinCreateMsgQueue( hab, 0 )))
  84.     {
  85.         sprintf (pRetStr->strptr, "%d", SSND_ERROR_NOT_PM);
  86.         pRetStr->strlength = strlen(pRetStr->strptr);
  87.         return (0);
  88.     }
  89.  
  90.     hwndParent = HWND_DESKTOP;
  91.  
  92.     henum = WinBeginEnumWindows (hwndParent);
  93.  
  94.     while ((hwndNext = WinGetNextWindow (henum)) != NULLHANDLE)
  95.     {
  96.         ulRc = WinQueryWindowText (hwndNext, sizeof(szWinName), szWinName);
  97.         if (!(strcmp(szWinName, SSND_PROG_NAME)))
  98.         {
  99.             bFound = TRUE;
  100.             break;
  101.         }
  102.     }
  103.     WinEndEnumWindows (henum);
  104.  
  105.     if (bFound)
  106.     {
  107.         hwndSSnd = hwndNext;
  108.         sprintf (pRetStr->strptr, "%d", SSND_SUCCESS);
  109.     }
  110.     else
  111.         sprintf (pRetStr->strptr, "%d", SSND_ERROR_SSND_NOT_FOUND);
  112.     
  113.     pRetStr->strlength = strlen(pRetStr->strptr);
  114.  
  115.     return (0);
  116. }
  117.  
  118.  
  119.  
  120. /*****************************************************************************\
  121. *
  122. *  Subroutine Name:  PlaySound
  123. *
  124. *  Function:  Post a window message to BocaSoft System Sounds with
  125. *             a sound index.
  126. *
  127. *  Returns:
  128. *              0 - Success
  129. *              3 - Invalid Window Handle 
  130. *
  131. \*****************************************************************************/
  132.  
  133. ULONG    PlaySound (PSZ pszFuncName,
  134.     LONG lArgc,
  135.     RXSTRING Argv[], 
  136.     PSZ QueueName,
  137.     PRXSTRING pRetStr)
  138. {
  139.     ULONG    ulRc = 0;
  140.  
  141.     /* Send a message to System Sounds */
  142.  
  143.     if (hwndSSnd)
  144.     {
  145.         ulRc = WinPostMsg (hwndSSnd,
  146.             SSND_WM_PLAY,
  147.             0,
  148.             (MPARAM)atoi(Argv[0].strptr));
  149.  
  150.         sprintf (pRetStr->strptr, "%d", SSND_SUCCESS);
  151.         pRetStr->strlength = strlen(pRetStr->strptr);
  152.     }
  153.     else    
  154.     {
  155.         sprintf (pRetStr->strptr, "%d", SSND_ERROR_INVALID_HANDLE);
  156.         pRetStr->strlength = strlen(pRetStr->strptr);
  157.     }
  158.     return (0);
  159. }
  160.  
  161.  
  162.  
  163.  
  164.