home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / fpdemo.zip / FPDEMO.C < prev    next >
Text File  |  1993-11-22  |  28KB  |  725 lines

  1. #define INCL_WIN
  2. #define INCL_GPI
  3. #define INCL_DOSPROCESS
  4.  
  5. #include <stdio.h>
  6. #include <os2.h>                        /* PM header file               */
  7. #include "footprnt.h"                   /* Resource symbolic identifiers*/
  8. #include "fpdemo.h"                     /* Dialog box symbolic ids      */
  9.  
  10. #define STRINGLENGTH 64                 /* Length of string             */
  11.  
  12. /*
  13.  * Function prototypes
  14.  */
  15. MRESULT EXPENTRY MyWindowProc( HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2 );
  16. MRESULT EXPENTRY DlgAboutProc( HWND hwnd, ULONG ulMsg, MPARAM mp1, MPARAM mp2 );
  17. MRESULT EXPENTRY DlgWelcomeProc( HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2 );
  18. MRESULT EXPENTRY DlgIsUpProc( HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2 );
  19. MRESULT EXPENTRY DlgMonitorProc( HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2 );
  20. MRESULT EXPENTRY DlgTraceProc( HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2 );
  21. MRESULT EXPENTRY DlgIsItOnProc( HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2 );
  22. MRESULT EXPENTRY DlgBit1Proc( HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2 );
  23. MRESULT EXPENTRY DlgBit2Proc( HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2 );
  24. MRESULT EXPENTRY DlgBit3Proc( HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2 );
  25. MRESULT EXPENTRY DlgNoneProc( HWND hwnd, ULONG ulMsg, MPARAM mp1, MPARAM mp2 );
  26. VOID APIENTRY HSSExit( VOID );
  27. VOID HandleError( char *szErrorMsg );
  28.                                         /* Define parameters by type    */
  29. HAB  hab;                               /* PM anchor block handle       */
  30. PSZ  pszErrMsg;
  31. /*----------------------------------------------------------------
  32.      This is the Footprints Handle.  It is global because all
  33.      modules use this when they make any Footprints calls
  34.  ----------------------------------------------------------------*/
  35. HFPHANDLE hfpFPHandle;
  36.  
  37. /**************************************************************************
  38.  *
  39.  *  Name       : main()
  40.  *
  41.  *  Description: Initializes the process for OS/2 PM services and
  42.  *               process the application message queue until a
  43.  *               WM_QUIT message is received.  It then destroys all
  44.  *               OS/2 PM resources and terminates.
  45.  *
  46.  *  Concepts   : - obtains anchor block handle and creates message
  47.  *                   queue
  48.  *               - creates the main frame window which creates the
  49.  *                   main client window
  50.  *               - polls the message queue via Get/Dispatch Msg loop
  51.  *               - upon exiting the loop, exits
  52.  *
  53.  *  API's      :   WinInitialize
  54.  *                 WinCreateMsgQueue
  55.  *                 WinTerminate
  56.  *                 WinSetWindowPos
  57.  *                 WinSetWindowText
  58.  *                 WinRegisterClass
  59.  *                 WinCreateStdWindow
  60.  *                 WinGetMsg
  61.  *                 WinDispatchMsg
  62.  *                 WinDestroyWindow
  63.  *                 WinDestroyMsgQueue
  64.  *
  65.  *  Parameters :  [none]
  66.  *
  67.  *  Return     :  1 - if successful execution completed
  68.  *                0 - if error
  69.  *
  70.  *************************************************************************/
  71. INT main (VOID)
  72. {
  73.   HMQ  hmq;                             /* Message queue handle         */
  74.   HWND hwndClient = NULLHANDLE;         /* Client area window handle    */
  75.   HWND hwndFrame = NULLHANDLE;          /* Frame window handle          */
  76.   QMSG qmsg;                            /* Message from message queue   */
  77.   ULONG flCreate;                       /* Window creation control flags*/
  78.   ULONG ulRC;
  79.   APIRET dosRC;
  80.   FILE *fp;
  81.  
  82.   /*---------------------------
  83.        Initialize Footprints
  84.    ---------------------------*/
  85.   /*+-----------------------------------------------------------------------+
  86.     | The first argument is the process id "Demo".  This name will appear   |
  87.     | in the FP.EXE window as the process name once the demo program is     |
  88.     | started.  The second argument is the address of a Footprints handle.  |
  89.     | This must be passed to any Footprints call made from this program.  It|
  90.     | is this handle that Footprints uses to know what process is calling   |
  91.     | it.                                                                   |
  92.     +-----------------------------------------------------------------------+*/
  93.   if( ulRC = HfpInit( "Demo", &hfpFPHandle )) 
  94.   {
  95.      DosBeep( 600L, 200L );
  96.      fp = fopen( "fpdemo.err", "w" );
  97.      if (fp != NULL ) 
  98.      {
  99.         fprintf( fp, "Initialization error = %d\n", ulRC );
  100.         fclose( fp );
  101.      }
  102.      return( 1 );
  103.   }
  104.   /*-----------------------------------------------------------------------
  105.       Register Exit list - This is a must with Footprints, since in the
  106.       event of a trap, you lose all your traced data - unless you use
  107.       this.  Since a trap is precisely when you want to view your
  108.       Footprints data, it is stupid not to use the Exit list.
  109.   -----------------------------------------------------------------------*/
  110.   if( dosRC = DosExitList( 1, (PFNEXITLIST)HSSExit ))
  111.   {
  112.      HfpTrace( hfpFPHandle, &dosRC, sizeof(dosRC), "Exitlist", 0 );
  113.      HSSExit();
  114.      return( 1 );
  115.   }
  116.   if ((hab = WinInitialize(0)) == 0L) /* Initialize PM     */
  117.   {
  118.      HandleError( "WinInit" );
  119.      DosExit( EXIT_PROCESS, 0 );
  120.   }
  121.  
  122.   if ((hmq = WinCreateMsgQueue( hab, 0 )) == 0L)/* Create a msg queue */
  123.   {
  124.      HandleError( "WinCMsgQ" );
  125.      DosExit( EXIT_PROCESS, 0 );
  126.   }
  127.  
  128.   if (!WinRegisterClass(                /* Register window class        */
  129.      hab,                               /* Anchor block handle          */
  130.      (PSZ)"MyWindow",                   /* Window class name            */
  131.      (PFNWP)MyWindowProc,               /* Address of window procedure  */
  132.      CS_SIZEREDRAW,                     /* Class style                  */
  133.      0                                  /* No extra window words        */
  134.      ))
  135.   {
  136.      HandleError( "WinRegCl" );
  137.      DosExit( EXIT_PROCESS, 0 );
  138.   }
  139.  
  140.    flCreate = FCF_STANDARD &            /* Set frame control flags to   */
  141.              ~FCF_SHELLPOSITION;        /* standard except for shell    */
  142.                                         /* positioning.                 */
  143.  
  144.   if ((hwndFrame = WinCreateStdWindow(
  145.                HWND_DESKTOP,            /* Desktop window is parent     */
  146.                0,                       /* STD. window styles           */
  147.                &flCreate,               /* Frame control flag           */
  148.                "MyWindow",              /* Client window class name     */
  149.                "",                      /* No window text               */
  150.                0,                       /* No special class style       */
  151.                (HMODULE)0L,             /* Resource is in .EXE file     */
  152.                ID_WINDOW,               /* Frame window identifier      */
  153.                &hwndClient              /* Client window handle         */
  154.                )) == 0L)
  155.   {
  156.      HandleError( "WinCrWin" );
  157.      DosExit( EXIT_PROCESS, 0 );
  158.   }
  159.  
  160.   WinSetWindowText(hwndFrame, "Footprints Demonstration");
  161.  
  162.   if (!WinSetWindowPos( hwndFrame,      /* Shows and activates frame    */
  163.                    HWND_TOP,            /* window at position 100, 100, */
  164.                    100, 100, 400, 300,  /* and size 400, 300.           */
  165.                    SWP_SIZE | SWP_MOVE | SWP_ACTIVATE | SWP_SHOW
  166.                  ))
  167.   {
  168.      HandleError( "WiSetPos" );
  169.      DosExit( EXIT_PROCESS, 0 );
  170.   }
  171.  
  172. /*---------------------------------------------------------------
  173.    Get and dispatch messages from the application message queue
  174.    until WinGetMsg returns FALSE, indicating a WM_QUIT message.
  175.  ---------------------------------------------------------------*/
  176.  
  177.   while( WinGetMsg( hab, &qmsg, 0L, 0, 0 ) )
  178.     WinDispatchMsg( hab, &qmsg );
  179.  
  180.   WinDestroyWindow(hwndFrame);           /* Tidy up...                   */
  181.   WinDestroyMsgQueue( hmq );             /* Tidy up...                   */
  182.   WinTerminate( hab );                   /* Terminate the application    */
  183.   DosExit( EXIT_PROCESS, 0 );
  184. } /* End of main */
  185.  
  186. /**************************************************************************
  187.  *
  188.  *  Name       : MyWindowProc
  189.  *
  190.  *  Description: The window procedure associated with the client area in
  191.  *               the standard frame window. It processes all messages
  192.  *               either sent or posted to the client area, depending on
  193.  *               the message command and parameters.
  194.  *
  195.  *
  196.  *  API's      :   WinLoadString
  197.  *                 WinInvalidateRegion
  198.  *                 WinPostMsg
  199.  *                 WinDefWindowProc
  200.  *                 WinBeginPaint
  201.  *                 GpiSetColor
  202.  *                 GpiSetBackColor
  203.  *                 GpiSetBackMix
  204.  *                 GpiCharStringAt
  205.  *                 WinEndPaint
  206.  *
  207.  *  Parameters :  hwnd = window handle
  208.  *                msg = message code
  209.  *                mp1 = first message parameter
  210.  *                mp2 = second message parameter
  211.  *
  212.  *  Return     :  depends on message sent
  213.  *
  214.  *************************************************************************/
  215. MRESULT EXPENTRY MyWindowProc( HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2 )
  216. {
  217.   ULONG   ulRC;
  218.   HPS     hps;                       /* Presentation Space handle    */
  219.   HBITMAP hbm;
  220.   POINTL  ptl;
  221.   static SHORT cxClient, cyClient;
  222.  
  223.   switch( msg )
  224.   {
  225.     case WM_COMMAND:
  226.       {
  227.       USHORT command;                   /* WM_COMMAND command value     */
  228.  
  229.       command = SHORT1FROMMP(mp1);      /* Extract the command value    */
  230.       switch (command)
  231.       {
  232.         case ID_BEGIN:
  233.           if( (ulRC = WinDlgBox( HWND_DESKTOP, hwnd, DlgWelcomeProc, 0L,
  234.                      (ULONG)DLG_WELCOME, NULL)) == DID_ERROR )
  235.           {
  236.            ulRC = WinGetLastError( hab );
  237.            /*+-----------------------------------------------------------+
  238.              | Here is a call to HfpTrace - the arguments in order are:  |
  239.              | hfpFPHandle - Footprints handle for this process          |
  240.              | &ulRC       - The data we are tracing (by address)        |
  241.              | sizeof(ulRC)- Trace 4 bytes of data                       |
  242.              | "DlgBxEr1"  - The label for this trace.  It is unique so  |
  243.              |               when I look at the realtime monitor or the  |
  244.              |               trace file, I will know where this trace    |
  245.              |               was generated, and what it represents       |
  246.              | 0           - The trace id number.  ID zero is always "on"|
  247.              |               This is best used to trace error conditions |
  248.              |               because you don't have to turn on any trace |
  249.              |               bits from the FP.EXE user interface.        |
  250.              |               i.e., this message will always be traced    |
  251.              +-----------------------------------------------------------+*/
  252.            HfpTrace( hfpFPHandle, &ulRC, sizeof(ulRC), "DlgBxEr1", 0 );
  253.           }
  254.           else if( ulRC == BID_OK ) /* user hit OK button */
  255.           {
  256.            if((ulRC = WinDlgBox( HWND_DESKTOP, hwnd, DlgIsUpProc, 0L,
  257.                              (ULONG)DLG_IS_UP, NULL)) == DID_ERROR )
  258.            {
  259.             ulRC = WinGetLastError( hab );
  260.             HfpTrace( hfpFPHandle, &ulRC, sizeof(ulRC), "DlgBxEr2", 0 );
  261.            }
  262.            else if( ulRC == BID_OK ) /* user hit OK button */
  263.            {
  264.             if((ulRC = WinDlgBox( HWND_DESKTOP, hwnd, DlgMonitorProc, 0L,
  265.                               (ULONG)DLG_MONITOR, NULL)) == DID_ERROR )
  266.             {
  267.              ulRC = WinGetLastError( hab );
  268.              HfpTrace( hfpFPHandle, &ulRC, sizeof(ulRC), "DlgBxEr3", 0 );
  269.             }
  270.             else if( ulRC == BID_OK ) /* user hit OK button */
  271.             {
  272.              if((ulRC = WinDlgBox( HWND_DESKTOP, hwnd, DlgTraceProc, 0L,
  273.                                   (ULONG)DLG_TRACE, NULL)) == DID_ERROR )
  274.              {
  275.               ulRC = WinGetLastError( hab );
  276.               HfpTrace( hfpFPHandle, &ulRC, sizeof(ulRC), "DlgBxEr4", 0 );
  277.              }
  278.             }
  279.            }
  280.           }
  281.           break;
  282.         case ID_EXITPROG:
  283.           WinPostMsg( hwnd, WM_QUIT, (MPARAM)0,(MPARAM)0 );/* Cause termination*/
  284.           break;
  285.         case ID_ABOUT:
  286.           if((ulRC = WinDlgBox( HWND_DESKTOP, hwnd, DlgAboutProc, 0L,
  287.                                (ULONG)DLG_ABOUT, NULL)) == DID_ERROR )
  288.           {
  289.              ulRC = WinGetLastError( hab );
  290.              HfpTrace( hfpFPHandle, &ulRC, sizeof(ulRC), "DlgBxEr2", 0 );
  291.           }
  292.           break;
  293.         default:
  294.           return WinDefWindowProc( hwnd, msg, mp1, mp2 );
  295.       }
  296.  
  297.       break;
  298.       }
  299.     case WM_ERASEBACKGROUND:
  300.       /*
  301.        * Return TRUE to request PM to paint the window background
  302.        * in SYSCLR_WINDOW.
  303.        */
  304.       return (MRESULT)( TRUE );
  305.     case WM_PAINT:
  306.       hps = WinBeginPaint( hwnd, 0L, NULL );
  307.       GpiErase( hps );
  308.       /* load the bare feet bitmap */
  309.       hbm = GpiLoadBitmap( hps, 0, BMP_BIGFOOTS, (LONG)cxClient,
  310.                            (LONG)cyClient );
  311.       if( hbm )
  312.       {
  313.          ptl.x = 0; ptl.y = 0;             /* Set the text coordinates,    */
  314.          WinDrawBitmap( hps, hbm, 0, &ptl, CLR_NEUTRAL, CLR_BACKGROUND,
  315.                         DBM_NORMAL);
  316.          GpiDeleteBitmap( hbm );
  317.       }
  318.       WinEndPaint( hps );                      /* Drawing is complete   */
  319.       break;
  320.     case WM_CLOSE:
  321.       WinPostMsg( hwnd, WM_QUIT, (MPARAM)0,(MPARAM)0 );/* Cause termination*/
  322.       break;
  323.     case WM_SIZE:
  324.       /* set the size parameters for use in WM_PAINT */
  325.       cxClient = SHORT1FROMMP( mp2 );
  326.       cyClient = SHORT2FROMMP( mp2 );
  327.       break;
  328.     default:
  329.       return WinDefWindowProc( hwnd, msg, mp1, mp2 );
  330.   }
  331.   return (MRESULT)FALSE;
  332. } /* End of MyWindowProc */
  333.  
  334.  
  335. /*+-------------------------------------------------------------------------+
  336.   |                                                                         |
  337.   |    DlgWelcomeProc is the first dialog box.  It just gives instructions  |
  338.   |    and provides the OK and Cancel buttons.                              |
  339.   |                                                                         |
  340.   +-------------------------------------------------------------------------+*/
  341. MRESULT EXPENTRY DlgWelcomeProc( HWND hwnd, ULONG ulMsg, MPARAM mp1, MPARAM mp2 )
  342. {
  343.    switch (ulMsg)
  344.    {
  345.      case WM_COMMAND:
  346.        switch( SHORT1FROMMP(mp1) )
  347.        {
  348.          case BID_CANCEL:
  349.            WinDismissDlg( hwnd, FALSE );
  350.            break;
  351.          case BID_OK:
  352.            WinDismissDlg( hwnd, TRUE );
  353.            break;
  354.          default:
  355.            return WinDefDlgProc( hwnd, ulMsg, mp1, mp2 );
  356.        }
  357.      default:
  358.        return WinDefDlgProc( hwnd, ulMsg, mp1, mp2 );
  359.    }
  360. }
  361.  
  362. /*+-------------------------------------------------------------------------+
  363.   |                                                                         |
  364.   |    DlgIsUpProc is the second dialog box.  It just gives instructions    |
  365.   |    and provides the OK and Cancel buttons.                              |
  366.   |                                                                         |
  367.   +-------------------------------------------------------------------------+*/
  368. MRESULT EXPENTRY DlgIsUpProc( HWND hwnd, ULONG ulMsg, MPARAM mp1, MPARAM mp2 )
  369. {
  370.    switch (ulMsg)
  371.    {
  372.      case WM_CREATE:
  373.        WinSetFocus( HWND_DESKTOP, WinWindowFromID( hwnd, BID_OK ));
  374.        break;
  375.      case WM_COMMAND:
  376.        switch( SHORT1FROMMP(mp1) )
  377.        {
  378.          case BID_CANCEL:
  379.            WinDismissDlg( hwnd, TRUE);
  380.            break;
  381.          case BID_OK:
  382.            break;
  383.          default:
  384.            return WinDefDlgProc( hwnd, ulMsg, mp1, mp2 );
  385.        }
  386.      default:
  387.        return WinDefDlgProc( hwnd, ulMsg, mp1, mp2 );
  388.    }
  389. }
  390.  
  391. /*+-------------------------------------------------------------------------+
  392.   |                                                                         |
  393.   |    DlgAboutProc is the programmer's ego trip dialog box.  It just gives |
  394.   |    the demo version number, copyright notice, and the name of yours     |
  395.   |    truly.                                                               |
  396.   |                                                                         |
  397.   +-------------------------------------------------------------------------+*/
  398. MRESULT EXPENTRY DlgAboutProc( HWND hwnd, ULONG ulMsg, MPARAM mp1, MPARAM mp2 )
  399. {
  400.    switch (ulMsg)
  401.    {
  402.      case WM_COMMAND:
  403.        switch( SHORT1FROMMP(mp1) )
  404.        {
  405.          case BID_OK:
  406.            WinDismissDlg( hwnd, TRUE );
  407.            break;
  408.          default:
  409.            return WinDefDlgProc( hwnd, ulMsg, mp1, mp2 );
  410.        }
  411.      default:
  412.        return WinDefDlgProc( hwnd, ulMsg, mp1, mp2 );
  413.    }
  414. }
  415.  
  416. /*+-------------------------------------------------------------------------+
  417.   |                                                                         |
  418.   |    DlgMonitorProc is the third dialog box.  It just gives instructions  |
  419.   |    and provides the OK and Cancel buttons.                              |
  420.   |                                                                         |
  421.   +-------------------------------------------------------------------------+*/
  422. MRESULT EXPENTRY DlgMonitorProc( HWND hwnd, ULONG ulMsg, MPARAM mp1, MPARAM mp2 )
  423. {
  424.    switch (ulMsg)
  425.    {
  426.      case WM_COMMAND:
  427.        switch( SHORT1FROMMP(mp1) )
  428.        {
  429.          case BID_CANCEL:
  430.            WinDismissDlg( hwnd, FALSE );
  431.            break;
  432.          case BID_OK:
  433.            WinDismissDlg( hwnd, TRUE );
  434.            break;
  435.          default:
  436.            return WinDefDlgProc( hwnd, ulMsg, mp1, mp2 );
  437.        }
  438.      default:
  439.        return WinDefDlgProc( hwnd, ulMsg, mp1, mp2 );
  440.    }
  441. }
  442.  
  443. /*+-------------------------------------------------------------------------+
  444.   |                                                                         |
  445.   |    DlgTraceProc is the fourth dialog box.  It prompts the user to enter |
  446.   |    a trace bit and type some text, and then hit Trace.  If he/she/or it |
  447.   |    has set that trace bit in Footprints, the text entered in the 2nd    |
  448.   |    entry field will be traced.  The Trace button can be hit multiple    |
  449.   |    times.  The OK button takes the user to the HfpIsItOn dialog box,    |
  450.   |    and Cancel dismisses this box.                                       |
  451.   |                                                                         |
  452.   +-------------------------------------------------------------------------+*/
  453. MRESULT EXPENTRY DlgTraceProc( HWND hwnd, ULONG ulMsg, MPARAM mp1, MPARAM mp2 )
  454. {
  455.    ULONG ulRC;
  456.    CHAR acTraceTxt[256];
  457.    CHAR acTraceID[16];
  458.    INT iTraceID;
  459.  
  460.    switch (ulMsg)
  461.    {
  462.      case WM_COMMAND:
  463.        switch( SHORT1FROMMP(mp1) )
  464.        {
  465.          case BID_CANCEL:
  466.            WinDismissDlg( hwnd, FALSE );
  467.            break;
  468.          case BID_OK:
  469.            if( (ulRC = WinDlgBox( HWND_DESKTOP, hwnd, DlgIsItOnProc, 0L,
  470.                                   (ULONG)DLG_ISITON, NULL)) == DID_ERROR )
  471.            {
  472.               ulRC = WinGetLastError( hab );
  473.               HfpTrace( hfpFPHandle, &ulRC, sizeof(ulRC), "DlgBxEr6", 0 );
  474.            }
  475.            break;
  476.          case BID_TRACE:
  477.            memset( acTraceID, 0, sizeof( acTraceID ));
  478.            WinQueryWindowText( WinWindowFromID( hwnd, EID_BITNO),
  479.                                sizeof(acTraceID), acTraceID );
  480.            if( ((iTraceID = atoi( acTraceID )) > 64) ||
  481.                (iTraceID < 1) )
  482.            {
  483.               break;
  484.            }
  485.            if(( WinQueryWindowText( WinWindowFromID( hwnd, EID_TRTEXT),
  486.                                sizeof(acTraceTxt), acTraceTxt )) == 0 )
  487.            {
  488.               break;
  489.            }
  490.            /*------------------------------------------------------------
  491.                Here, we are tracing the text the user entered in the
  492.                dialog box window.  The trace id # is whatever the user
  493.                entered in that entry field.
  494.             ------------------------------------------------------------*/
  495.            HfpTrace( hfpFPHandle, acTraceTxt, strlen(acTraceTxt), "UserText",
  496.                      iTraceID );
  497.            break;
  498.          default:
  499.            return WinDefDlgProc( hwnd, ulMsg, mp1, mp2 );
  500.        }
  501.      case WM_CONTROL:
  502.        break;
  503.      default:
  504.        return WinDefDlgProc( hwnd, ulMsg, mp1, mp2 );
  505.    }
  506. }
  507.  
  508. /*+-------------------------------------------------------------------------+
  509.   |                                                                         |
  510.   |    DlgIsItOnProc is the last dialog box.  It prompts the user to turn   |
  511.   |    on any or all of trace bits 1, 2, or 3, and the code will check to   |
  512.   |    see which bits have been turned on.  This simply shows how runtime   |
  513.   |    execution can be changed by external events. Hopefully, the          |
  514.   |    developer can use the imagination to see what kind of debug code he  |
  515.   |    would use with this type of function.                                |
  516.   |                                                                         |
  517.   +-------------------------------------------------------------------------+*/
  518. MRESULT EXPENTRY DlgIsItOnProc( HWND hwnd, ULONG ulMsg, MPARAM mp1, MPARAM mp2 )
  519. {
  520.    int iOneOn = FALSE;                    /* initialize no bits on */
  521.    ULONG ulRC;
  522.  
  523.    switch (ulMsg)
  524.    {
  525.      case WM_COMMAND:
  526.        switch( SHORT1FROMMP(mp1) )
  527.        {
  528.          case BID_CANCEL:
  529.            WinDismissDlg( hwnd, FALSE );
  530.            break;
  531.          case BID_OK:
  532.            if( HfpIsItOn( hfpFPHandle, 1 ))
  533.            {
  534.               if( (ulRC = WinDlgBox( HWND_DESKTOP, hwnd, DlgBit1Proc, 0L,
  535.                                      (ULONG)DLG_BIT1, NULL)) == DID_ERROR )
  536.               {
  537.                  ulRC = WinGetLastError( hab );
  538.                  HfpTrace( hfpFPHandle, &ulRC, sizeof(ulRC), "DlgBxEr7", 0 );
  539.               }
  540.               iOneOn = TRUE;
  541.            }
  542.            if( HfpIsItOn( hfpFPHandle, 2 ))
  543.            {
  544.               if( (ulRC = WinDlgBox( HWND_DESKTOP, hwnd, DlgBit2Proc, 0L,
  545.                                      (ULONG)DLG_BIT2, NULL)) == DID_ERROR )
  546.               {
  547.                  ulRC = WinGetLastError( hab );
  548.                  HfpTrace( hfpFPHandle, &ulRC, sizeof(ulRC), "DlgBxEr8", 0 );
  549.               }
  550.               iOneOn = TRUE;
  551.            }
  552.            if( HfpIsItOn( hfpFPHandle, 3 ))
  553.            {
  554.               if( (ulRC = WinDlgBox( HWND_DESKTOP, hwnd, DlgBit3Proc, 0L,
  555.                                      (ULONG)DLG_BIT3, NULL)) == DID_ERROR )
  556.               {
  557.                  ulRC = WinGetLastError( hab );
  558.                  HfpTrace( hfpFPHandle, &ulRC, sizeof(ulRC), "DlgBxEr9", 0 );
  559.               }
  560.               iOneOn = TRUE;
  561.            }
  562.            if( iOneOn == FALSE )
  563.            {
  564.               if( (ulRC = WinDlgBox( HWND_DESKTOP, hwnd, DlgNoneProc, 0L,
  565.                                      (ULONG)DLG_NONE, NULL)) == DID_ERROR )
  566.               {
  567.                  ulRC = WinGetLastError( hab );
  568.                  HfpTrace( hfpFPHandle, &ulRC, sizeof(ulRC), "DlgBxErA", 0 );
  569.               }
  570.            }
  571.            break;
  572.          default:
  573.            return WinDefDlgProc( hwnd, ulMsg, mp1, mp2 );
  574.        }
  575.        break;
  576.      default:
  577.        return WinDefDlgProc( hwnd, ulMsg, mp1, mp2 );
  578.    }
  579. }
  580.  
  581. /*------------------------------------------------
  582.     This guy is practically just a message box
  583.     He gets called if Bit 1 has been turned on 
  584.     with Footprints
  585. -------------------------------------------------*/
  586. MRESULT EXPENTRY DlgBit1Proc( HWND hwnd, ULONG ulMsg, MPARAM mp1, MPARAM mp2 )
  587. {
  588.    switch (ulMsg)
  589.    {
  590.      case WM_COMMAND:
  591.        switch( SHORT1FROMMP(mp1) )
  592.        {
  593.          case BID_OK:
  594.            WinDismissDlg( hwnd, TRUE );
  595.            return( (MRESULT)TRUE );
  596.            break;
  597.          default:
  598.            return WinDefDlgProc( hwnd, ulMsg, mp1, mp2 );
  599.        }
  600.      default:
  601.        return WinDefDlgProc( hwnd, ulMsg, mp1, mp2 );
  602.    }
  603. }
  604.  
  605. /*------------------------------------------------
  606.     This guy is practically just a message box
  607.     He gets called if Bit 2 has been turned on 
  608.     with Footprints
  609. -------------------------------------------------*/
  610. MRESULT EXPENTRY DlgBit2Proc( HWND hwnd, ULONG ulMsg, MPARAM mp1, MPARAM mp2 )
  611. {
  612.    switch (ulMsg)
  613.    {
  614.      case WM_COMMAND:
  615.        switch( SHORT1FROMMP(mp1) )
  616.        {
  617.          case BID_OK:
  618.            WinDismissDlg( hwnd, TRUE );
  619.            return( (MRESULT)TRUE );
  620.            break;
  621.          default:
  622.            return WinDefDlgProc( hwnd, ulMsg, mp1, mp2 );
  623.        }
  624.      default:
  625.        return WinDefDlgProc( hwnd, ulMsg, mp1, mp2 );
  626.    }
  627. }
  628.  
  629. /*------------------------------------------------
  630.     This guy is practically just a message box
  631.     He gets called if Bit 3 has been turned on 
  632.     with Footprints
  633. -------------------------------------------------*/
  634. MRESULT EXPENTRY DlgBit3Proc( HWND hwnd, ULONG ulMsg, MPARAM mp1, MPARAM mp2 )
  635. {
  636.    switch (ulMsg)
  637.    {
  638.      case WM_COMMAND:
  639.        switch( SHORT1FROMMP(mp1) )
  640.        {
  641.          case BID_OK:
  642.            WinDismissDlg( hwnd, TRUE );
  643.            return( (MRESULT)TRUE );
  644.            break;
  645.          default:
  646.            return WinDefDlgProc( hwnd, ulMsg, mp1, mp2 );
  647.        }
  648.      default:
  649.        return WinDefDlgProc( hwnd, ulMsg, mp1, mp2 );
  650.    }
  651. }
  652.  
  653. /*------------------------------------------------
  654.     This guy is practically just a message box
  655.     He gets called if no bits have been turned
  656.     on with Footprints
  657. -------------------------------------------------*/
  658. MRESULT EXPENTRY DlgNoneProc( HWND hwnd, ULONG ulMsg, MPARAM mp1, MPARAM mp2 )
  659. {
  660.    switch (ulMsg)
  661.    {
  662.      case WM_COMMAND:
  663.        switch( SHORT1FROMMP(mp1) )
  664.        {
  665.          case BID_OK:
  666.            WinDismissDlg( hwnd, TRUE );
  667.            return( (MRESULT)TRUE );
  668.            break;
  669.          default:
  670.            return WinDefDlgProc( hwnd, ulMsg, mp1, mp2 );
  671.        }
  672.      default:
  673.        return WinDefDlgProc( hwnd, ulMsg, mp1, mp2 );
  674.    }
  675. }
  676.  
  677.  
  678. /*+-----------------------------------------------------------------------+
  679.   |  HandleError assumes there is a bad RC from a Win API call, in which  |
  680.   |  case it gets the last error and puts it in the Footprints trace      |
  681.   |  using Trace id 0, which is always set.                               |
  682.   +-----------------------------------------------------------------------+*/
  683. VOID HandleError( char *szErrString )
  684. {
  685.    ERRORID Err;
  686.  
  687.    Err = WinGetLastError( hab );
  688.    HfpTrace( hfpFPHandle, &Err, sizeof( Err ), szErrString, 0 );
  689.    return;
  690. }
  691.  
  692.  
  693. /*+-----------------------------------------------------------------------+ 
  694.   | HSSExit is registered with the DosExitList API call in the event of   |
  695.   | a Trap or DosExit, this routine will be called.                       |
  696.   | The HfpTerm function flushes out the current Footprints               |
  697.   | trace buffer so we can view any traced info.                          |
  698.   +-----------------------------------------------------------------------+*/
  699. VOID APIENTRY HSSExit( VOID )
  700. {
  701.    FILE *fp;
  702.    APIRET apiRC;
  703.  
  704.    /*-----------------------------------------------------------------------
  705.        HfpTerm tells Footprints to flush all trace messages to the trace
  706.        file and terminate this trace session.  No more HfpTrace calls
  707.        or HfpIsItOn calls may be made using this handle unless HfpInit is
  708.        called again.
  709.     -----------------------------------------------------------------------*/
  710.    if( apiRC = HfpTerm( hfpFPHandle ))
  711.    {
  712.       DosBeep( 600L, 200L );
  713.       fp = fopen( "fpdemo.err", "a" );
  714.       if (fp != NULL )
  715.       {
  716.          fprintf( fp, "Initialization error = %d\n", apiRC );
  717.          fclose( fp );
  718.       }
  719.    }
  720.    return;
  721. }
  722.  
  723.  
  724. /*********************** End of the hello.c *******************************/
  725.