home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / pentlk11.zip / IMAGES / PENTLKT1.IMG / unc.dsk / APPLIC.C next >
C/C++ Source or Header  |  1994-01-13  |  56KB  |  1,295 lines

  1. /*****************************************************************************/
  2. /*                                                                           */
  3. /*  File Name   : APPLIC.C                                                   */
  4. /*                                                                           */
  5. /*  Description : Example Sketch/Handwriting Controls in Pen for OS/2        */
  6. /*                                                                           */
  7. /*  This program demonstrates how to create Handwriting and Sketch Controls  */
  8. /*  by defining them as part of a dialog template in a resource definition   */
  9. /*  file.  The name, address, city, state, and zip code fields are           */
  10. /*  Handwriting Controls and the signature field is a Sketch Control.        */
  11. /*                                                                           */
  12. /*  This application also shows how to use the following SKETCH Control      */
  13. /*  Messages in order to save/restore a sketch to/from disk.                 */
  14. /*    SKM_QUERY_CTL_STROKE_COUNT - Returns the number of strokes in          */
  15. /*                                 the stroke database.                      */
  16. /*    SKM_QUERY_STROKE_LENGTH    - Returns the length of stroke [1..n].      */
  17. /*    SKM_QUERY_STROKE_DATA      - Queries stroke data for stroke [1..n].    */
  18. /*    SKM_ADD_STROKE             - Adds a stroke into the stroke database.   */
  19. /*                                                                           */
  20. /*   Other Sketch Control Messages used:                                     */
  21. /*    SKM_SET_CTL_DRAW_POINTER   - Sets the drawing pointer.                 */
  22. /*    SKM_SET_CTL_INK_COLOR      - Sets the Control's ink color.             */
  23. /*    SKM_DELETE_ALL_STROKES     - Deletes all strokes from the database.    */
  24. /*                                                                           */
  25. /*  Copyright (C) 1993 IBM Corporation                                       */
  26. /*                                                                           */
  27. /*      DISCLAIMER OF WARRANTIES.  The following [enclosed] code is          */
  28. /*      sample code created by IBM Corporation. This sample code is not      */
  29. /*      part of any standard or IBM product and is provided to you solely    */
  30. /*      for  the purpose of assisting you in the development of your         */
  31. /*      applications.  The code is provided "AS IS", without                 */
  32. /*      warranty of any kind.  IBM shall not be liable for any damages       */
  33. /*      arising out of your use of the sample code, even if they have been   */
  34. /*      advised of the possibility of such damages.                          */
  35. /*                                                                           */
  36. /*****************************************************************************/
  37.  
  38. #define INCL_GPI
  39. #define INCL_DOS
  40. #define INCL_WIN
  41. #define INCL_PM
  42. #define INCL_DOSMEMMGR
  43. #define INCL_WINERRORS
  44. #include <stdlib.h>
  45. #include <stdio.h>
  46. #include <string.h>
  47. #include <os2.h>
  48. #include <penpm.h>
  49.  
  50. #include "applic.h"
  51.  
  52. int main()
  53. {
  54.  
  55.   HMQ     hmq;
  56.   QMSG    qmsg;
  57.   HWND    hwndClient;
  58.  
  59.   CHAR      szClientClass[50];
  60.   ULONG     flFrameFlags = FCF_TITLEBAR | FCF_TASKLIST | FCF_SIZEBORDER |
  61.                            FCF_SYSMENU  | FCF_MINMAX   | FCF_MENU       |
  62.                            FCF_SHELLPOSITION | FCF_ICON;
  63.  
  64.  
  65.   /*************************************************************************/
  66.   /* Initialize PM for this program and create its PM message queue.       */
  67.   /*************************************************************************/
  68.   hab = WinInitialize( (ULONG)NULL );
  69.   hmq = WinCreateMsgQueue( hab, 0L );
  70.  
  71.   /*************************************************************************/
  72.   /* Register "ClientWndProc" as the handling procedure for the            */
  73.   /* "ApplicationDemo" class window.                                       */
  74.   /*************************************************************************/
  75.   WinLoadString( hab
  76.                , (HMODULE) 0L
  77.                , APPLIC_CLASSNAME
  78.                , sizeof(szClientClass)
  79.                , szClientClass);
  80.  
  81.   WinRegisterClass( hab,
  82.                     szClientClass,
  83.                     (PFNWP)ClientWndProc,
  84.                     0L,
  85.                     0UL );
  86.  
  87.   /*************************************************************************/
  88.   /* Tell PM that we want the standard frame window.  This frame window    */
  89.   /* will surround a "ApplicationDemo" class client window.                */
  90.   /*************************************************************************/
  91.   hwndFrame = WinCreateStdWindow( HWND_DESKTOP,
  92.                                   WS_VISIBLE,
  93.                                   (PULONG)&flFrameFlags,
  94.                                   szClientClass,
  95.                                   szClientClass,
  96.                                   0L,
  97.                                   (HMODULE)NULL,
  98.                                   ID_MAIN,
  99.                                   (PHWND)&hwndClient );
  100.  
  101.  
  102.   /*************************************************************************/
  103.   /* This while loop waits for messages from PM.  If not a WM_CLOSE msg,   */
  104.   /* then we dispatch the message to our client window procedure.          */
  105.   /*************************************************************************/
  106.   while( WinGetMsg( hab, &qmsg, (HWND) NULL, 0, 0 ) )
  107.   {
  108.     WinDispatchMsg( hab, &qmsg );
  109.   }
  110.  
  111.   /*************************************************************************/
  112.   /* We will drop out of the while loop if the program receives a WM_CLOSE */
  113.   /* message.  We must destroy our PM resources and return to the          */
  114.   /* invoking procedure.                                                   */
  115.   /*************************************************************************/
  116.   WinDestroyWindow( hwndFrame );
  117.   WinDestroyMsgQueue( hmq );
  118.   WinTerminate( hab );
  119.   return( 0 );
  120. }
  121.  
  122.  
  123.  
  124. MRESULT EXPENTRY ClientWndProc( HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2 )
  125. {
  126.   HPS       hpsClient;
  127.   RECTL     rclClient;
  128.   USHORT    rc;                    /* is 1st app read successfully           */
  129.   CHAR cbuffer[100];
  130.   HWND      hwndFillDlg;
  131.  
  132.   switch( msg )
  133.   {
  134.  
  135.     case WM_CREATE:
  136.      /***********************************************************************/
  137.      /*  Check to make sure Pen for OS/2 is up before we do anything else.  */
  138.      /***********************************************************************/
  139.      if( WrtWaitActive( WRT_IMMEDIATE_RETURN ) )
  140.      {
  141.        /******************************************************************/
  142.        /* If Pen for OS/2 is NOT active then put up a message box and    */
  143.        /* terminate the program.                                         */
  144.        /******************************************************************/
  145.        ShowMessageBox(hwnd, IDMSG_NO_PEN_RUNNING);
  146.        WinSendMsg( hwnd, WM_CLOSE, NULL, NULL );
  147.        return( 0 );
  148.      }
  149.  
  150.      /******************************************/
  151.      /*  Load the colored pen pointers.        */
  152.      /******************************************/
  153.      BlackPen = WinLoadPointer(HWND_DESKTOP, 0L, BLACK_PEN);
  154.      BluePen  = WinLoadPointer(HWND_DESKTOP, 0L, BLUE_PEN);
  155.      RedPen   = WinLoadPointer(HWND_DESKTOP, 0L, RED_PEN);
  156.  
  157.      break;
  158.  
  159.     case WM_PAINT:
  160.     {
  161.       /*********************************************************************/
  162.       /* If we get a paint message then just clear the client window.      */
  163.       /*********************************************************************/
  164.       hpsClient = WinBeginPaint( hwnd, (HPS)NULL, &rclClient );
  165.       WinFillRect( hpsClient, &rclClient, CLR_BACKGROUND );
  166.       WinEndPaint( hpsClient );
  167.       return( (MRESULT)FALSE );
  168.     }
  169.  
  170.     case WM_COMMAND:
  171.     {
  172.       switch(SHORT1FROMMP(mp1))
  173.       {
  174.         case IDM_FILL_APP:
  175.           /******************************************************************/
  176.           /* The user has selected option to fill out an application.       */
  177.           /* Call dialog to save application to disk.                       */
  178.           /******************************************************************/
  179.           hwndFillDlg = WinLoadDlg ( HWND_DESKTOP, hwnd,  (PFNWP) FillDlgProc,
  180.                                     0L, IDD_FILL, NULL);
  181.           if ( hwndFillDlg )
  182.           {
  183.             WinShowWindow ( hwndFillDlg, TRUE );
  184.   
  185.             /******************************************************************/
  186.             /* The following lines are done to make sure that the handwriting */
  187.             /* has the number of boxes that you need.                         */
  188.             /* When using the program in different display adapters           */
  189.             /* (XGA, SVGA, VGA the window may not be big enough to            */
  190.             /* have the correct number of boxes.                              */
  191.             /* you can either change the size here or choose the correct size */
  192.             /* using the dialog editor.                                       */
  193.             /******************************************************************/
  194.             CombSizing ( hwndFillDlg, IDC_DATA_LASTNAME, 17 );
  195.             CombSizing ( hwndFillDlg, IDC_DATA_FIRSTNAME, 17 );
  196.             CombSizing ( hwndFillDlg, IDC_DATA_ADDRESS, 17 );
  197.             CombSizing ( hwndFillDlg, IDC_DATA_CITY, 17 );
  198.             CombSizing ( hwndFillDlg, IDC_DATA_STATE, 2 );
  199.             CombSizing ( hwndFillDlg, IDC_DATA_ZIP, 5 );
  200.           } else
  201.           {
  202.             sprintf(cbuffer, "WinLodDlg Failed HwndFillDlg= %ld", hwndFillDlg );
  203.             WinMessageBox( HWND_DESKTOP,
  204.                        hwnd,
  205.                        cbuffer,
  206.                        NULL, 1, MB_OK );
  207.           } /* endif */
  208.           break;
  209.  
  210.         case IDM_DISPLAY_APP:
  211.           /***********************************************************/
  212.           /* The user has selected option to display an Application. */
  213.           /* Call dialog to restore sketch to Sketch Control.        */
  214.           /***********************************************************/
  215.            rc = OpenFile();             /* Open the File  APPLIC.DAT         */
  216.            if (!rc)
  217.              /*********************************************************/
  218.              /* Applic.dat file will be created or appeneded to when  */
  219.              /* "Fill Out Application" is selected from Options Menu. */
  220.              /*********************************************************/
  221.              ShowMessageBox(hwnd, IDMSG_MISSING_FILE);
  222.            else
  223.               /************************************************/
  224.               /* Display the Application to the screen,       */
  225.               /* by restoring the signature to the Sketch     */
  226.               /* Control and the Handwriting fields to the    */
  227.               /* HWX Control.                                 */
  228.               /************************************************/
  229.               hwndFillDlg = WinLoadDlg ( HWND_DESKTOP, hwnd,  (PFNWP) DisplayDlgProc,
  230.                                         0L, IDD_FILL, NULL);
  231.               if ( hwndFillDlg ) 
  232.               {
  233.                 WinShowWindow ( hwndFillDlg, TRUE );
  234.       
  235.                 /******************************************************************/
  236.                 /* The following lines are done to make sure that the handwriting */
  237.                 /* has the number of boxes that you need.                         */
  238.                 /* When using the program in different display adapters           */
  239.                 /* (XGA, SVGA, VGA the window may not be big enough to            */
  240.                 /* have the correct number of boxes.                              */
  241.                 /* you can either change the size here or choose the correct size */
  242.                 /* using the dialog editor.                                       */
  243.                 /******************************************************************/
  244.                 CombSizing ( hwndFillDlg, IDC_DATA_LASTNAME, 17 );
  245.                 CombSizing ( hwndFillDlg, IDC_DATA_FIRSTNAME, 17 );
  246.                 CombSizing ( hwndFillDlg, IDC_DATA_ADDRESS, 17 );
  247.                 CombSizing ( hwndFillDlg, IDC_DATA_CITY, 17 );
  248.                 CombSizing ( hwndFillDlg, IDC_DATA_STATE, 2 );
  249.                 CombSizing ( hwndFillDlg, IDC_DATA_ZIP, 5 );
  250.               } else 
  251.               {
  252.                 sprintf(cbuffer, "WinLodDlg Failed HwndFillDlg= %ld", hwndFillDlg );
  253.                 WinMessageBox( HWND_DESKTOP,
  254.                            hwnd,
  255.                            cbuffer,
  256.                            NULL, 1, MB_OK );
  257.               } /* endif */
  258.           break;
  259.  
  260.  
  261.         case IDM_EXIT:
  262.           WinSendMsg(hwnd, WM_CLOSE, NULL, NULL);
  263.           break;
  264.       }
  265.       break;
  266.     }
  267.  
  268.     default:
  269.       return( WinDefWindowProc( hwnd, msg, mp1, mp2 ) );
  270.   }
  271.   return((MRESULT) FALSE);
  272. }
  273.  
  274.  
  275.  
  276. /****************************************************************************/
  277. /*  Name : FillDlgProc                                                      */
  278. /*                                                                          */
  279. /*  Description : Process to Fill out an Application and save to disk.      */
  280. /*                                                                          */
  281. /* Parameters   : hwnd - Window handle to which message is addressed        */
  282. /*                msg - Message type                                        */
  283. /*                mp1 - First message parameter                             */
  284. /*                mp2 - Second message parameter                            */
  285. /*                                                                          */
  286. /****************************************************************************/
  287. MRESULT EXPENTRY FillDlgProc( HWND hwndDlg, ULONG msg, MPARAM mp1, MPARAM mp2 )
  288. {
  289.  
  290.  
  291. ULONG     ulToolBarItem;
  292. USHORT    usToolNum;
  293.  
  294. USHORT    usSaveOK;              /* true if save successfully                */
  295.  
  296.   switch ( msg )
  297.   {
  298.     case WM_INITDLG:
  299.  
  300.        /**************************************/
  301.        /* Set the Dialog Title.              */
  302.        /**************************************/
  303.        WinSetWindowText(hwndDlg, "Fill Out Application");
  304.  
  305.        /**********************************************/
  306.        /* Set Drawing pointer to Black pen.          */
  307.        /**********************************************/
  308.        WinSendMsg( WinWindowFromID( hwndDlg, IDC_SIGNATURE),
  309.                    SKM_SET_CTL_DRAW_POINTER,
  310.                    MPFROMLONG(BlackPen), NULL);
  311.  
  312.  
  313.        /**********************************************/
  314.        /* Set INK to black.                          */
  315.        /**********************************************/
  316.        WinSendMsg( WinWindowFromID( hwndDlg, IDC_SIGNATURE),
  317.                   SKM_SET_CTL_INK_COLOR,
  318.                   MPFROMLONG(CLR_BLACK), NULL);
  319.  
  320.        /**************************************/
  321.        /* Set the "SAVE" pushbutton text.    */
  322.        /**************************************/
  323.        WinSetDlgItemText(hwndDlg, IDC_SAVE_OR_NEXT, "SAVE");
  324.  
  325.        /**************************************/
  326.        /* Set the "CLEAR" pushbutton text.   */
  327.        /**************************************/
  328.        WinSetDlgItemText(hwndDlg, IDC_CLEAR_OR_TOP, "CLEAR");
  329.  
  330.        FillToolBar(hwndDlg);
  331.  
  332.        break;
  333.  
  334.  
  335.     case WM_CONTROL:
  336.       switch (SHORT2FROMMP(mp1))   /* Event notification code.      */
  337.         {
  338.         case VN_SELECT:
  339.           {
  340.           switch (SHORT1FROMMP(mp1))
  341.             {
  342.               case IDC_PEN_COLORS:
  343.                 ulToolBarItem = (ULONG) WinSendMsg( WinWindowFromID( hwndDlg, IDC_PEN_COLORS),
  344.                                                     VM_QUERYSELECTEDITEM,
  345.                                                     NULL, NULL);
  346.                 usToolNum = SHORT2FROMMR(ulToolBarItem);
  347.                 switch (usToolNum)
  348.                   {
  349.                   case ID_BLACK:
  350.                     WinSendMsg( WinWindowFromID( hwndDlg, IDC_SIGNATURE),
  351.                                 SKM_SET_CTL_DRAW_POINTER,
  352.                                 MPFROMLONG(BlackPen), NULL);
  353.  
  354.                     WinSendMsg( WinWindowFromID( hwndDlg, IDC_SIGNATURE),
  355.                                SKM_SET_CTL_INK_COLOR,
  356.                                MPFROMLONG(CLR_BLACK), NULL);
  357.                     break;
  358.  
  359.                   case ID_BLUE:
  360.                     WinSendMsg( WinWindowFromID( hwndDlg, IDC_SIGNATURE),
  361.                                 SKM_SET_CTL_DRAW_POINTER,
  362.                                 MPFROMLONG(BluePen), NULL);
  363.  
  364.                     WinSendMsg( WinWindowFromID( hwndDlg, IDC_SIGNATURE),
  365.                                SKM_SET_CTL_INK_COLOR,
  366.                                MPFROMLONG(CLR_BLUE), NULL);
  367.                     break;
  368.  
  369.                   case ID_RED:
  370.                     WinSendMsg( WinWindowFromID( hwndDlg, IDC_SIGNATURE),
  371.                                 SKM_SET_CTL_DRAW_POINTER,
  372.                                 MPFROMLONG(RedPen), NULL);
  373.  
  374.                     WinSendMsg( WinWindowFromID( hwndDlg, IDC_SIGNATURE),
  375.                                SKM_SET_CTL_INK_COLOR,
  376.                                MPFROMLONG(CLR_RED), NULL);
  377.                     break;
  378.  
  379.                   }
  380.                 break;
  381.             }
  382.             break;
  383.           }
  384.  
  385.         case HXN_STROKE_ADDED:
  386.           /**********************************************************/
  387.           /* Notification message from hwx control -                */
  388.           /* Control has just received a pen stroke to be recoed.   */
  389.           /* Disable the save and clear buttons.                    */
  390.           /**********************************************************/
  391.           WinEnableWindow( (WinWindowFromID(hwndDlg, IDC_CLEAR_OR_TOP)), FALSE);
  392.           WinEnableWindow( (WinWindowFromID(hwndDlg, IDC_SAVE_OR_NEXT)), FALSE);
  393.           break;
  394.  
  395.         case HXN_CONTENTS_CHANGED:
  396.           /**********************************************************/
  397.           /* Notification message from hwx control -                */
  398.           /* Control has just completed stroke reco.                */
  399.           /* Ok to enable the save and clear buttons.               */
  400.           /**********************************************************/
  401.           WinEnableWindow( (WinWindowFromID(hwndDlg, IDC_CLEAR_OR_TOP)), TRUE);
  402.           WinEnableWindow( (WinWindowFromID(hwndDlg, IDC_SAVE_OR_NEXT)), TRUE);
  403.           break;
  404.  
  405.         default:
  406.           return WinDefWindowProc(hwndDlg, msg, mp1, mp2);
  407.         }
  408.       break;
  409.  
  410.     case WM_COMMAND:                    /* Posted by pushbutton or key       */
  411.       switch( SHORT1FROMMP( mp1 ) )     /* Extract the command value         */
  412.       {
  413.         case DID_CANCEL:         /* The Cancel pushbutton or Escape key      */
  414.           WinDismissDlg( hwndDlg, DID_CANCEL);  /* Removes the dialog box    */
  415.           return (MRESULT) FALSE;
  416.  
  417.  
  418.         case IDC_CLEAR_OR_TOP:       /* CLEAR */
  419.           ClearFields(hwndDlg);
  420.           break;
  421.  
  422.         case IDC_SAVE_OR_NEXT:       /* SAVE */
  423.             /********************************************************/
  424.             /* Save the Application, including the signature.       */
  425.             /********************************************************/
  426.             usSaveOK = SaveApp(hwndDlg);
  427.             if (usSaveOK)
  428.                 ClearFields(hwndDlg);
  429.           break;
  430.  
  431.       }
  432.       break;
  433.     default:
  434.       return WinDefDlgProc( hwndDlg, msg, mp1, mp2 );
  435.   }
  436.   return (MRESULT) FALSE;
  437. }
  438.  
  439.  
  440. /*********************************************************************/
  441. /*  Name : ClearFields                                               */
  442. /*                                                                   */
  443. /*  Description : Clear the Application Fields.                      */
  444. /*                                                                   */
  445. /* Parameters   : hwnd - Window handle to which message is addressed */
  446. /*                                                                   */
  447. /*********************************************************************/
  448. void ClearFields(HWND hwndDlg)
  449. {
  450.  
  451.     WinSetDlgItemText(hwndDlg, IDC_DATA_LASTNAME, "");
  452.     WinSetDlgItemText(hwndDlg, IDC_DATA_FIRSTNAME, "");
  453.     WinSetDlgItemText(hwndDlg, IDC_DATA_ADDRESS, "");
  454.     WinSetDlgItemText(hwndDlg, IDC_DATA_CITY, "");
  455.     WinSetDlgItemText(hwndDlg, IDC_DATA_STATE, "");
  456.     WinSetDlgItemText(hwndDlg, IDC_DATA_ZIP, "");
  457.  
  458.     WinSendMsg(WinWindowFromID(hwndDlg, IDC_SIGNATURE),
  459.                SKM_DELETE_ALL_STROKES,
  460.                NULL, NULL);
  461.  
  462. } /* end ClearFields function */
  463.  
  464.  
  465. /*****************************************************************************/
  466. /*  Name:   ShowMessageBox                                                   */
  467. /*                                                                           */
  468. /*  Description : Displays Messages                                          */
  469. /*                                                                           */
  470. /*  Concepts : Displays the Info/warning/error message box with the message  */
  471. /*             given in idMsg retrived from the message table                */
  472. /*             Called whever a Info/warning/error occurs and a message wishes*/
  473. /*             to be displayed to the user.                                  */
  474. /*                                                                           */
  475. /*  Parameters :  hwnd      - window handle of the owner of the              */
  476. /*                            message box                                    */
  477. /*                idMsg     - id of message to be retrieved from             */
  478. /*                            resource file                                  */
  479. /*                                                                           */
  480. /*  Returns: USHORT                                                          */
  481. /*                                                                           */
  482. /*****************************************************************************/
  483. USHORT ShowMessageBox(HWND hwnd, USHORT idMsg)
  484. {
  485.   CHAR    szText[MAXTEXTLEN];
  486.   CHAR    szTitle[MAXTEXTLEN];
  487.   USHORT  ulAlarm;
  488.   USHORT  ulStyle;
  489.  
  490.   if (idMsg > IDMSG_ERROR)
  491.     {
  492.     WinLoadMessage(hab, 0L, IDMSG_ERROR, MAXTEXTLEN, (PSZ) szTitle);
  493.     ulAlarm = WA_ERROR;
  494.     ulStyle = MB_OK | MB_ERROR | MB_MOVEABLE;
  495.     }
  496.   else
  497.   if (idMsg > IDMSG_WARNING)
  498.     {
  499.     WinLoadMessage(hab, 0L, IDMSG_WARNING, MAXTEXTLEN, (PSZ) szTitle);
  500.     ulAlarm = WA_WARNING;
  501.     ulStyle = MB_OKCANCEL | MB_ICONEXCLAMATION | MB_MOVEABLE;
  502.     }
  503.   else
  504.     {  /* Information message */
  505.     WinLoadMessage(hab, 0L, IDMSG_INFO, MAXTEXTLEN, (PSZ) szTitle);
  506.     ulAlarm = WA_NOTE;
  507.     ulStyle = MB_OK | MB_INFORMATION | MB_MOVEABLE;
  508.     }
  509.  
  510.   WinLoadMessage(hab, 0L, idMsg, MAXTEXTLEN, (PSZ) szText);
  511.   WinAlarm(HWND_DESKTOP, ulAlarm);
  512.  
  513.   return(WinMessageBox(HWND_DESKTOP,
  514.                        hwnd,
  515.                        szText,
  516.                        szTitle,
  517.                        IDD_MSGBOX,
  518.                        ulStyle));
  519. }
  520.  
  521. /*****************************************************************************/
  522. /*  Name:   CreateToolBar(HWND hwnd)                                         */
  523. /*                                                                           */
  524. /*                                                                           */
  525. /*****************************************************************************/
  526. VOID FillToolBar(HWND hwndDlg)
  527. {
  528.  
  529.  
  530.   WinSendMsg( WinWindowFromID( hwndDlg, IDC_PEN_COLORS),
  531.                                VM_SETITEM,
  532.                                MPFROM2SHORT(1, 1),
  533.                                MPFROMLONG(BlackPen) );
  534.  
  535.   WinSendMsg( WinWindowFromID( hwndDlg, IDC_PEN_COLORS),
  536.                                VM_SETITEM,
  537.                                MPFROM2SHORT(1, 2),
  538.                                MPFROMLONG(BluePen) );
  539.  
  540.   WinSendMsg( WinWindowFromID( hwndDlg, IDC_PEN_COLORS),
  541.                                VM_SETITEM,
  542.                                MPFROM2SHORT(1, 3),
  543.                                MPFROMLONG(RedPen) );
  544.  
  545.  
  546. }
  547.  
  548.  
  549. /*****************************************************************************/
  550. /*  Name : DisplayDlgProc                                                    */
  551. /*                                                                           */
  552. /*  Description : Process to display one or all Applications.                */
  553. /*                                                                           */
  554. /*  Parameters   : hwnd - Window handle to which message is addressed        */
  555. /*                 msg - Message type                                        */
  556. /*                 mp1 - First message parameter                             */
  557. /*                 mp2 - Second message parameter                            */
  558. /*                                                                           */
  559. /*****************************************************************************/
  560. MRESULT EXPENTRY DisplayDlgProc( HWND hwndDlg, ULONG msg, MPARAM mp1, MPARAM mp2 )
  561. {
  562.  
  563.   switch ( msg )
  564.   {
  565.     case WM_INITDLG:
  566.        /**************************************/
  567.        /* Set the Dialog Title.              */
  568.        /**************************************/
  569.        WinSetWindowText(hwndDlg, "Application Display");
  570.  
  571.        /******************************************/
  572.        /*  Set all HWX ENTRY fields to read only */
  573.        /******************************************/
  574.        WinEnableWindow( WinWindowFromID( hwndDlg, IDC_DATA_LASTNAME), FALSE);
  575.        WinEnableWindow( WinWindowFromID( hwndDlg, IDC_DATA_FIRSTNAME), FALSE);
  576.        WinEnableWindow( WinWindowFromID( hwndDlg, IDC_DATA_ADDRESS), FALSE);
  577.        WinEnableWindow( WinWindowFromID( hwndDlg, IDC_DATA_CITY), FALSE);
  578.        WinEnableWindow( WinWindowFromID( hwndDlg, IDC_DATA_STATE), FALSE);
  579.        WinEnableWindow( WinWindowFromID( hwndDlg, IDC_DATA_ZIP), FALSE);
  580.  
  581.  
  582.        /**************************************/
  583.        /* Disable the SKETCH window.         */
  584.        /**************************************/
  585.        WinEnableWindow( (WinWindowFromID(hwndDlg, IDC_SIGNATURE)), FALSE);
  586.  
  587.        /**************************************/
  588.        /* Set the "NEXT" pushbutton text.    */
  589.        /**************************************/
  590.        WinSetFocus(HWND_DESKTOP, WinWindowFromID(hwndDlg, IDC_SAVE_OR_NEXT) );
  591.        WinSetDlgItemText(hwndDlg, IDC_SAVE_OR_NEXT, "NEXT");
  592.  
  593.        /**************************************/
  594.        /* Set the "TOP"  pushbutton text.    */
  595.        /**************************************/
  596.        WinSetDlgItemText(hwndDlg, IDC_CLEAR_OR_TOP, "TOP");
  597.  
  598.        /**************************************/
  599.        /* Show the "SEARCH" pushbutton       */
  600.        /**************************************/
  601.        WinShowWindow(WinWindowFromID(hwndDlg, IDC_SEARCH), TRUE);
  602.  
  603.        /******************************************/
  604.        /* Hide the Pen Colors Selection ToolBar. */
  605.        /******************************************/
  606.        WinShowWindow(WinWindowFromID(hwndDlg, IDC_PEN_COLORS), FALSE);
  607.  
  608.        /**************************************************/
  609.        /* Initialize the Search Dialog Box.              */
  610.        /**************************************************/
  611.        hwndSearchDlg = WinLoadDlg( HWND_DESKTOP, hwndDlg,  (PFNWP) SearchDlgProc,
  612.                        0L, IDD_SEARCH, NULL);
  613.  
  614.        /*******************************************************************/
  615.        /* Display the first Application in file APPLIC.DAT to the screen. */
  616.        /*******************************************************************/
  617.        WinSendMsg( WinWindowFromID( hwndDlg, IDC_CLEAR_OR_TOP),
  618.                    BM_CLICK, 0L, 0L);             /* send TOP */
  619.        break;
  620.  
  621.  
  622.     case WM_COMMAND:                    /* Posted by pushbutton or key  */
  623.       switch( SHORT1FROMMP( mp1 ) )     /* Extract the command value    */
  624.       {
  625.         case DID_CANCEL:              /* The Cancel pushbutton or Escape key */
  626.           WinDestroyWindow( hwndSearchDlg);
  627.           WinDismissDlg( hwndDlg, DID_CANCEL);  /* Removes the dialog box    */
  628.           DosClose(hf);
  629.           return (MRESULT) FALSE;
  630.  
  631.         case IDC_SAVE_OR_NEXT:    /* NEXT BUTTON */
  632.            /******************************************************************/
  633.            /* Display the next Application in file APPLIC.DAT to the screen. */
  634.            /******************************************************************/
  635.            if ( !ReadHeader() )
  636.              ShowMessageBox(hwndDlg, IDMSG_FILE_END);
  637.            else
  638.              {
  639.                SetRecord(hwndDlg);
  640.                if (App.ulSignatureSize != 0)
  641.                  {
  642.                    if ( !ReadAndDisplaySignature(hwndDlg) )
  643.                      {
  644.                        ShowMessageBox(hwndDlg, IDMSG_SIGNATURE_READ_ERROR);
  645.                        WinSendMsg( WinWindowFromID( hwndDlg, DID_CANCEL),
  646.                                     BM_CLICK, 0L, 0L);           /* send CANCEL */
  647.                      }
  648.                  }  /* No Signature to display */
  649.                else
  650.                  {
  651.                    /**************************************/
  652.                    /* Clear last record's signature.     */
  653.                    /**************************************/
  654.                    WinSendMsg(WinWindowFromID(hwndDlg, IDC_SIGNATURE),
  655.                               SKM_DELETE_ALL_STROKES,
  656.                               NULL, NULL);
  657.                  }
  658.              }
  659.            break;
  660.  
  661.         case IDC_CLEAR_OR_TOP:          /* Top button */
  662.            /******************************************/
  663.            /* Go to beginning of file APPLIC.DAT and */
  664.            /* display the first application.         */
  665.            /******************************************/
  666.            DosSetFilePtr(hf, 0, FILE_BEGIN, &ulNewPtr);
  667.            WinSendMsg( WinWindowFromID( hwndDlg, IDC_SAVE_OR_NEXT),
  668.                          BM_CLICK, 0L, 0L);             /* send NEXT */
  669.            break;
  670.  
  671.         case IDC_SEARCH:
  672.           /****************************************/
  673.           /* Search Dialog visible.               */
  674.           /* Choose application to display.       */
  675.           /****************************************/
  676.           WinSetWindowPos(hwndSearchDlg,
  677.                           HWND_TOP,
  678.                           100,
  679.                           250,
  680.                           0,
  681.                           0,
  682.                           SWP_MOVE | SWP_SHOW | SWP_ACTIVATE);
  683.           break;
  684.  
  685.       }
  686.       break;
  687.     default:
  688.       return WinDefDlgProc( hwndDlg, msg, mp1, mp2 );
  689.   }
  690.   return (MRESULT) FALSE;
  691. }
  692.  
  693.  
  694. /****************************************************************************/
  695. /* SaveApp - Returns TRUE if saved successfully.                            */
  696. /*                                                                          */
  697. /*  Parameters:                                                             */
  698. /*                                                                          */
  699. /*  Return Value:                                                           */
  700. /*                                                                          */
  701. /****************************************************************************/
  702. USHORT SaveApp(HWND hwndDlg)
  703. {
  704.   APIRET rc;                                  /* return code                */
  705.  
  706.   ULONG             ulStrokeCount;              /* Total Strokes in signat  */
  707.   ULONG             ulSaveIndex;
  708.  
  709.  
  710.   /***************************************************************************/
  711.   /* First, Copy all handwriting fields to structure.                        */
  712.   /***************************************************************************/
  713.   WinQueryDlgItemText(hwndDlg, IDC_DATA_LASTNAME, LASTNAME_MAX, App.szLastName);
  714.   if ( (strlen(App.szLastName) ) == 0)
  715.     {
  716.       ShowMessageBox(hwndDlg, IDMSG_MISSING_LASTNAME);
  717.       return(FALSE);
  718.     }
  719.  
  720.   WinQueryDlgItemText(hwndDlg, IDC_DATA_FIRSTNAME, FIRSTNAME_MAX, App.szFirstName);
  721.   WinQueryDlgItemText(hwndDlg, IDC_DATA_ADDRESS, ADDRESS_MAX, App.szAddress);
  722.   WinQueryDlgItemText(hwndDlg, IDC_DATA_CITY, CITY_MAX, App.szCity);
  723.   WinQueryDlgItemText(hwndDlg, IDC_DATA_STATE, STATE_MAX, App.szState);
  724.   WinQueryDlgItemText(hwndDlg, IDC_DATA_ZIP, ZIP_MAX, App.szZip);
  725.  
  726.   /**************************************************************************/
  727.   /* Next, Open file to save Application Record, if first time - create it. */
  728.   /**************************************************************************/
  729.   rc =  DosOpen("APPLIC.DAT",
  730.               &hf,
  731.               &ulAction,
  732.               0,
  733.               FILE_NORMAL,
  734.                        FILE_OPEN | FILE_CREATE,
  735.                        (ULONG)OPEN_ACCESS_READWRITE |
  736.                        OPEN_SHARE_DENYREADWRITE |
  737.                        OPEN_FLAGS_FAIL_ON_ERROR,
  738.                        (PEAOP2)NULL);
  739.  
  740.   if (rc)         /* Error opening the file                                  */
  741.     {
  742.        ShowMessageBox(hwndDlg, IDMSG_FILE_OPEN_ERROR);
  743.        return FALSE;
  744.     }
  745.  
  746.   /*****************************************/
  747.   /* Move to end of file.                  */
  748.   /*****************************************/
  749.   DosSetFilePtr(hf, 0, FILE_END, &ulNewPtr);
  750.  
  751.   /***************************************************************************/
  752.   /* Next, Save the Signature Field and write the Application record to end  */
  753.   /* of the file.                                                            */
  754.   /***************************************************************************/
  755.  
  756.   /****************************************************/
  757.   /* Get the total count of strokes in the signature. */
  758.   /****************************************************/
  759.   ulStrokeCount =
  760.   (ULONG) WinSendMsg(WinWindowFromID( hwndDlg, IDC_SIGNATURE),
  761.                      SKM_QUERY_CTL_STROKE_COUNT,
  762.                      NULL, NULL);
  763.  
  764.   App.ulStrokeTotal = ulStrokeCount;
  765.  
  766.   App.ulSignatureSize = ulStrokeCount * sizeof(ULONG);  /* bytes in file     */
  767.  
  768.   /*******************************************************/
  769.   /* Malloc enough to save the lengths of each stroke.   */
  770.   /*******************************************************/
  771.   ulEachStrokeLength = (ULONG *) calloc(App.ulStrokeTotal, sizeof(ULONG) );
  772.  
  773.  
  774.   /*************************************************************/
  775.   /* First stroke to the last stroke -                         */
  776.   /* Save each strokes' length in the array which was malloced */
  777.   /*************************************************************/
  778.   for (ulSaveIndex = 0; ulSaveIndex < ulStrokeCount; ulSaveIndex++)
  779.     {
  780.  
  781.       ulEachStrokeLength[ulSaveIndex] =
  782.       (ULONG) WinSendMsg(WinWindowFromID( hwndDlg, IDC_SIGNATURE),
  783.                          SKM_QUERY_STROKE_LENGTH,
  784.                          MPFROMLONG(ulSaveIndex + 1), /* actual stroke number */
  785.                          NULL);
  786.       App.ulSignatureSize += ulEachStrokeLength[ulSaveIndex];
  787.     }
  788.  
  789.  
  790.   /************************************************************************/
  791.   /* Write HEADER containing HWX fields, Stroke count and Signature size. */
  792.   /************************************************************************/
  793.   DosWrite(hf,
  794.            &App,
  795.            sizeof(APPLICATION),
  796.            &ulBytesWritten);
  797.  
  798.   if ( ulBytesWritten != (sizeof(APPLICATION)) )
  799.     {
  800.       ShowMessageBox(hwndDlg, IDMSG_FILE_WRITE_ERROR);
  801.       free(ulEachStrokeLength);
  802.       DosClose(hf);
  803.       return(FALSE);
  804.     }
  805.  
  806.  
  807.   /*******************************************************/
  808.   /* Write ALL of the stroke's lengths to the file.      */
  809.   /*******************************************************/
  810.   DosWrite(hf,
  811.            ulEachStrokeLength,
  812.            sizeof(ULONG) * App.ulStrokeTotal,
  813.            &ulBytesWritten);
  814.  
  815.   if ( ulBytesWritten != ( sizeof(ULONG) * App.ulStrokeTotal) )
  816.     {
  817.  
  818.       ShowMessageBox(hwndDlg, IDMSG_FILE_WRITE_ERROR);
  819.       free(ulEachStrokeLength);
  820.       DosClose(hf);
  821.       return(FALSE);
  822.     }
  823.  
  824.  
  825.  
  826.   /**************************************/
  827.   /* First stroke to the last stroke -  */
  828.   /* Write each stroke to the file.     */
  829.   /**************************************/
  830.   for (ulSaveIndex = 0; ulSaveIndex < ulStrokeCount; ulSaveIndex++)
  831.     {
  832.       /*******************************************************/
  833.       /* Allocate a buffer (non-shared) based on that size.  */
  834.       /*******************************************************/
  835.       pStrokeData = malloc(ulEachStrokeLength[ulSaveIndex]);
  836.       if (!pStrokeData)
  837.         {
  838.          ShowMessageBox(hwndDlg, IDMSG_MEMORY_ERROR);
  839.          free(ulEachStrokeLength);
  840.          DosClose(hf);
  841.          return(FALSE);
  842.         }
  843.  
  844.       /*******************************/
  845.       /* Get the Stroke information. */
  846.       /*******************************/
  847.       WinSendMsg(WinWindowFromID( hwndDlg, IDC_SIGNATURE),
  848.                  SKM_QUERY_STROKE_DATA,
  849.                  MPFROMLONG(ulSaveIndex + 1), /* actual stroke number */
  850.                  MPFROMP(pStrokeData) );
  851.  
  852.       /**********************************/
  853.       /* Write the Stroke to file.      */
  854.       /**********************************/
  855.       DosWrite(hf,
  856.                pStrokeData,
  857.                ulEachStrokeLength[ulSaveIndex],
  858.                &ulBytesWritten);
  859.  
  860.       if ( ulBytesWritten != ulEachStrokeLength[ulSaveIndex])
  861.         {
  862.  
  863.           ShowMessageBox(hwndDlg, IDMSG_FILE_WRITE_ERROR);
  864.           free(ulEachStrokeLength);
  865.           free(pStrokeData);
  866.           DosClose(hf);
  867.           return(FALSE);
  868.         }
  869.  
  870.       free(pStrokeData);
  871.  
  872.     }
  873.     DosClose(hf);
  874.     free(ulEachStrokeLength);
  875.  
  876.  
  877.   return TRUE;
  878. } /* SaveApp */
  879.  
  880.  
  881. /****************************************************************************/
  882. /* OpenFile       - Returns TRUE  if successfully open the file.            */
  883. /*                                                                          */
  884. /*  Parameters:                                                             */
  885. /*                                                                          */
  886. /*  Return Value:                                                           */
  887. /*                                                                          */
  888. /****************************************************************************/
  889. USHORT OpenFile(void)
  890. {
  891.   APIRET rc;                                  /* return code                */
  892.  
  893.   /*****************************************/
  894.   /* Open file, READ ONLY                  */
  895.   /*****************************************/
  896.   rc =  DosOpen("APPLIC.DAT",
  897.               &hf,
  898.               &ulAction,
  899.               0,
  900.               FILE_NORMAL,
  901.                        FILE_OPEN,
  902.                        (ULONG)OPEN_ACCESS_READONLY |
  903.                        OPEN_SHARE_DENYREADWRITE |
  904.                        OPEN_FLAGS_FAIL_ON_ERROR,
  905.                        (PEAOP2)NULL);
  906.  
  907.   if (rc)                               /* error opening the file            */
  908.        return FALSE;
  909.  
  910.   return TRUE;
  911.  
  912. } /* OpenFile */
  913.  
  914. /****************************************************************************/
  915. /* ReadHeader     - Returns TRUE  if successfully can read hwx fields and   */
  916. /*                  number of strokes element from file.                    */
  917. /*  Parameters:                                                             */
  918. /*                                                                          */
  919. /*  Return Value:                                                           */
  920. /*                                                                          */
  921. /****************************************************************************/
  922. USHORT ReadHeader()
  923. {
  924.  
  925.   /********************************************/
  926.   /* Read one header record.                  */
  927.   /********************************************/
  928.   DosRead(hf, (VOID *) &App, sizeof(APPLICATION), &ulBytesRead);
  929.   if (ulBytesRead != sizeof(APPLICATION) )
  930.     return FALSE;
  931.  
  932.   return TRUE;
  933.  
  934. } /* ReadHeader */
  935.  
  936.  
  937. /****************************************************************************/
  938. /* ReadAndDisplaySignature  - Returns TRUE if successfully can read strokes */
  939. /*                            from file and put them in the SKETCH Control. */
  940. /*  Parameters:                                                             */
  941. /*                                                                          */
  942. /*  Return Value:                                                           */
  943. /*                                                                          */
  944. /****************************************************************************/
  945. USHORT ReadAndDisplaySignature(HWND hwndDlg)
  946. {
  947.  
  948.   ULONG        ulStrokeIndex;             /* stroke indexer                  */
  949.   BOOL         rc;
  950.  
  951.   /**************************************/
  952.   /* Clear the Sketch window.           */
  953.   /**************************************/
  954.   WinSendMsg(WinWindowFromID(hwndDlg, IDC_SIGNATURE),
  955.              SKM_DELETE_ALL_STROKES,
  956.              NULL, NULL);
  957.  
  958.  
  959.   /*********************************************************/
  960.   /* Malloc enough to retrieve the lengths of each stroke. */
  961.   /*********************************************************/
  962.   ulEachStrokeLength = (ULONG *) calloc(App.ulStrokeTotal, sizeof(ULONG) );
  963.  
  964.  
  965.   /**************************************************/
  966.   /* Read All stroke lengths into array of lengths. */
  967.   /**************************************************/
  968.   DosRead(hf, (VOID *) ulEachStrokeLength, (sizeof(ULONG) * App.ulStrokeTotal), &ulBytesRead);
  969.   if ( ulBytesRead != (sizeof(ULONG) * App.ulStrokeTotal) )
  970.     {
  971.       free(ulEachStrokeLength);
  972.       return(FALSE);
  973.     }
  974.  
  975.  
  976.   /**************************************/
  977.   /* First stroke to the last stroke -  */
  978.   /* Read each stroke from the file.    */
  979.   /**************************************/
  980.   for (ulStrokeIndex = 0; ulStrokeIndex < App.ulStrokeTotal; ulStrokeIndex++)
  981.     {
  982.  
  983.       /*******************************************************/
  984.       /* Allocate a buffer (non-shared) based on that size.  */
  985.       /*******************************************************/
  986.       pStrokeData = malloc(ulEachStrokeLength[ulStrokeIndex]);
  987.       if (!pStrokeData)
  988.         {
  989.           free(ulEachStrokeLength);
  990.           return(FALSE);
  991.         }
  992.  
  993.       memset(pStrokeData , '\0',ulEachStrokeLength[ulStrokeIndex]); /* Zap, Zap, Zap */
  994.       /**************************************************/
  995.       /* Read the stroke from the file into the buffer. */
  996.       /**************************************************/
  997.       DosRead(hf,
  998.               pStrokeData,
  999.               ulEachStrokeLength[ulStrokeIndex],
  1000.               &ulBytesRead);
  1001.  
  1002.       /**********************************************/
  1003.       /* The following code is necessary for Stroke */
  1004.       /* Data pointer fix ups after each read.      */
  1005.       /**********************************************/
  1006.       pStrokeData->pStroke = (PSTROKEDATA)    ( (PBYTE) pStrokeData + sizeof( SKETCHSTROKEDEF ));
  1007.       pStrokeData->pStroke->pXY  = (PPOINTL)  ( (PBYTE) pStrokeData + sizeof( SKETCHSTROKEDEF ) + sizeof( STROKEDATA ));
  1008.  
  1009.  
  1010.       if (pStrokeData->pStroke->pAuxInfo)
  1011.         {
  1012.           pStrokeData->pStroke->pAuxInfo = (PAUXDATAINFO)
  1013.               ( (PBYTE)  pStrokeData->pStroke->pXY
  1014.               + pStrokeData->pStroke->ulNumPoints * sizeof( POINTL ));
  1015.         }
  1016.  
  1017.  
  1018.       if (pStrokeData->pStroke->pAuxData)
  1019.         {
  1020.           pStrokeData->pStroke->pAuxData = (PAUXSTROKEDATA)
  1021.  
  1022.           ( (PBYTE)  pStrokeData->pStroke->pAuxInfo
  1023.             + sizeof( AUXDATAINFO )
  1024.             + sizeof( AUXDATADESC )
  1025.             * ( pStrokeData->pStroke->pAuxInfo->ulNumElements - 1 )
  1026.             + pStrokeData->pStroke->ulNumPoints
  1027.             * pStrokeData->pStroke->pAuxInfo->ulAuxSize);
  1028.         }
  1029.  
  1030.  
  1031.  
  1032.       if ( ulBytesRead != ulEachStrokeLength[ulStrokeIndex])
  1033.         {
  1034.           free(ulEachStrokeLength);
  1035.           free(pStrokeData);
  1036.           return(FALSE);
  1037.         }
  1038.  
  1039.       /*******************************************/
  1040.       /* Put the Stroke into the Sketch Control. */
  1041.       /*******************************************/
  1042.       rc = (BOOL)WinSendMsg( WinWindowFromID( hwndDlg, IDC_SIGNATURE),
  1043.                              SKM_ADD_STROKE,
  1044.                              NULL,
  1045.                              MPFROMP(pStrokeData) );
  1046.  
  1047.  
  1048.       if (rc == FALSE)
  1049.         {
  1050.           free(ulEachStrokeLength);
  1051.           free(pStrokeData);
  1052.           return(FALSE);
  1053.         }
  1054.  
  1055.  
  1056.  
  1057.       free(pStrokeData);
  1058.     } /* end for loop - completed reading all strokes */
  1059.  
  1060.   /**************************************************/
  1061.   /* Free the array of stroke lengths.              */
  1062.   /**************************************************/
  1063.   free(ulEachStrokeLength);
  1064.  
  1065.   return TRUE;
  1066.  
  1067. } /* ReadandDisplaySignature */
  1068.  
  1069.  
  1070. /****************************************************************************/
  1071. /* SetRecord      - Sets the Application HWX information into the screen   .*/
  1072. /*                  handwriting fields.                                     */
  1073. /* Parameters:                                                              */
  1074. /*                                                                          */
  1075. /* Return Value:                                                            */
  1076. /*                                                                          */
  1077. /****************************************************************************/
  1078. VOID SetRecord( HWND hwndDlg)
  1079. {
  1080.  
  1081.  
  1082.   /****************************/
  1083.   /* Set Field Information.   */
  1084.   /****************************/
  1085.   WinSetDlgItemText(hwndDlg, IDC_DATA_LASTNAME, App.szLastName);
  1086.   WinSetDlgItemText(hwndDlg, IDC_DATA_FIRSTNAME, App.szFirstName);
  1087.   WinSetDlgItemText(hwndDlg, IDC_DATA_ADDRESS, App.szAddress);
  1088.   WinSetDlgItemText(hwndDlg, IDC_DATA_CITY, App.szCity);
  1089.   WinSetDlgItemText(hwndDlg, IDC_DATA_STATE, App.szState);
  1090.   WinSetDlgItemText(hwndDlg, IDC_DATA_ZIP, App.szZip);
  1091.  
  1092.  
  1093.  
  1094. } /* end SetRecord() */
  1095.  /* SetRecord */
  1096.  
  1097.  
  1098. /*************************************************************************/
  1099. /*  Name : SearchDlgProc                                                 */
  1100. /*                                                                       */
  1101. /*  Description : List Box to select Application to be displayed.        */
  1102. /*                                                                       */
  1103. /* Parameters   : hwnd - Window handle to which message is addressed     */
  1104. /*                msg - Message type                                     */
  1105. /*                mp1 - First message parameter                          */
  1106. /*                mp2 - Second message parameter                         */
  1107. /*                                                                       */
  1108. /*************************************************************************/
  1109. MRESULT EXPENTRY SearchDlgProc( HWND hwndDlg, ULONG msg, MPARAM mp1, MPARAM mp2 )
  1110. {
  1111.  
  1112. BOOL      bFill;        /* fill the listbox with names from applic.dat file  */
  1113. SHORT     sSelection;   /* Desired Application to display from listbox       */
  1114. BOOL      bFound;
  1115.  
  1116. HWND      hwndOwner;            /* debug */
  1117.  
  1118.   switch ( msg )
  1119.   {
  1120.     case WM_INITDLG:
  1121.        /****************************/
  1122.        /* Go to beginning of file. */
  1123.        /****************************/
  1124.        DosSetFilePtr(hf, 0, FILE_BEGIN, &ulNewPtr);
  1125.        bFill = TRUE;
  1126.        while (bFill)
  1127.          {
  1128.            DosRead(hf, (VOID *) &App, sizeof(APPLICATION), &ulBytesRead);
  1129.            if (ulBytesRead == sizeof(APPLICATION) )
  1130.              {
  1131.                WinSendMsg( WinWindowFromID( hwndDlg, IDC_SEARCHBOX),
  1132.                               LM_INSERTITEM,          /* insert an item */
  1133.                               MPFROMSHORT(LIT_SORTASCENDING),
  1134.                               MPFROMP(App.szLastName) ); /* item to insert */
  1135.  
  1136.                /************************************************/
  1137.                /* Advance the file pointer past the signature. */
  1138.                /************************************************/
  1139.                DosSetFilePtr(hf, App.ulSignatureSize, FILE_CURRENT, &ulNewPtr);
  1140.              }
  1141.            else /* EOF reached */
  1142.              bFill = FALSE;
  1143.          } /* List box is filled when end of file is reached. */
  1144.        break;
  1145.  
  1146.  
  1147.     case WM_COMMAND:                    /* Posted by pushbutton or key  */
  1148.       switch( SHORT1FROMMP( mp1 ) )     /* Extract the command value    */
  1149.       {
  1150.         case DID_CANCEL:         /* The Cancel pushbutton or Escape key */
  1151.           /**************************************/
  1152.           /* Hide the Search Dialog.            */
  1153.           /**************************************/
  1154.           WinDismissDlg( hwndDlg, DID_CANCEL);  /* Removes the dialog box    */
  1155.           return (MRESULT) FALSE;
  1156.  
  1157.         case DID_OK:
  1158.            /***********************************/
  1159.            /*  Get Owner of Display Dialog    */
  1160.            /***********************************/
  1161.            hwndOwner = WinQueryWindow(hwndDlg, QW_OWNER);
  1162.  
  1163.            /***********************************/
  1164.            /*  Get app selected from list box */
  1165.            /***********************************/
  1166.            sSelection = (SHORT)WinSendMsg(WinWindowFromID( hwndDlg, IDC_SEARCHBOX),
  1167.                             LM_QUERYSELECTION, 0, 0);
  1168.            /***********************************/
  1169.            /*  If slection was made set text  */
  1170.            /***********************************/
  1171.            if (sSelection != LIT_NONE)
  1172.              {
  1173.                WinSendMsg(WinWindowFromID( hwndDlg, IDC_SEARCHBOX),
  1174.                           LM_QUERYITEMTEXT,
  1175.                           MPFROM2SHORT(sSelection, LASTNAME_MAX),
  1176.                           MPFROMP(szSelectedName) );
  1177.                szSelectedName[LASTNAME_MAX] = '\0';
  1178.  
  1179.  
  1180.                /*********************************************/
  1181.                /*  Find and Display requested application.  */
  1182.                /*********************************************/
  1183.                 DosSetFilePtr(hf, 0, FILE_BEGIN, &ulNewPtr);   /* beginning of file */
  1184.                 bFound = FALSE;
  1185.                 while( !bFound)
  1186.                   {
  1187.                     if ( !ReadHeader() )
  1188.                       {
  1189.                         ShowMessageBox(hwndDlg, IDMSG_FILE_READ_ERROR);
  1190.                         WinSendMsg( WinWindowFromID( hwndOwner, DID_CANCEL),
  1191.                                     BM_CLICK, 0L, 0L);           /* Cancel Display */
  1192.                       }
  1193.                     else
  1194.                       {
  1195.                         if ( (strcmp(App.szLastName, szSelectedName) ) == 0)
  1196.                           bFound = TRUE;
  1197.                         else
  1198.                           {
  1199.                             /************************************************/
  1200.                             /* Advance the file pointer past the signature. */
  1201.                             /************************************************/
  1202.                             DosSetFilePtr(hf, App.ulSignatureSize, FILE_CURRENT, &ulNewPtr);
  1203.                           }
  1204.                       }
  1205.                   } /* end while */
  1206.  
  1207.                 WinDismissDlg( hwndDlg, DID_OK);  /* Removes the dialog box    */
  1208.                 SetRecord(hwndOwner);
  1209.                 if (App.ulSignatureSize != 0)
  1210.                   {
  1211.                     if ( !ReadAndDisplaySignature(hwndOwner) )
  1212.                       {
  1213.                         ShowMessageBox(hwndDlg, IDMSG_SIGNATURE_READ_ERROR);
  1214.                         WinSendMsg( WinWindowFromID( hwndOwner, DID_CANCEL),
  1215.                                     BM_CLICK, 0L, 0L);           /* Cancel Display */
  1216.                       }
  1217.                   }
  1218.                 else
  1219.                   /**************************************/
  1220.                   /* Clear last record's signature.     */
  1221.                   /**************************************/
  1222.                     {
  1223.  
  1224.                       WinSendMsg(WinWindowFromID(hwndOwner, IDC_SIGNATURE),
  1225.                                  SKM_DELETE_ALL_STROKES,
  1226.                                  NULL, NULL);
  1227.                     }
  1228.  
  1229.              }
  1230.           return (MRESULT) FALSE;
  1231.       }
  1232.       break;
  1233.     default:
  1234.       return WinDefDlgProc( hwndDlg, msg, mp1, mp2 );
  1235.   }
  1236.   return (MRESULT) FALSE;
  1237. }
  1238.  
  1239.  
  1240. /******************************************************************************
  1241. * SIZING OF A CONTROL TO A SPECIFIC NUMBER OF COLUMNS.                        *
  1242. * The control uses the PPMSV_CHARACTER_BOX_DX system value to size the        *
  1243. * control within the window.                                                  *
  1244. *                                                                             *
  1245. *     columns   = 5                                                           *
  1246. *     charboxdx = WrtQuerySysValue ( HWND_DESKTOP, PPMSV_CHARACTER_BOX_DX )   *
  1247. *     controlcx = (columns * charboxdx ) + (charboxdx / 2)                    *
  1248. *                                                                             *
  1249. * If you want to see how to size using the row and culumns look in the        *
  1250. * HWX_SAMP code for sizing sample                                             *
  1251. ******************************************************************************/
  1252. BOOL CombSizing ( HWND hWnd,
  1253.                   USHORT usField,
  1254.                   USHORT Columns )
  1255. {
  1256.    HWND     hwndComb;
  1257.    LONG     CharBoxDX;
  1258.    LONG     BorderCX;
  1259.    SWP      SWPwindow;
  1260.    BOOL     fSuccess;
  1261.    ULONG    ControlDX;
  1262.  
  1263.    fSuccess = TRUE;
  1264.  
  1265.    /* Get the size of the X border */
  1266.    BorderCX = WinQuerySysValue ( HWND_DESKTOP, SV_CXBORDER );
  1267.  
  1268.    /* get the X size of the HandWriting box */
  1269.    CharBoxDX  = WrtQuerySysValue ( HWND_DESKTOP, PPMSV_CHARACTER_BOX_DX );
  1270.  
  1271.    /* calculate the size the window need to be so it will have the */
  1272.    /* specified number of columns                                  */
  1273.    ControlDX  = ( ( Columns * CharBoxDX ) + ( CharBoxDX / 2 ) + ( 2 * BorderCX ) ) ;
  1274.  
  1275.  
  1276.    if ( ( hwndComb = WinWindowFromID ( hWnd, usField ) ) != NULLHANDLE )
  1277.       {
  1278.         WinQueryWindowPos ( hwndComb, (PSWP)&SWPwindow );
  1279.         fSuccess = WinSetWindowPos  ( hwndComb,
  1280.                                     HWND_TOP,
  1281.                                     SWPwindow.x,
  1282.                                     SWPwindow.y,
  1283.                                     ControlDX,
  1284.                                     SWPwindow.cy,
  1285.                                     SWP_MOVE   |
  1286.                                       SWP_SIZE   |
  1287.                                       SWP_SHOW );
  1288.  
  1289.       }
  1290.    else
  1291.       fSuccess = FALSE;
  1292.  
  1293.    return ( fSuccess );
  1294. }
  1295.