home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / warptlk3.zip / TOOLKIT / SAMPLES / MM / MCISPY / MCISPY.C < prev    next >
C/C++ Source or Header  |  1995-08-24  |  32KB  |  863 lines

  1. /*********************** START OF SPECIFICATIONS *******************************
  2. *
  3. * SOURCE FILE NAME: MCISPY.C
  4. *
  5. * DESCRIPTIVE NAME: Multimedia MCI Message Spy
  6. *
  7. *              Copyright (c) IBM Corporation   1993
  8. *                        All Rights Reserved
  9. *
  10. * FUNCTION: Monitor MCI Messages.
  11. *
  12. *              DISCLAIMER OF WARRANTIES.  The following [enclosed] code is
  13. *              sample code created by IBM Corporation. This sample code is not
  14. *              part of any standard or IBM product and is provided to you solely
  15. *              for  the purpose of assisting you in the development of your
  16. *              applications.  The code is provided "AS IS", without
  17. *              warranty of any kind.  IBM shall not be liable for any damages
  18. *              arising out of your use of the sample code, even if they have been
  19. *              advised of the possibility of   such damages.
  20. *
  21. *
  22. * INSTALLATION:
  23. *              In order to begin monitoring MCI messages the existing
  24. *              MDM.DLL must be renamed to MCI.DLL. To do this use a tool
  25. *              called DLLRNAME. DLLRNAME is provided as part of IBM
  26. *              CSET/2 compiler. ex DLLRNAME d:\mmos2\dll\mdm.dll mdm=mci
  27. *              is the command you would actually type if the true MDM.DLL
  28. *              resides on drive D:.
  29. *              Then Copy the stub MDM.DLL (this source product) to d:\mmos2
  30. *              \DLL\MDM.DLL.
  31. *              If MDM.DLL cannot be renamed or replaced then the DLL may be
  32. *              in use because of system sounds. Temporarily Deinstall System
  33. *              sounds by running \mmos2\install\DINSTSND.CMD. Yoy may have
  34. *              to reboot after this. After the reboot you can replace the
  35. *              MDM.DLL.
  36. *
  37. * OS/2 APIs Used:
  38. *
  39. *           DosRequestMutexSem ()
  40. *           DosReleaseMutexSem ()
  41. *           DosCreateMutexSem  ()
  42. *           DosClose ()
  43. *           WinInitialize()
  44. *           WinCreateMsgQueue()
  45. *           WinRegisterClass()
  46. *           WinCreateStdWindow()
  47. *           WinAssociateHelpInstance()
  48. *           WinGetMsg()
  49. *           WinDispatchMsg()
  50. *           WinSendMsg ()
  51. *           WinWindowFromID()
  52. *           WinQueryWindow()
  53. *           WinGetScreenPS()
  54. *           WinFontDlg ()
  55. *           WinDlgBox ()
  56. *           WinQueryWindowRect ()
  57. *           WinCreateWindow()
  58. *           WinSetWindowPos()
  59. *           WinBeginPaint()
  60. *           WinFillRect()
  61. *           WinEndPaint()
  62. *           WinDefWindowProc()
  63. *
  64. *
  65. * WHAT YOU NEED TO COMPILE THIS PROGRAM:
  66. * --------------------------------------
  67. *
  68. * REQUIRED FILES:
  69. * ---------------
  70. *
  71. *   OS2.H          - Presentation Manager include file
  72. *   STDLIB.H       - Standard library function declarations
  73. *   OS2ME.H        - MultiMedia System include
  74. *
  75. * REQUIRED LIBRARIES:
  76. * -------------------
  77. *
  78. *   OS2386.LIB     - OS/2 API Library
  79. *   MMPM2.LIB      - MMPM/2 API Library
  80. *
  81. * REQUIRED PROGRAMS:
  82. * ------------------
  83. *
  84. *   IBM C Set/2 Compiler (icc.exe    )
  85. *   IBM Linker           (link386.exe)
  86. *   Resource Compiler    (rc.exe     )
  87. *   Help Compiler        (ipfc.exe   )
  88. *
  89. *********************** END OF SPECIFICATIONS ********************************/
  90. #define INCL_DOS                       /* DosCall Definitions include     */
  91. #define INCL_PM                        /* Presentation Manager include    */
  92. #define INCL_WIN                       /* OS/2 2.x Win  include           */
  93. #define INCL_GPI                       /* OS/2 2.x Win  include           */
  94. #define INCL_OS2MM                     /* OS/2 2.x MM include             */
  95. #include <os2.h>                       /* OS/2 2.x System include         */
  96. #include <stdio.h>                     /* C Standard library include      */
  97. #include <stdlib.h>                    /* C Standard library include      */
  98. #include <string.h>                    /* C String Functions include      */
  99. #include <stdarg.h>                    /* C Standard Arguments include    */
  100. #include <os2me.h>                     /* Multimedia System include       */
  101. #include "mcispy.h"                    /* Component Private Definitions   */
  102.  
  103. MCISPY_BLOCK    SpyBlock;               /* SPY Application Data struct    */
  104. CHAR            szMainWin[]="MainWin";  /* Main window class title        */
  105. CHAR            szTitle[]="MultiMedia MCI Message Spy V1.0"; /* Application title */
  106. USHORT          cxChar,cyChar;          /* Character dimensions */
  107. extern          MCIMessageTable   MCIMsgTbl[];/* Table of MCI Messages     */
  108.  
  109. /****************************START OF SPECIFICATIONS *************************
  110. *
  111. * FUNCTION:    main
  112. *
  113. * ARGUMENTS:  argc, argv, envp.
  114. *
  115. * RETURN:     None.
  116. *
  117. * DESCRIPTION: MCISPY Application Main
  118. *
  119. * OS/2 API's USED:
  120. *
  121. *****************************END OF SPECIFICATIONS ***************************/
  122. INT main(LONG argc,PSZ argv[])
  123. {
  124.    static ULONG flCreate;      /* Window Creation Flags        */
  125.    APIRET rc;                  /* Return Code                  */
  126.  
  127.    /* initialize global variables */
  128.  
  129.    memset (&SpyBlock,0,sizeof(MCISPY_BLOCK));
  130.   /* clear the fontmetrics structure */
  131.    memset (&SpyBlock.fm,0,sizeof(FONTMETRICS));
  132.  
  133.  
  134.    sprintf (SpyBlock.szTitle,"%s",
  135.    "PID    DeviceID     MCI Message                 Flags       UserParm      Data");
  136.  
  137.    /* Intialize PM */
  138.    SpyBlock.hab = WinInitialize((USHORT) NULL);
  139.  
  140.    /* Create default size message queue */
  141.    SpyBlock.hmq = WinCreateMsgQueue(SpyBlock.hab,0);
  142.  
  143.    WinRegisterClass( SpyBlock.hab,szMainWin,
  144.                      (PFNWP) SpyWinProc,CS_SIZEREDRAW|CS_CLIPCHILDREN |
  145.                      CS_MOVENOTIFY | CS_PARENTCLIP,
  146.                      0 );
  147.    /* Set main window creation flags */
  148.  
  149.    flCreate = FCF_SIZEBORDER | FCF_MENU  | FCF_MINMAX |
  150.               FCF_SYSMENU | FCF_TITLEBAR | FCF_TASKLIST |
  151.               FCF_ICON;
  152.  
  153.    /* Create the main window */
  154.  
  155.    SpyBlock.hwnd1 = WinCreateStdWindow( HWND_DESKTOP, WS_VISIBLE, &flCreate,
  156.                                 szMainWin, szTitle, 0L, NULLHANDLE,
  157.                                 WND_FRM, (PHWND) & SpyBlock.hwndc1  );
  158.  
  159.    WinSetWindowPos( SpyBlock.hwnd1,
  160.                     HWND_TOP,
  161.                     100, 100, 500, 250,
  162.                     SWP_SIZE | SWP_MOVE | SWP_ACTIVATE | SWP_SHOW );
  163.  
  164.    if (!SpyBlock.hwnd1)
  165.     {
  166.        mprintf ("Main Window Creation Error");
  167.        DosExit (0,0);
  168.     }
  169.  
  170.    /* Initialize Global Data Structures and Register Spy */
  171.  
  172.     Initialize(&SpyBlock);
  173.     /* Message Loop */
  174.  
  175.     while ( WinGetMsg(SpyBlock.hab,(PQMSG) &SpyBlock.qmsg,(HWND) NULL,0,0))
  176.        WinDispatchMsg(SpyBlock.hab,(PQMSG) &SpyBlock.qmsg );
  177.  
  178.     Terminate (SpyBlock.hmq);  /* Terminate Application */
  179.     return(0);
  180. }  /* of main */
  181.  
  182.  
  183. /****************************START OF SPECIFICATIONS *************************
  184. *
  185. * FUNCTION: SpyWinProc()
  186. *
  187. * ARGUMENTS: Standard OS/2 PM Win Proc arguments
  188. *
  189. * RETURN:
  190. *
  191. * DESCRIPTION: This is the main window that interfaces with the user.
  192. * it routes user choices to various internal routines to perform
  193. * specific data streaming tasks.
  194. *
  195. * NOTES:
  196. *
  197. * SIDE EFFECTS:
  198. *
  199. *****************************END OF SPECIFICATIONS ***************************/
  200. MRESULT EXPENTRY SpyWinProc( HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
  201. {
  202.    RECTL           rectl,rectl1;      /* Client rectangles       */
  203.    int             i ;                /* loop index              */
  204.    APIRET          RetCode;           /* API return code         */
  205.    THREAD_BLOCK    *pNotPacket;       /* IPC Notification packet */
  206.    HWND            hwndFontDlg;       /* Font Dialog handle      */
  207.    POINTL          pt;                /* GPI static text x,y     */
  208.    BOOL            fReply ;           /* Internal Flag           */
  209.    BOOL            fFoundDevTyp ;     /* Internal Flag           */
  210.    BOOL            fGainorLose ;      /* Internal Flag           */
  211.    static HPS      hps;               /* Presentation Space      */
  212.    char            buffer[2048];      /* MLE buffer              */
  213.    char            buffer2[1024];      /* MSG buffer              */
  214.    static FONTDLG  FontDlg;           /* Font Dialog Structure   */
  215.    PCHAR           pchAlias;          /* String Alias            */
  216.    char            tokensep[]=" \t";  /* Token Seperators        */
  217.    SZ              szDevTyp[30];      /* Device Type             */
  218.    char            szSpace[11]= "    ";
  219.    char            szSpace2[50]="                                                ";
  220.  
  221.    switch( msg )
  222.      {
  223.      case WM_CONTROL:
  224.        if (SHORT2FROMMP(mp1) == MLN_TEXTOVERFLOW)
  225.         {
  226.            SpyBlock.ipt = 0;
  227.            WinSendMsg (SpyBlock.hwndMLE,MLM_DELETE,MPFROMLONG(SpyBlock.ipt),
  228.                        MPFROMLONG(65536));
  229.            return (MRESULT)(TRUE);
  230.         }
  231.        break;
  232.  
  233.      case WM_COMMAND:
  234.        switch ( SHORT1FROMMP( mp1 ) )
  235.          {
  236.          /* Recieved MCI Command through mciSendCommand() API.*/
  237.  
  238.          case SPY_NOTIFY:
  239.            /*
  240.            ** If Driver Notifications are disabled then just return
  241.            ** without writing it to MLE.
  242.            */
  243.            if (SpyBlock.fNoCmd)
  244.               break;
  245.  
  246.            /*
  247.            ** Obtain the Serialization Semaphore.
  248.            */
  249.            DosRequestMutexSem (SpyBlock.hmtxPrntSem, SEM_INDEFINITE_WAIT);
  250.  
  251.            /* Obtain the Shared Memory Packet */
  252.            GetSharedMemory(&SpyBlock);
  253.  
  254.            /* Display the MCI Message and other Info */
  255.            DisplayMCIMsg(&SpyBlock);
  256.  
  257.            /*
  258.            ** Give up the Serialization Semaphore.
  259.            */
  260.            DosReleaseMutexSem (SpyBlock.hmtxPrntSem);
  261.            return (FALSE);
  262.          break;
  263.  
  264.          /* Recieved String command through mciSendString() API.*/
  265.  
  266.          case SPY_STRING:
  267.            /*
  268.            ** If String Commands are disabled then just return
  269.            ** without writing it to MLE.
  270.            */
  271.            if (SpyBlock.fNoStr)
  272.               break;
  273.            /*
  274.            ** Obtain the Serialization Semaphore.
  275.            */
  276.            DosRequestMutexSem (SpyBlock.hmtxPrntSem, SEM_INDEFINITE_WAIT);
  277.  
  278.            /* Obtain the Shared Memory Packet */
  279.            GetSharedMemory (&SpyBlock);
  280.  
  281.            /* Derefence the packet to a local pointer */
  282.            pNotPacket = (THREAD_BLOCK *)SpyBlock.pvPacket;
  283.  
  284.            if (SpyBlock.fDevTypFil)
  285.             {
  286.                /* Update open instance information */
  287.  
  288.                SpyBlock.QueryOpenInstance ((OPEN_LIST *)&SpyBlock.OpenList,TRUE);
  289.  
  290.                strcpy (buffer,pNotPacket->szCmd);
  291.                pchAlias = strtok (buffer,tokensep);
  292.  
  293.                /* Second Token Should be the Alias on the string interface */
  294.  
  295.                pchAlias = strtok (NULL,tokensep);
  296.  
  297.                /* In order to implement device type filtering we maintain
  298.                ** a list of all open device ids and aliases together with
  299.                ** associated devices. We look at the device type for this
  300.                ** alias and compare it with the global device type filter
  301.                ** in effect. If they match then we know that this device
  302.                ** is on the filter list.
  303.                */
  304.                for (i=0; i < MAXOPENS; i++)
  305.                  {
  306.                     if (strcmpi (SpyBlock.OpenList.szAlias[i].szAlias,pchAlias) == 0)
  307.                      {
  308.                         strcpy (szDevTyp,SpyBlock.OpenList.szAlias[i].szDevTyp);
  309.                         fFoundDevTyp = TRUE;
  310.                        break;
  311.                      } /* Found Alias */
  312.                  } /* Num Open Devices */
  313.                if (fFoundDevTyp)
  314.                 {
  315.                    for (i=0; i < SpyBlock.usNumFilDevs; i++)
  316.                      {
  317.                         if (strnicmp(szDevTyp,SpyBlock.szDevTypFil[i],
  318.                                       strlen (SpyBlock.szDevTypFil[i])) == 0)
  319.                          {
  320.                            /*
  321.                            ** Give up the Serialization Semaphore.
  322.                            */
  323.                            DosReleaseMutexSem (SpyBlock.hmtxPrntSem);
  324.                            return (MRESULT)(0);
  325.                          } /* Device Type on Filter list */
  326.                      } /* Max Devices */
  327.                 } /* Found Device Type */
  328.             } /* Device Type Filter in Effect */
  329.  
  330.            if (SpyBlock.fDevIdFil)
  331.             {
  332.                /* Update open instance information */
  333.  
  334.                SpyBlock.QueryOpenInstance ((OPEN_LIST *)&SpyBlock.OpenList,FALSE);
  335.  
  336.                strcpy (buffer,pNotPacket->szCmd);
  337.  
  338.                pchAlias = strtok (buffer,tokensep);
  339.  
  340.                /* Second Token Should be the Alias on the string interface */
  341.  
  342.                pchAlias = strtok (NULL,tokensep);
  343.  
  344.                for (i=0; i < MAXOPENS; i++)
  345.                  {
  346.                     if (stricmp (SpyBlock.OpenList.szAlias[i].szAlias,pchAlias) == 0)
  347.                      {
  348.                        /* There may be Multiple Aliases Across different PIDs */
  349.  
  350.                        if (pNotPacket->ulPID == SpyBlock.OpenList.szAlias[i].ulPID)
  351.                         {
  352.                            if (SpyBlock.OpenList.szAlias[i].fExclude)
  353.                             {
  354.                               /*
  355.                               ** Give up the Serialization Semaphore.
  356.                               */
  357.                               DosReleaseMutexSem (SpyBlock.hmtxPrntSem);
  358.                               return (MRESULT)(0);
  359.                             } /* Exclude was on */
  360.                         } /* PIDs match on Alias */
  361.                      }  /* Found the Alias */
  362.                  } /* Number of Open Instances */
  363.             } /* Device Id Filter in Use */
  364.  
  365.            /* Format the String */
  366.            sprintf (buffer,  "%03d %s %s %s %04d\n", pNotPacket->ulPID, szSpace,
  367.                               (char *)pNotPacket->szCmd,szSpace,pNotPacket->wUserParm);
  368.            /* Write to MLE */
  369.  
  370.           WinSendMsg (SpyBlock.hwndMLE,MLM_SETSEL,MPFROMLONG(SpyBlock.ipt),
  371.                       MPFROMLONG(SpyBlock.ipt));
  372.  
  373.           WinSendMsg (SpyBlock.hwndMLE,MLM_INSERT,MPFROMLONG(buffer),
  374.                      (MPARAM)0);
  375.  
  376.           SpyBlock.ipt= (IPT)WinSendMsg (SpyBlock.hwndMLE,MLM_QUERYSEL,MPFROMSHORT(MLFQS_CURSORSEL),
  377.                                          0L);
  378.           if (SpyBlock.fNoLog)
  379.               Write2File (SpyBlock.hfileLog,buffer);
  380.  
  381.            /*
  382.            ** Give up the Serialization Semaphore.
  383.            */
  384.            DosReleaseMutexSem (SpyBlock.hmtxPrntSem);
  385.            return (FALSE);
  386.          break;
  387.  
  388.           /*
  389.           ** Recieved Device Notifications through our Input hook.
  390.           */
  391.          case SPY_DEVICE:
  392.            /*
  393.            ** Obtain the Serialization Semaphore.
  394.            */
  395.            DosRequestMutexSem (SpyBlock.hmtxPrntSem, SEM_INDEFINITE_WAIT);
  396.  
  397.            if (MCIMsgTbl[56].fExclude)
  398.             {
  399.                /*
  400.                ** Give up the Print Semaphore
  401.                */
  402.                DosReleaseMutexSem (SpyBlock.hmtxPrntSem);
  403.                return ;
  404.             }
  405.            /* Obtain the Shared Memory Packet */
  406.  
  407.            GetSharedMemory (&SpyBlock);
  408.  
  409.            pNotPacket = (THREAD_BLOCK *)SpyBlock.pvPacket;
  410.  
  411.            strcpy (buffer2,"  MM_MCIPASSDEVICE");
  412.            if (pNotPacket->dwParam2 == MCI_LOSING_USE)
  413.             {
  414.                strcat (buffer2,"  Losing Use");
  415.                fGainorLose = TRUE;
  416.             }
  417.            else
  418.             {
  419.               strcat (buffer2,"  Gaining Use");
  420.               fGainorLose = TRUE;
  421.             }
  422.            if (fGainorLose)
  423.             {
  424.                sprintf (buffer,"%03d %s %02d %s %s\n",pNotPacket->ulPID,szSpace,
  425.                                pNotPacket->wDevID,szSpace, buffer2);
  426.                WinSendMsg (SpyBlock.hwndMLE,MLM_SETSEL,MPFROMLONG(SpyBlock.ipt),
  427.                           MPFROMLONG(SpyBlock.ipt));
  428.  
  429.                WinSendMsg (SpyBlock.hwndMLE,MLM_INSERT,MPFROMLONG(buffer),
  430.                          (MPARAM)0);
  431.  
  432.                SpyBlock.ipt= (IPT)WinSendMsg (SpyBlock.hwndMLE,MLM_QUERYSEL,MPFROMSHORT(MLFQS_CURSORSEL),
  433.                                              0L);
  434.             }
  435.            /*
  436.            ** Give up the Print Semaphore
  437.            */
  438.            DosReleaseMutexSem (SpyBlock.hmtxPrntSem);
  439.  
  440.            return (MRESULT)(FALSE);
  441.          break;
  442.  
  443.          /* Recieved an Error Notification.*/
  444.          case SPY_ERRRC:
  445.            DosRequestMutexSem (SpyBlock.hmtxPrntSem, SEM_INDEFINITE_WAIT);
  446.            GetSharedMemory (&SpyBlock);
  447.            pNotPacket = (THREAD_BLOCK *)SpyBlock.pvPacket;
  448.            sprintf (buffer,  "%03d %s %02d %s %s  %s %04d\n",pNotPacket->ulPID,szSpace,
  449.                     pNotPacket->wDevID,szSpace,"Error: Return Code = ",szSpace,
  450.                     pNotPacket->ulReturnCode);
  451.  
  452.            WinSendMsg (SpyBlock.hwndMLE,MLM_SETSEL,MPFROMLONG(SpyBlock.ipt),
  453.                       MPFROMLONG(SpyBlock.ipt));
  454.  
  455.            WinSendMsg (SpyBlock.hwndMLE,MLM_INSERT,MPFROMLONG(buffer),
  456.                        (MPARAM)0);
  457.  
  458.            SpyBlock.ipt= (IPT)WinSendMsg (SpyBlock.hwndMLE,MLM_QUERYSEL,MPFROMSHORT(MLFQS_CURSORSEL),
  459.                                          0L);
  460.  
  461.           if (SpyBlock.fNoLog)
  462.               Write2File (SpyBlock.hfileLog,buffer);
  463.  
  464.            /*
  465.            ** Give up the Print Semaphore
  466.            */
  467.            DosReleaseMutexSem (SpyBlock.hmtxPrntSem);
  468.            return (FALSE);
  469.          break;
  470.          /* File open */
  471.          case IDM_OPEN:
  472.            RetCode = OpenFileDlg (hwnd,"MCISPY: Open Log File",
  473.                                  SpyBlock.szLogFile,"*.LOG");
  474.  
  475.            /* Close the Default LogFile */
  476.            DosClose (SpyBlock.hfileLog);
  477.  
  478.            OpenFile (SpyBlock.szLogFile,&SpyBlock.hfileLog);
  479.          break;
  480.  
  481.          /* Enable Logging (Toggle) */
  482.  
  483.          case IDM_LOG:
  484.            fReply = (BOOL)WinSendMsg(WinWindowFromID(
  485.                       WinQueryWindow(hwnd,QW_PARENT),
  486.                       FID_MENU),
  487.                       MM_QUERYITEMATTR,
  488.                       MPFROM2SHORT(IDM_LOG,TRUE), /* item to check */
  489.                       MPFROMLONG(MIA_CHECKED) );
  490.  
  491.            if (fReply)
  492.             {
  493.                /* Uncheck the item */
  494.                WinSendMsg(WinWindowFromID(
  495.                           WinQueryWindow(hwnd,QW_PARENT),
  496.                           FID_MENU),
  497.                           MM_SETITEMATTR,
  498.                           MPFROM2SHORT(IDM_LOG,TRUE), /* item to uncheck */
  499.                           MPFROM2SHORT(MIA_CHECKED,0) );
  500.  
  501.                SpyBlock.fNoLog = FALSE;
  502.             }
  503.             else
  504.             {
  505.                WinSendMsg(WinWindowFromID(
  506.                           WinQueryWindow(hwnd,QW_PARENT),
  507.                           FID_MENU),
  508.                           MM_SETITEMATTR,
  509.                           MPFROM2SHORT(IDM_LOG,TRUE), /* item to check */
  510.                           MPFROM2SHORT(MIA_CHECKED,MIA_CHECKED) );
  511.  
  512.                SpyBlock.fNoLog = TRUE;
  513.             }
  514.          break;
  515.  
  516.          /* Enable System Sounds (Toggle) */
  517.  
  518.          case IDM_NOSYS:
  519.            fReply = (BOOL)WinSendMsg(WinWindowFromID(
  520.                       WinQueryWindow(hwnd,QW_PARENT),
  521.                       FID_MENU),
  522.                       MM_QUERYITEMATTR,
  523.                       MPFROM2SHORT(IDM_NOSYS,TRUE), /* item to check */
  524.                       MPFROMLONG(MIA_CHECKED) );
  525.  
  526.            if (fReply)
  527.             {
  528.                /* Uncheck the item */
  529.                WinSendMsg(WinWindowFromID(
  530.                           WinQueryWindow(hwnd,QW_PARENT),
  531.                           FID_MENU),
  532.                           MM_SETITEMATTR,
  533.                           MPFROM2SHORT(IDM_NOSYS,TRUE), /* item to uncheck */
  534.                           MPFROM2SHORT(MIA_CHECKED,0) );
  535.  
  536.                SpyBlock.SystemSounds(TRUE);
  537.  
  538.             }
  539.             else
  540.             {
  541.                WinSendMsg(WinWindowFromID(
  542.                           WinQueryWindow(hwnd,QW_PARENT),
  543.                           FID_MENU),
  544.                           MM_SETITEMATTR,
  545.                           MPFROM2SHORT(IDM_NOSYS,TRUE), /* item to check */
  546.                           MPFROM2SHORT(MIA_CHECKED,MIA_CHECKED) );
  547.  
  548.                SpyBlock.SystemSounds(FALSE);
  549.  
  550.             }
  551.          break;
  552.  
  553.          /* Clear MLE Contents    */
  554.  
  555.          case IDM_EDCLEAR:
  556.            SpyBlock.ipt = 0;
  557.            WinSendMsg (SpyBlock.hwndMLE,MLM_DELETE,MPFROMLONG(SpyBlock.ipt),
  558.                        MPFROMLONG(65536));
  559.          break;
  560.  
  561.          /* Copy MLE contents to clipboard */
  562.  
  563.          case IDM_EDCOPY:
  564.            CopyMLE (SpyBlock.hwndMLE);
  565.          break;
  566.  
  567.         /* Discard MLE Selected Text */
  568.  
  569.          case IDM_EDDISCARD:
  570.            WinSendMsg (SpyBlock.hwndMLE,MLM_CLEAR,MPFROMLONG(0),
  571.                        MPFROMLONG(0));
  572.  
  573.          break;
  574.  
  575.          /* Set MLE Font   */
  576.  
  577.          case IDM_EDFONT:
  578.            memset (&FontDlg,0,sizeof(FONTDLG));
  579.            memset (buffer,0,sizeof(buffer));
  580.            FontDlg.cbSize = sizeof(FONTDLG);
  581.            FontDlg.hpsScreen = WinGetScreenPS(HWND_DESKTOP);
  582.            strcpy (buffer,"10.System Monospaced");
  583.  
  584.            /* Initialize The FontDlg members */
  585.  
  586.            FontDlg.pszFamilyname = buffer;
  587.            FontDlg.usFamilyBufLen = FACESIZE;
  588.            FontDlg.fl = FNTS_CENTER | FNTS_INITFROMFATTRS;
  589.            FontDlg.clrFore = CLR_BLACK;
  590.            FontDlg.clrBack = CLR_WHITE;
  591.            FontDlg.fAttrs.usRecordLength = sizeof(FATTRS);
  592.            FontDlg.fAttrs.lMatch = 3;
  593.            FontDlg.fAttrs.fsSelection = FM_SEL_OUTLINE;
  594.            FontDlg.fAttrs.lMaxBaselineExt = 20;
  595.            FontDlg.fAttrs.lAveCharWidth=9;
  596.            FontDlg.fAttrs.fsFontUse=2;
  597.            hwndFontDlg = WinFontDlg (HWND_DESKTOP,hwnd,(PFONTDLG)&FontDlg);
  598.            if ((hwndFontDlg) && (FontDlg.lReturn == DID_OK))
  599.             {
  600.                WinSendMsg (SpyBlock.hwndMLE,MLM_SETFONT,MPFROMP((PFATTRS)&FontDlg.fAttrs),
  601.                            MPFROMSHORT(0));
  602.             }
  603.          break;
  604.  
  605.          /* View Installed Multimedia Devices */
  606.          case IDM_IDEVS:
  607.            /* Query Multimedia Devices installed in system */
  608.            QueryInstalledDevices (&SpyBlock);
  609.  
  610.            WinDlgBox ( HWND_DESKTOP, hwnd,(PFNWP) ViewInstDevDlgProc, NULLHANDLE,
  611.                        ID_DEVNAMESDLG, NULL );
  612.  
  613.          break;
  614.  
  615.          /* Filter by MCI messages */
  616.  
  617.          case IDM_FILMSG:
  618.            WinDlgBox (HWND_DESKTOP,hwnd,(PFNWP) FilterMsgDlgProc,NULLHANDLE,
  619.                        ID_FILTERMSG, NULL );
  620.          break;
  621.  
  622.          /* Filter by Open Device Ids */
  623.  
  624.          case IDM_FILDEVID:
  625.            if (SpyBlock.QueryOpenInstance == NULL)
  626.             {
  627.               mprintf ("Null QueryOpenInstance Pointer \n");
  628.               break;
  629.             }
  630.  
  631.            /* Query Open Instance information */
  632.            SpyBlock.QueryOpenInstance ((OPEN_LIST *)&SpyBlock.OpenList,TRUE);
  633.            SpyBlock.QueryOpenInstance ((OPEN_LIST *)&SpyBlock.OpenList,FALSE);
  634.  
  635.            if (SpyBlock.OpenList.ulNumOpen == 0)
  636.             {
  637.               mprintf ("No Open Multimedia Instances Detected \n");
  638.               break;
  639.             }
  640.            WinDlgBox (HWND_DESKTOP, hwnd,(PFNWP) FilterDevIdDlgProc, NULLHANDLE,
  641.                        ID_FILTERDEVIDS, NULL );
  642.          break;
  643.  
  644.          /* Filter by Device Types  */
  645.  
  646.          case IDM_FILDEVTYP:
  647.            /* Query Open Instance information */
  648.            SpyBlock.QueryOpenInstance ((OPEN_LIST *)&SpyBlock.OpenList,TRUE);
  649.            SpyBlock.QueryOpenInstance ((OPEN_LIST *)&SpyBlock.OpenList,FALSE);
  650.            WinDlgBox ( HWND_DESKTOP, hwnd,(PFNWP) FilterDevTypDlgProc, NULLHANDLE,
  651.                        ID_FILTERDEVTYP, NULL );
  652.          break;
  653.  
  654.          /* View MCI Flags */
  655.  
  656.          case IDM_FLAGS:
  657.            WinDlgBox ( HWND_DESKTOP, hwnd,(PFNWP) ShowFlagDlgProc, NULLHANDLE,
  658.                        ID_FLAGSDLG, NULL );
  659.          break;
  660.  
  661.          /* Disable mciSendString() Interface */
  662.  
  663.          case IDM_NOSTR:
  664.            fReply = (BOOL)WinSendMsg(WinWindowFromID(
  665.                       WinQueryWindow(hwnd,QW_PARENT),
  666.                       FID_MENU),
  667.                       MM_QUERYITEMATTR,
  668.                       MPFROM2SHORT(IDM_NOSTR,TRUE), /* item to check */
  669.                       MPFROMLONG(MIA_CHECKED) );
  670.  
  671.            if (fReply)
  672.             {
  673.                /* Uncheck the item */
  674.                WinSendMsg(WinWindowFromID(
  675.                           WinQueryWindow(hwnd,QW_PARENT),
  676.                           FID_MENU),
  677.                           MM_SETITEMATTR,
  678.                           MPFROM2SHORT(IDM_NOSTR,TRUE), /* item to uncheck */
  679.                           MPFROM2SHORT(MIA_CHECKED,0) );
  680.  
  681.                SpyBlock.fNoStr = FALSE;
  682.             }
  683.             else
  684.             {
  685.                WinSendMsg(WinWindowFromID(
  686.                           WinQueryWindow(hwnd,QW_PARENT),
  687.                           FID_MENU),
  688.                           MM_SETITEMATTR,
  689.                           MPFROM2SHORT(IDM_NOSTR,TRUE), /* item to check */
  690.                           MPFROM2SHORT(MIA_CHECKED,MIA_CHECKED) );
  691.  
  692.                SpyBlock.fNoStr = TRUE;
  693.             }
  694.          break;
  695.  
  696.          /* Disable mciSendCommand() Interface */
  697.  
  698.          case IDM_NOCMD:
  699.  
  700.            fReply = (BOOL)WinSendMsg(WinWindowFromID(
  701.                       WinQueryWindow(hwnd,QW_PARENT),
  702.                       FID_MENU),
  703.                       MM_QUERYITEMATTR,
  704.                       MPFROM2SHORT(IDM_NOCMD,TRUE), /* item to check */
  705.                       MPFROMLONG(MIA_CHECKED) );
  706.  
  707.            if (fReply)
  708.             {
  709.                /* Uncheck the item */
  710.                WinSendMsg(WinWindowFromID(
  711.                           WinQueryWindow(hwnd,QW_PARENT),
  712.                           FID_MENU),
  713.                           MM_SETITEMATTR,
  714.                           MPFROM2SHORT(IDM_NOCMD,TRUE), /* item to uncheck */
  715.                           MPFROM2SHORT(MIA_CHECKED,0) );
  716.  
  717.                SpyBlock.fNoCmd = FALSE;
  718.             }
  719.             else
  720.             {
  721.                WinSendMsg(WinWindowFromID(
  722.                           WinQueryWindow(hwnd,QW_PARENT),
  723.                           FID_MENU),
  724.                           MM_SETITEMATTR,
  725.                           MPFROM2SHORT(IDM_NOCMD,TRUE), /* item to check */
  726.                           MPFROM2SHORT(MIA_CHECKED,MIA_CHECKED) );
  727.  
  728.                SpyBlock.fNoCmd = TRUE;
  729.             }
  730.  
  731.          break;
  732.  
  733.          case IDM_HELP_INDEX:
  734.            if ( SpyBlock.hwndHelpInstance )
  735.              WinSendMsg(SpyBlock.hwndHelpInstance, HM_HELP_INDEX, MPVOID, MPVOID);
  736.          break;
  737.  
  738.          case IDM_HELP_GEN:
  739.            if ( SpyBlock.hwndHelpInstance )
  740.                WinSendMsg (SpyBlock.hwndHelpInstance,HM_DISPLAY_HELP,
  741.                            MPFROM2SHORT(GENHLP, NULL),
  742.                            MPFROMSHORT(HM_RESOURCEID));
  743.  
  744.          break;
  745.  
  746.          case IDM_HELP_KEYS:
  747.            if ( SpyBlock.hwndHelpInstance )
  748.                WinSendMsg (SpyBlock.hwndHelpInstance,HM_DISPLAY_HELP,
  749.                            MPFROM2SHORT(KEYSHELP, NULL),
  750.                            MPFROMSHORT(HM_RESOURCEID));
  751.          break;
  752.  
  753.          case IDM_HELP_USING:
  754.            if ( SpyBlock.hwndHelpInstance )
  755.              WinSendMsg(SpyBlock.hwndHelpInstance, HM_DISPLAY_HELP, MPVOID, MPVOID);
  756.          break;
  757.  
  758.          case IDM_HELP_PRODINFO:
  759.            WinDlgBox ( HWND_DESKTOP, hwnd,(PFNWP) AboutDlgProc, NULLHANDLE,
  760.                        IDM_PRODUCTINFO, NULL );
  761.          break;
  762.  
  763.          } /* WM_COMMAND */
  764.         break;
  765.      case WM_HELP:
  766.        if ( SpyBlock.hwndHelpInstance )
  767.            WinSendMsg (SpyBlock.hwndHelpInstance,HM_DISPLAY_HELP,
  768.                        MPFROM2SHORT(STDHLP, NULL),
  769.                        MPFROMSHORT(HM_RESOURCEID));
  770.  
  771.          return (MRESULT)0;
  772.        break;
  773.  
  774.      case WM_CLOSE:
  775.        /******************************************************************/
  776.        /* This is the place to put your termination routines             */
  777.        /******************************************************************/
  778.        WinPostMsg( hwnd, WM_QUIT, 0L, 0L );  /* Cause termination        */
  779.        break;
  780.  
  781.      case WM_CREATE:
  782.        WinQueryWindowRect (hwnd, &rectl);
  783.  
  784.         /* Get Character dimensions */
  785.        SpyBlock.hps = WinGetPS (hwnd);
  786.        GpiQueryFontMetrics (SpyBlock.hps,(LONG)sizeof(SpyBlock.fm),&SpyBlock.fm);
  787.  
  788.        /* Get Character dimensions   */
  789.  
  790.        cxChar = (SHORT)SpyBlock.fm.lAveCharWidth;
  791.        cyChar = (SHORT)SpyBlock.fm.lMaxBaselineExt;
  792.  
  793.        /*
  794.        ** Create the MLE and set it up as a
  795.        ** client of the main window
  796.        */
  797.        SpyBlock.hwndMLE = WinCreateWindow( hwnd, WC_MLE, "",
  798.                                     WS_VISIBLE | MLS_BORDER | MLS_VSCROLL |
  799.                                     MLS_HSCROLL| MLS_READONLY,
  800.                                     0, 0,
  801.                                     (SHORT)rectl.xRight,
  802.                                     (SHORT)rectl.yTop - 30 ,
  803.                                     hwnd, HWND_BOTTOM, FID_CLIENT, 0L, NULL );
  804.  
  805.        /* Set the default font to system monospaced */
  806.  
  807.        strcpy (buffer2,"10.System Monospaced");
  808.  
  809.        /* Client MLE Font */
  810.        WinSetPresParam(SpyBlock.hwndMLE,PP_FONTNAMESIZE,
  811.                        (strlen(buffer2)+(ULONG)1),
  812.                        (PSZ) buffer2);
  813.  
  814.        /* main Window Font */
  815.        WinSetPresParam(hwnd,PP_FONTNAMESIZE,
  816.                        (strlen(buffer2)+(ULONG)1),
  817.                        (PSZ) buffer2);
  818.  
  819.        /* Create Print Active Information mutual exclusion semaphore */
  820.  
  821.        DosCreateMutexSem (NULL,(PHEV) &SpyBlock.hmtxPrntSem,DC_SEM_SHARED,
  822.                          FALSE);
  823.        /*
  824.        ** Set up MLE import export transaction format
  825.        */
  826.        SetMLEFormat(SpyBlock.hwndMLE);
  827.         break;
  828.  
  829.      case WM_SIZE:
  830.  
  831.        WinQueryWindowRect ( hwnd, &rectl );
  832.  
  833.       /* Set the window position  of the frames making them visible */
  834.  
  835.        WinSetWindowPos(SpyBlock.hwndMLE, HWND_TOP,(SHORT)0, (SHORT)0,
  836.                        (SHORT)rectl.xRight, (SHORT)rectl.yTop - 30 ,
  837.                        SWP_MOVE|SWP_SIZE | SWP_ACTIVATE |SWP_SHOW );
  838.  
  839.         break;
  840.  
  841.      case WM_PAINT:
  842.        hps = WinBeginPaint( hwnd, (HPS) NULL, (PRECTL) &rectl );
  843.        WinFillRect( hps, (PRECTL) &rectl, SYSCLR_WINDOW );
  844.        WinQueryWindowRect (hwnd, &rectl1);
  845.        pt .x = rectl1.xLeft;
  846.        pt.y =  (rectl1.yTop - cyChar);
  847.        /* Set color of the text */
  848.        GpiSetColor( hps, CLR_BLUE );
  849.        /* Format the Title columns */
  850.        GpiCharStringAt(hps, &pt, strlen(SpyBlock.szTitle)+1, SpyBlock.szTitle);
  851.        WinEndPaint( hps );
  852.         break;
  853.  
  854.      default:
  855.         return(WinDefWindowProc(hwnd,msg,mp1,mp2));
  856.      }
  857.   return(FALSE);
  858. }
  859.  
  860.  
  861.  
  862.  
  863.