home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / wpentk.zip / WBPENTK1.DSK / APPLIC.C next >
C/C++ Source or Header  |  1994-10-06  |  56KB  |  1,298 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.       WrtCopyStrokeData(pStrokeData->pStroke, 0, CSD_FLATTEN);
  856.       DosWrite(hf,
  857.                pStrokeData,
  858.                ulEachStrokeLength[ulSaveIndex],
  859.                &ulBytesWritten);
  860.  
  861.       if ( ulBytesWritten != ulEachStrokeLength[ulSaveIndex])
  862.         {
  863.  
  864.           ShowMessageBox(hwndDlg, IDMSG_FILE_WRITE_ERROR);
  865.           free(ulEachStrokeLength);
  866.           free(pStrokeData);
  867.           DosClose(hf);
  868.           return(FALSE);
  869.         }
  870.  
  871.       free(pStrokeData);
  872.  
  873.     }
  874.     DosClose(hf);
  875.     free(ulEachStrokeLength);
  876.  
  877.  
  878.   return TRUE;
  879. } /* SaveApp */
  880.  
  881.  
  882. /****************************************************************************/
  883. /* OpenFile       - Returns TRUE  if successfully open the file.            */
  884. /*                                                                          */
  885. /*  Parameters:                                                             */
  886. /*                                                                          */
  887. /*  Return Value:                                                           */
  888. /*                                                                          */
  889. /****************************************************************************/
  890. USHORT OpenFile(void)
  891. {
  892.   APIRET rc;                                  /* return code                */
  893.  
  894.   /*****************************************/
  895.   /* Open file, READ ONLY                  */
  896.   /*****************************************/
  897.   rc =  DosOpen("APPLIC.DAT",
  898.               &hf,
  899.               &ulAction,
  900.               0,
  901.               FILE_NORMAL,
  902.                        FILE_OPEN,
  903.                        (ULONG)OPEN_ACCESS_READONLY |
  904.                        OPEN_SHARE_DENYREADWRITE |
  905.                        OPEN_FLAGS_FAIL_ON_ERROR,
  906.                        (PEAOP2)NULL);
  907.  
  908.   if (rc)                               /* error opening the file            */
  909.        return FALSE;
  910.  
  911.   return TRUE;
  912.  
  913. } /* OpenFile */
  914.  
  915. /****************************************************************************/
  916. /* ReadHeader     - Returns TRUE  if successfully can read hwx fields and   */
  917. /*                  number of strokes element from file.                    */
  918. /*  Parameters:                                                             */
  919. /*                                                                          */
  920. /*  Return Value:                                                           */
  921. /*                                                                          */
  922. /****************************************************************************/
  923. USHORT ReadHeader()
  924. {
  925.  
  926.   /********************************************/
  927.   /* Read one header record.                  */
  928.   /********************************************/
  929.   DosRead(hf, (VOID *) &App, sizeof(APPLICATION), &ulBytesRead);
  930.   if (ulBytesRead != sizeof(APPLICATION) )
  931.     return FALSE;
  932.  
  933.   return TRUE;
  934.  
  935. } /* ReadHeader */
  936.  
  937.  
  938. /****************************************************************************/
  939. /* ReadAndDisplaySignature  - Returns TRUE if successfully can read strokes */
  940. /*                            from file and put them in the SKETCH Control. */
  941. /*  Parameters:                                                             */
  942. /*                                                                          */
  943. /*  Return Value:                                                           */
  944. /*                                                                          */
  945. /****************************************************************************/
  946. USHORT ReadAndDisplaySignature(HWND hwndDlg)
  947. {
  948.  
  949.   ULONG        ulStrokeIndex;             /* stroke indexer                  */
  950.   BOOL         rc;
  951.   PSKETCHSTROKEDEF  pStrokeData1;
  952.  
  953.   /**************************************/
  954.   /* Clear the Sketch window.           */
  955.   /**************************************/
  956.   WinSendMsg(WinWindowFromID(hwndDlg, IDC_SIGNATURE),
  957.              SKM_DELETE_ALL_STROKES,
  958.              NULL, NULL);
  959.  
  960.  
  961.   /*********************************************************/
  962.   /* Malloc enough to retrieve the lengths of each stroke. */
  963.   /*********************************************************/
  964.   ulEachStrokeLength = (ULONG *) calloc(App.ulStrokeTotal, sizeof(ULONG) );
  965.  
  966.  
  967.   /**************************************************/
  968.   /* Read All stroke lengths into array of lengths. */
  969.   /**************************************************/
  970.   DosRead(hf, (VOID *) ulEachStrokeLength, (sizeof(ULONG) * App.ulStrokeTotal), &ulBytesRead);
  971.   if ( ulBytesRead != (sizeof(ULONG) * App.ulStrokeTotal) )
  972.     {
  973.       free(ulEachStrokeLength);
  974.       return(FALSE);
  975.     }
  976.  
  977.  
  978.   /**************************************/
  979.   /* First stroke to the last stroke -  */
  980.   /* Read each stroke from the file.    */
  981.   /**************************************/
  982.   for (ulStrokeIndex = 0; ulStrokeIndex < App.ulStrokeTotal; ulStrokeIndex++)
  983.     {
  984.  
  985.       /*******************************************************/
  986.       /* Allocate a buffer (non-shared) based on that size.  */
  987.       /*******************************************************/
  988.       pStrokeData = malloc(ulEachStrokeLength[ulStrokeIndex]);
  989.       if (!pStrokeData)
  990.         {
  991.           free(ulEachStrokeLength);
  992.           return(FALSE);
  993.         }
  994.  
  995.       memset(pStrokeData , '\0',ulEachStrokeLength[ulStrokeIndex]); /* Zap, Zap, Zap */
  996.       /**************************************************/
  997.       /* Read the stroke from the file into the buffer. */
  998.       /**************************************************/
  999.       DosRead(hf,
  1000.               pStrokeData,
  1001.               ulEachStrokeLength[ulStrokeIndex],
  1002.               &ulBytesRead);
  1003.  
  1004.       /**********************************************/
  1005.       /* The following code is necessary for Stroke */
  1006.       /* Data pointer fix ups after each read.      */
  1007.       /**********************************************/
  1008.       pStrokeData->pStroke = (PSTROKEDATA)    ( (PBYTE) pStrokeData + sizeof( SKETCHSTROKEDEF ));
  1009.       if (pStrokeData->pStroke->cbStructSize == sizeof (STROKEDATA))
  1010.         {
  1011.         WrtCopyStrokeData(pStrokeData->pStroke, 0, CSD_UNFLATTEN);
  1012.         }
  1013.  
  1014.       if ( ulBytesRead != ulEachStrokeLength[ulStrokeIndex])
  1015.         {
  1016.           free(ulEachStrokeLength);
  1017.           free(pStrokeData);
  1018.           return(FALSE);
  1019.         }
  1020.  
  1021.  
  1022.       /*******************************************/
  1023.       /* Convert to Pen 1.1 stroke data          */
  1024.       /*******************************************/
  1025. /* Size of Pen 1.0 STROKEDATA */
  1026. #define STROKEDATA_10_LENGTH  ((ULONG) &(((STROKEDATA *)0)->ulInkColor))
  1027.  
  1028.       if (pStrokeData->pStroke->cbStructSize == STROKEDATA_10_LENGTH)
  1029.         {
  1030.         pStrokeData1 = malloc(ulEachStrokeLength[ulStrokeIndex]+ (sizeof (STROKEDATA) - STROKEDATA_10_LENGTH));
  1031.   
  1032.         memcpy(pStrokeData1, pStrokeData, sizeof (SKETCHSTROKEDEF));
  1033.         pStrokeData->pStroke->pXY = (PPOINTL) ((ULONG) pStrokeData->pStroke + STROKEDATA_10_LENGTH);
  1034.         pStrokeData1->pStroke = (PSTROKEDATA) ((ULONG) pStrokeData1 + sizeof (SKETCHSTROKEDEF));
  1035.         WrtCopyStrokeData((PSTROKEDATA)((ULONG) pStrokeData  + sizeof (SKETCHSTROKEDEF)),
  1036.                           (PBYTE)((ULONG) pStrokeData1 + sizeof (SKETCHSTROKEDEF)),
  1037.                           CSD_MIGRATE);
  1038.         free(pStrokeData);
  1039.         pStrokeData = pStrokeData1;
  1040.         } 
  1041.  
  1042.       /*******************************************/
  1043.       /* Put the Stroke into the Sketch Control. */
  1044.       /*******************************************/
  1045.       rc = (BOOL)WinSendMsg( WinWindowFromID( hwndDlg, IDC_SIGNATURE),
  1046.                              SKM_ADD_STROKE,
  1047.                              NULL,
  1048.                              MPFROMP(pStrokeData) );
  1049.  
  1050.  
  1051.       if (rc == FALSE)
  1052.         {
  1053.           free(ulEachStrokeLength);
  1054.           free(pStrokeData);
  1055.           return(FALSE);
  1056.         }
  1057.  
  1058.  
  1059.  
  1060.       free(pStrokeData);
  1061.     } /* end for loop - completed reading all strokes */
  1062.  
  1063.   /**************************************************/
  1064.   /* Free the array of stroke lengths.              */
  1065.   /**************************************************/
  1066.   free(ulEachStrokeLength);
  1067.  
  1068.   return TRUE;
  1069.  
  1070. } /* ReadandDisplaySignature */
  1071.  
  1072.  
  1073. /****************************************************************************/
  1074. /* SetRecord      - Sets the Application HWX information into the screen   .*/
  1075. /*                  handwriting fields.                                     */
  1076. /* Parameters:                                                              */
  1077. /*                                                                          */
  1078. /* Return Value:                                                            */
  1079. /*                                                                          */
  1080. /****************************************************************************/
  1081. VOID SetRecord( HWND hwndDlg)
  1082. {
  1083.  
  1084.  
  1085.   /****************************/
  1086.   /* Set Field Information.   */
  1087.   /****************************/
  1088.   WinSetDlgItemText(hwndDlg, IDC_DATA_LASTNAME, App.szLastName);
  1089.   WinSetDlgItemText(hwndDlg, IDC_DATA_FIRSTNAME, App.szFirstName);
  1090.   WinSetDlgItemText(hwndDlg, IDC_DATA_ADDRESS, App.szAddress);
  1091.   WinSetDlgItemText(hwndDlg, IDC_DATA_CITY, App.szCity);
  1092.   WinSetDlgItemText(hwndDlg, IDC_DATA_STATE, App.szState);
  1093.   WinSetDlgItemText(hwndDlg, IDC_DATA_ZIP, App.szZip);
  1094.  
  1095.  
  1096.  
  1097. } /* end SetRecord() */
  1098.  /* SetRecord */
  1099.  
  1100.  
  1101. /*************************************************************************/
  1102. /*  Name : SearchDlgProc                                                 */
  1103. /*                                                                       */
  1104. /*  Description : List Box to select Application to be displayed.        */
  1105. /*                                                                       */
  1106. /* Parameters   : hwnd - Window handle to which message is addressed     */
  1107. /*                msg - Message type                                     */
  1108. /*                mp1 - First message parameter                          */
  1109. /*                mp2 - Second message parameter                         */
  1110. /*                                                                       */
  1111. /*************************************************************************/
  1112. MRESULT EXPENTRY SearchDlgProc( HWND hwndDlg, ULONG msg, MPARAM mp1, MPARAM mp2 )
  1113. {
  1114.  
  1115. BOOL      bFill;        /* fill the listbox with names from applic.dat file  */
  1116. SHORT     sSelection;   /* Desired Application to display from listbox       */
  1117. BOOL      bFound;
  1118.  
  1119. HWND      hwndOwner;            /* debug */
  1120.  
  1121.   switch ( msg )
  1122.   {
  1123.     case WM_INITDLG:
  1124.        /****************************/
  1125.        /* Go to beginning of file. */
  1126.        /****************************/
  1127.        DosSetFilePtr(hf, 0, FILE_BEGIN, &ulNewPtr);
  1128.        bFill = TRUE;
  1129.        while (bFill)
  1130.          {
  1131.            DosRead(hf, (VOID *) &App, sizeof(APPLICATION), &ulBytesRead);
  1132.            if (ulBytesRead == sizeof(APPLICATION) )
  1133.              {
  1134.                WinSendMsg( WinWindowFromID( hwndDlg, IDC_SEARCHBOX),
  1135.                               LM_INSERTITEM,          /* insert an item */
  1136.                               MPFROMSHORT(LIT_SORTASCENDING),
  1137.                               MPFROMP(App.szLastName) ); /* item to insert */
  1138.  
  1139.                /************************************************/
  1140.                /* Advance the file pointer past the signature. */
  1141.                /************************************************/
  1142.                DosSetFilePtr(hf, App.ulSignatureSize, FILE_CURRENT, &ulNewPtr);
  1143.              }
  1144.            else /* EOF reached */
  1145.              bFill = FALSE;
  1146.          } /* List box is filled when end of file is reached. */
  1147.        break;
  1148.  
  1149.  
  1150.     case WM_COMMAND:                    /* Posted by pushbutton or key  */
  1151.       switch( SHORT1FROMMP( mp1 ) )     /* Extract the command value    */
  1152.       {
  1153.         case DID_CANCEL:         /* The Cancel pushbutton or Escape key */
  1154.           /**************************************/
  1155.           /* Hide the Search Dialog.            */
  1156.           /**************************************/
  1157.           WinDismissDlg( hwndDlg, DID_CANCEL);  /* Removes the dialog box    */
  1158.           return (MRESULT) FALSE;
  1159.  
  1160.         case DID_OK:
  1161.            /***********************************/
  1162.            /*  Get Owner of Display Dialog    */
  1163.            /***********************************/
  1164.            hwndOwner = WinQueryWindow(hwndDlg, QW_OWNER);
  1165.  
  1166.            /***********************************/
  1167.            /*  Get app selected from list box */
  1168.            /***********************************/
  1169.            sSelection = (SHORT)WinSendMsg(WinWindowFromID( hwndDlg, IDC_SEARCHBOX),
  1170.                             LM_QUERYSELECTION, 0, 0);
  1171.            /***********************************/
  1172.            /*  If slection was made set text  */
  1173.            /***********************************/
  1174.            if (sSelection != LIT_NONE)
  1175.              {
  1176.                WinSendMsg(WinWindowFromID( hwndDlg, IDC_SEARCHBOX),
  1177.                           LM_QUERYITEMTEXT,
  1178.                           MPFROM2SHORT(sSelection, LASTNAME_MAX),
  1179.                           MPFROMP(szSelectedName) );
  1180.                szSelectedName[LASTNAME_MAX] = '\0';
  1181.  
  1182.  
  1183.                /*********************************************/
  1184.                /*  Find and Display requested application.  */
  1185.                /*********************************************/
  1186.                 DosSetFilePtr(hf, 0, FILE_BEGIN, &ulNewPtr);   /* beginning of file */
  1187.                 bFound = FALSE;
  1188.                 while( !bFound)
  1189.                   {
  1190.                     if ( !ReadHeader() )
  1191.                       {
  1192.                         ShowMessageBox(hwndDlg, IDMSG_FILE_READ_ERROR);
  1193.                         WinSendMsg( WinWindowFromID( hwndOwner, DID_CANCEL),
  1194.                                     BM_CLICK, 0L, 0L);           /* Cancel Display */
  1195.                       }
  1196.                     else
  1197.                       {
  1198.                         if ( (strcmp(App.szLastName, szSelectedName) ) == 0)
  1199.                           bFound = TRUE;
  1200.                         else
  1201.                           {
  1202.                             /************************************************/
  1203.                             /* Advance the file pointer past the signature. */
  1204.                             /************************************************/
  1205.                             DosSetFilePtr(hf, App.ulSignatureSize, FILE_CURRENT, &ulNewPtr);
  1206.                           }
  1207.                       }
  1208.                   } /* end while */
  1209.  
  1210.                 WinDismissDlg( hwndDlg, DID_OK);  /* Removes the dialog box    */
  1211.                 SetRecord(hwndOwner);
  1212.                 if (App.ulSignatureSize != 0)
  1213.                   {
  1214.                     if ( !ReadAndDisplaySignature(hwndOwner) )
  1215.                       {
  1216.                         ShowMessageBox(hwndDlg, IDMSG_SIGNATURE_READ_ERROR);
  1217.                         WinSendMsg( WinWindowFromID( hwndOwner, DID_CANCEL),
  1218.                                     BM_CLICK, 0L, 0L);           /* Cancel Display */
  1219.                       }
  1220.                   }
  1221.                 else
  1222.                   /**************************************/
  1223.                   /* Clear last record's signature.     */
  1224.                   /**************************************/
  1225.                     {
  1226.  
  1227.                       WinSendMsg(WinWindowFromID(hwndOwner, IDC_SIGNATURE),
  1228.                                  SKM_DELETE_ALL_STROKES,
  1229.                                  NULL, NULL);
  1230.                     }
  1231.  
  1232.              }
  1233.           return (MRESULT) FALSE;
  1234.       }
  1235.       break;
  1236.     default:
  1237.       return WinDefDlgProc( hwndDlg, msg, mp1, mp2 );
  1238.   }
  1239.   return (MRESULT) FALSE;
  1240. }
  1241.  
  1242.  
  1243. /******************************************************************************
  1244. * SIZING OF A CONTROL TO A SPECIFIC NUMBER OF COLUMNS.                        *
  1245. * The control uses the PPMSV_CHARACTER_BOX_DX system value to size the        *
  1246. * control within the window.                                                  *
  1247. *                                                                             *
  1248. *     columns   = 5                                                           *
  1249. *     charboxdx = WrtQuerySysValue ( HWND_DESKTOP, PPMSV_CHARACTER_BOX_DX )   *
  1250. *     controlcx = (columns * charboxdx ) + (charboxdx / 2)                    *
  1251. *                                                                             *
  1252. * If you want to see how to size using the row and culumns look in the        *
  1253. * HWX_SAMP code for sizing sample                                             *
  1254. ******************************************************************************/
  1255. BOOL CombSizing ( HWND hWnd,
  1256.                   USHORT usField,
  1257.                   USHORT Columns )
  1258. {
  1259.    HWND     hwndComb;
  1260.    LONG     CharBoxDX;
  1261.    LONG     BorderCX;
  1262.    SWP      SWPwindow;
  1263.    BOOL     fSuccess;
  1264.    ULONG    ControlDX;
  1265.  
  1266.    fSuccess = TRUE;
  1267.  
  1268.    /* Get the size of the X border */
  1269.    BorderCX = WinQuerySysValue ( HWND_DESKTOP, SV_CXBORDER );
  1270.  
  1271.    /* get the X size of the HandWriting box */
  1272.    CharBoxDX  = WrtQuerySysValue ( HWND_DESKTOP, PPMSV_CHARACTER_BOX_DX );
  1273.  
  1274.    /* calculate the size the window need to be so it will have the */
  1275.    /* specified number of columns                                  */
  1276.    ControlDX  = ( ( Columns * CharBoxDX ) + ( CharBoxDX / 2 ) + ( 2 * BorderCX ) ) ;
  1277.  
  1278.  
  1279.    if ( ( hwndComb = WinWindowFromID ( hWnd, usField ) ) != NULLHANDLE )
  1280.       {
  1281.         WinQueryWindowPos ( hwndComb, (PSWP)&SWPwindow );
  1282.         fSuccess = WinSetWindowPos  ( hwndComb,
  1283.                                     HWND_TOP,
  1284.                                     SWPwindow.x,
  1285.                                     SWPwindow.y,
  1286.                                     ControlDX,
  1287.                                     SWPwindow.cy,
  1288.                                     SWP_MOVE   |
  1289.                                       SWP_SIZE   |
  1290.                                       SWP_SHOW );
  1291.  
  1292.       }
  1293.    else
  1294.       fSuccess = FALSE;
  1295.  
  1296.    return ( fSuccess );
  1297. }
  1298.