home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / pentlk11.zip / SKETSAMP.C < prev    next >
C/C++ Source or Header  |  1994-01-13  |  103KB  |  2,400 lines

  1. /*****************************************************************************/
  2. /*                                                                           */
  3. /*  File Name   : SKETSAMP.C                                                 */
  4. /*                                                                           */
  5. /*  Description : Sample Program for SKETCH Controls                         */
  6. /*                A Sketch Control is created in the client window.          */
  7. /*                                                                           */
  8. /*                A SKETCH Control Message will be executed when the user    */
  9. /*                presses the "Select Control" pushbutton and highlights an  */
  10. /*                item from the list box then presses OK.                    */
  11. /*                The user can get HELP for a particular message by          */
  12. /*                highlighting a Message in the list box and pressing HELP.  */
  13. /*                                                                           */
  14. /*                                                                           */
  15. /*                                                                           */
  16. /*  Copyright (C) 1993 IBM Corporation                                       */
  17. /*                                                                           */
  18. /*      DISCLAIMER OF WARRANTIES.  The following [enclosed] code is          */
  19. /*      sample code created by IBM Corporation. This sample code is not      */
  20. /*      part of any standard or IBM product and is provided to you solely    */
  21. /*      for  the purpose of assisting you in the development of your         */
  22. /*      applications.  The code is provided "AS IS", without                 */
  23. /*      warranty of any kind.  IBM shall not be liable for any damages       */
  24. /*      arising out of your use of the sample code, even if they have been   */
  25. /*      advised of the possibility of such damages.                          */
  26. /*                                                                           */
  27. /*****************************************************************************/
  28.  
  29. #define INCL_GPI
  30. #define INCL_DOS
  31. #define INCL_WIN
  32. #define INCL_PM
  33. #include <stdlib.h>
  34. #include <stdio.h>
  35. #include <string.h>
  36. #include <os2.h>
  37. #include <penpm.h>
  38.  
  39. #include "sketsamp.h"
  40. int main()
  41. {
  42.  
  43.   HMQ     hmq;
  44.   QMSG    qmsg;
  45.   HWND    hwndClient;
  46.  
  47.   CHAR      szClientClass [] = "SKETCH Controls Sample Program";
  48.  
  49.   ULONG ulCreateFlags =  FCF_STANDARD         /* Frame creation flags        */
  50.                       & ~(FCF_SHELLPOSITION   /* Don't let shell position    */
  51.                       | FCF_ACCELTABLE        /* No accelerator table        */
  52.                       | FCF_MENU );           /* No application menu bar     */
  53.  
  54.  
  55.   /*************************************************************************/
  56.   /* Initialize PM for this program and create its PM message queue.       */
  57.   /*************************************************************************/
  58.   hab = WinInitialize( (ULONG)NULL );
  59.   hmq = WinCreateMsgQueue( hab, 0L );
  60.  
  61.   /*************************************************************************/
  62.   /* Register "ClientWndProc" as the handling procedure for the            */
  63.   /* "Sketch Sample" class window.                                         */
  64.   /*************************************************************************/
  65.   WinRegisterClass( hab,
  66.                     szClientClass,
  67.                     (PFNWP)ClientWndProc,
  68.                     (LONG) CS_SIZEREDRAW,     /* Class flags            */
  69.                     0UL );
  70.  
  71.   /*************************************************************************/
  72.   /* Tell PM that we want the standard frame window.  This frame window    */
  73.   /* will surround a "Sketch Sample" class client window.                  */
  74.   /*************************************************************************/
  75.   hwndFrame = WinCreateStdWindow( HWND_DESKTOP,
  76.                                   WS_VISIBLE,
  77.                                   (PULONG)&ulCreateFlags,
  78.                                   szClientClass,
  79.                                   szClientClass,
  80.                                   0L,
  81.                                   (HMODULE)NULL,
  82.                                   ID_MAIN,
  83.                                   (PHWND)&hwndClient );
  84.  
  85.  
  86.   InitHelp();
  87.  
  88.   WinSetWindowPos(hwndFrame, HWND_TOP,
  89.                   100, 100, 450, 280,
  90.                   SWP_SIZE | SWP_MOVE | SWP_ACTIVATE | SWP_SHOW );
  91.  
  92.   /*************************************************************************/
  93.   /* This while loop waits for messages from PM.  If not a WM_CLOSE msg,   */
  94.   /* then we dispatch the message to our client window procedure.          */
  95.   /*************************************************************************/
  96.   while( WinGetMsg( hab, &qmsg, (HWND) NULL, 0, 0 ) )
  97.   {
  98.     WinDispatchMsg( hab, &qmsg );
  99.   }
  100.  
  101.   /*************************************************************************/
  102.   /* We will drop out of the while loop if the program receives a WM_CLOSE */
  103.   /* message.  We must destroy our PM resources and return to the          */
  104.   /* invoking procedure.                                                   */
  105.   /*************************************************************************/
  106.   WinDestroyHelpInstance( hwndHelp );
  107.   WinDestroyWindow( hwndFrame );
  108.   WinDestroyMsgQueue( hmq );
  109.   WinTerminate( hab );
  110.   return( 0 );
  111. }
  112.  
  113.  
  114. /****************************************************************************/
  115. /*  Name : ClientWndProc                                                    */
  116. /*                                                                          */
  117. /*  Description :                                                           */
  118. /*                                                                          */
  119. /* Parameters   : hwnd - Window handle to which message is addressed        */
  120. /*                msg - Message type                                        */
  121. /*                mp1 - First message parameter                             */
  122. /*                mp2 - Second message parameter                            */
  123. /*                                                                          */
  124. /****************************************************************************/
  125. MRESULT EXPENTRY ClientWndProc( HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2 )
  126. {
  127.         HPS       hpsClient;
  128.         RECTL     rclClient;
  129. static  CHAR      szListItem[MESSAGE_MAX];    /* Control Message             */
  130.  
  131.         ULONG     ulStrokeNumber;    /* notify of Stroke to clear, undo, add */
  132.  
  133.         COLOR     lColorChangedTo;   /* notify of color changed to           */
  134.         ULONG     ulWidthChangedTo;  /* notify of width changed to           */
  135.  
  136.         ULONG     ulDX, ulDY, ulY;
  137.         CHAR      szTempString[40];    /* temporary string buffer                    */
  138.  
  139.         USHORT fsKeyFlags;
  140.  
  141.  
  142.   switch( msg )
  143.   {
  144.  
  145.     case WM_CREATE:
  146.      bWindowsCreated = FALSE;  /* Control, buttons not yet created.          */
  147.      /*********************************************************************/
  148.      /* Check to make sure Pen for OS/2 is up before we do anything else. */
  149.      /*********************************************************************/
  150.      if( WrtWaitActive( WRT_IMMEDIATE_RETURN ) )
  151.      {
  152.        /******************************************************************/
  153.        /* If Pen for OS/2 is NOT active then put up a message box and    */
  154.        /* terminate the program.                                         */
  155.        /******************************************************************/
  156.        ShowMessageBox(hwnd, IDMSG_NO_PEN_RUNNING, NULL);
  157.        WinSendMsg( hwnd, WM_CLOSE, NULL, NULL );
  158.        return( 0 );
  159.      }
  160.  
  161.  
  162.      CreateControls(hwnd);        /* Create Select, Cancel, and Help button  */
  163.                                   /* and SKETCH window.                      */
  164.  
  165.      /***********************************/
  166.      /* Load the PEN Pointer            */
  167.      /***********************************/
  168.      hptrt1 = WinLoadPointer(HWND_DESKTOP, 0L, PTR_PEN);
  169.  
  170.      strcpy(szListItem, "SKM_DELETE_ALL_STROKES"); /* Highlight listbox item     */
  171.  
  172.      /***********************************/
  173.      /* Save the Default Sketch Pointer */
  174.      /***********************************/
  175.      hpDefault = (LONG) WinSendMsg(hSKETCHControl, SKM_QUERY_CTL_DRAW_POINTER,
  176.                                 NULL, NULL);
  177.  
  178.      bLookAtNotification = FALSE; /* Don't display notification messages     */
  179.                                   /* unless selected from example selection  */
  180.  
  181.      /*****************************************/
  182.      /* Create the SELECT Dialog ListBox.     */
  183.      /*****************************************/
  184.      hwndSelectDlg = WinLoadDlg( HWND_DESKTOP, hwnd,  (PFNWP) ChooseControlProc,
  185.                        0L, IDD_SELECTCONTROL, szListItem);
  186.  
  187.  
  188.     break;
  189.  
  190.     case WM_SIZE:              /* Check for a changed pos/size of the window */
  191.     {
  192.  
  193.       ulDX = SHORT1FROMMP(mp2) - 10;
  194.       ulDY = SHORT2FROMMP(mp2)
  195.            - 30L                                      /* DY of buttons       */
  196.            - 5L                                       /* offset of buttons   */
  197.            - 5L                                       /* space below sketch  */
  198.            - 5L;                                      /* space above sketch  */
  199.  
  200.       ulY  = SHORT2FROMMP(mp2) - ulDY - 5L;
  201.       WinSetWindowPos( WinWindowFromID(hwnd, IDC_SKETCH),
  202.                        (HWND) NULL,
  203.                        5,                                  /* x              */
  204.                        ulY,                                /* y              */
  205.                        ulDX,                               /* dx             */
  206.                        ulDY,                               /* dy             */
  207.                        SWP_SIZE | SWP_MOVE );              /* Operation      */
  208.     }
  209.     break;
  210.  
  211.     case WM_CLOSE:
  212.     {
  213.  
  214.       if (bWindowsCreated)
  215.         {
  216.           WinDestroyWindow( hwndSelectDlg);
  217.           WinDestroyWindow( hSELECTButton );
  218.           WinDestroyWindow( hCANCELButton );
  219.           WinDestroyWindow( hSKETCHControl);
  220.         }
  221.       WinDestroyWindow( hHELPButton );
  222.       WinPostMsg(hwnd, WM_QUIT, MPVOID, MPVOID ); /* Force termination       */
  223.     }
  224.     break;
  225.  
  226.  
  227.     case WM_PAINT:
  228.     {
  229.       /*********************************************************************/
  230.       /* If we get a paint message then just clear the client window.      */
  231.       /*********************************************************************/
  232.       hpsClient = WinBeginPaint( hwnd, (HPS)NULL, &rclClient );
  233.       WinFillRect( hpsClient, &rclClient, CLR_PALEGRAY );
  234.       WinEndPaint( hpsClient );
  235.       return( (MRESULT)FALSE );
  236.     }
  237.  
  238.     case WM_CHAR:
  239.        fsKeyFlags = (USHORT)SHORT1FROMMP(mp1);
  240.        if (fsKeyFlags & KC_VIRTUALKEY)
  241.          {
  242.            switch (SHORT2FROMMP(mp2) )
  243.            {
  244.              case VK_ENTER:
  245.              case VK_NEWLINE:
  246.                WinSendMsg( hwnd,
  247.                            WM_COMMAND,
  248.                            MPFROMSHORT(IDC_SELECT),
  249.                            MPFROM2SHORT(CMDSRC_PUSHBUTTON, FALSE) );
  250.            }
  251.          }
  252.        return( (MRESULT)FALSE );
  253.  
  254.     case WM_COMMAND:
  255.     {
  256.       switch(SHORT1FROMMP(mp1))
  257.       {
  258.         case IDC_CANCEL:
  259.           WinSendMsg(hwnd, WM_CLOSE, NULL, NULL);
  260.           break;
  261.  
  262.         case IDC_SELECT:
  263.         /***************************************************/
  264.         /* Show the SELECT Dialog.                         */
  265.         /***************************************************/
  266.         WinSetWindowPos(hwndSelectDlg,
  267.                         HWND_TOP,
  268.                         100,
  269.                         250,
  270.                         0,
  271.                         0,
  272.                         SWP_MOVE | SWP_SHOW | SWP_ACTIVATE);
  273.         break;
  274.       }
  275.       break;
  276.  
  277.  
  278.     }
  279.  
  280.     case WM_CONTROL:
  281.       switch(SHORT2FROMMP(mp1))
  282.       {
  283.  
  284.        /*************************************************/
  285.        /* Notification messages from the SKETCH Control */
  286.        /*************************************************/
  287.  
  288.         case SKN_STROKE_ADD:
  289.           /****************************************************************/
  290.           /* Tell user stroke is about to be added - if Cancel, don't add */
  291.           /****************************************************************/
  292.           if (bLookAtNotification)      /* if SKN_STROKE_ADD was selected    */
  293.             {
  294.               bLookAtNotification = FALSE;
  295.               ulStrokeNumber = LONGFROMMP(mp2);
  296.               sprintf(szTempString, "%ld", ulStrokeNumber);
  297.               if (MBID_OK != ShowMessageBox(hwnd, IDMSG_STROKE_ADD, szTempString) )
  298.                  return((MRESULT) TRUE);   /* Don't add the stroke           */
  299.               else
  300.                  return((MRESULT) FALSE);  /* Add the stroke                 */
  301.  
  302.             }
  303.           break;
  304.  
  305.         case SKN_STROKE_UNDO:
  306.           /******************************************************************/
  307.           /* Tell user stroke is about to be deleted - if Cancel, don't DEL */
  308.           /******************************************************************/
  309.           if (bLookAtNotification)
  310.             {
  311.               bLookAtNotification = FALSE;
  312.               ulStrokeNumber = LONGFROMMP(mp2);
  313.               sprintf(szTempString, "%ld", ulStrokeNumber);
  314.               if (MBID_OK != ShowMessageBox(hwnd, IDMSG_STROKE_UNDO, szTempString) )
  315.                  return((MRESULT) TRUE);   /* Don't undo the stroke          */
  316.               else
  317.                  return((MRESULT) FALSE);  /* Delete the stroke              */
  318.             }
  319.           break;
  320.  
  321.         case SKN_CONTROL_CLEARED:
  322.           /**********************************************************************/
  323.           /* Tell user database is about to be cleared - if Cancel, don't CLEAR */
  324.           /**********************************************************************/
  325.           if (bLookAtNotification)
  326.             {
  327.               bLookAtNotification = FALSE;
  328.               ulStrokeNumber = LONGFROMMP(mp2);
  329.               sprintf(szTempString, "%ld", ulStrokeNumber);
  330.               if (MBID_OK != ShowMessageBox(hwnd, IDMSG_STROKE_CLEAR, szTempString) )
  331.                  return((MRESULT) TRUE);        /* Don't delete the strokes  */
  332.               else
  333.                  return((MRESULT) FALSE);       /* delete all strokes        */
  334.             }
  335.           break;
  336.  
  337.  
  338.         case SKN_INK_COLOR_CHANGE:
  339.           if (bLookAtNotification)
  340.             {
  341.               lColorChangedTo = LONGFROMMP(mp2);
  342.               GetColorString(lColorChangedTo, (PSZ) &szTempString);   /* get color string*/
  343.               ShowMessageBox(hwnd, IDMSG_INK_COLOR_CHANGE, szTempString);
  344.               bLookAtNotification = FALSE;    /* turn off notification flag  */
  345.             }
  346.           break;
  347.  
  348.         case SKN_INK_WIDTH_CHANGE:
  349.           if (bLookAtNotification)
  350.             {
  351.               ulWidthChangedTo = LONGFROMMP(mp2);
  352.               sprintf(szTempString, "%ld", ulWidthChangedTo);
  353.               ShowMessageBox(hwnd, IDMSG_INK_WIDTH_CHANGE, szTempString);
  354.               bLookAtNotification = FALSE;    /* turn off notification flag  */
  355.             }
  356.           break;
  357.  
  358.         default:
  359.           return( WinDefWindowProc( hwnd, msg, mp1, mp2 ) );
  360.       }
  361.     break;
  362.  
  363.     default:
  364.       return( WinDefWindowProc( hwnd, msg, mp1, mp2 ) );
  365.   }
  366.   return((MRESULT) FALSE);
  367. }
  368.  
  369.  
  370. /*************************************************************************/
  371. /*  Name : ChooseControlProc                                             */
  372. /*                                                                       */
  373. /*  Description : List Box to select which SKETCH Control to execute.    */
  374. /*                                                                       */
  375. /*  Parameters  : hwnd - Window handle to which message is addressed     */
  376. /*                msg - Message type                                     */
  377. /*                mp1 - First message parameter                          */
  378. /*                mp2 - Second message parameter                         */
  379. /*                                                                       */
  380. /*************************************************************************/
  381. MRESULT EXPENTRY ChooseControlProc( HWND hwndDlg, ULONG msg, MPARAM mp1, MPARAM mp2 )
  382. {
  383.  
  384.        PSZ      pszTemp;         /* temporary string pointer                 */
  385.        USHORT   i;               /* temporary loop counter                   */
  386.        SHORT    sIndex;          /* Control index                            */
  387.        SHORT    sSelection;      /* selected Control Message Index           */
  388.  
  389.  
  390. static HWND    hwndControlList;    /* Listbox window handle                  */
  391. static PSZ     pszControl;         /* Current Control String                 */
  392.  
  393. LONG   MessageHelpPanel; /* Help panels for Control Messages                 */
  394.  
  395.  
  396.   switch ( msg )
  397.   {
  398.     case WM_INITDLG:
  399.        /****************************************************/
  400.        /* Retrieve a pointer to the current Control string */
  401.        /* to highlight it.                                 */
  402.        /****************************************************/
  403.        pszControl = PVOIDFROMMP(mp2);
  404.  
  405.        /****************************************************/
  406.        /* Retrieve the window handle of the list box.      */
  407.        /****************************************************/
  408.        hwndControlList = WinWindowFromID(hwndDlg, IDC_SELECTBOX);
  409.  
  410.        /****************************************************/
  411.        /* Add all of the Control strings to the list box.  */
  412.        /****************************************************/
  413.        for ( pszTemp = MessageList[0].pszMessageName, i = 1;
  414.              pszTemp != NULL; i++ )
  415.          {
  416.            WinSendMsg (hwndControlList,
  417.                        LM_INSERTITEM,
  418.                        MPFROMSHORT(LIT_END),
  419.                        MPFROMP(pszTemp) );
  420.            pszTemp = MessageList[i].pszMessageName;
  421.          }
  422.  
  423.        /****************************************************/
  424.        /* Find the index of the current Control string.    */
  425.        /****************************************************/
  426.        sIndex = (SHORT)  WinSendMsg( hwndControlList,
  427.                                      LM_SEARCHSTRING,
  428.                                      MPFROM2SHORT(LSS_CASESENSITIVE, LIT_FIRST),
  429.                                      MPFROMP( pszControl) );
  430.  
  431.        /*********************************************************/
  432.        /* Highlight the current Control string in the list box. */
  433.        /*********************************************************/
  434.        if (sIndex != LIT_NONE)
  435.          {
  436.            WinSendMsg( hwndControlList,
  437.                        LM_SELECTITEM,
  438.                        MPFROMSHORT(sIndex),
  439.                        MPFROMSHORT(TRUE) );
  440.          }
  441.  
  442.        /***********************************************************/
  443.        /* Set the Help Panel to match highlighted Control Message */
  444.        /***********************************************************/
  445.        MessageHelpPanel = MessageList[sIndex].ulMessageHelpValue;
  446.  
  447.        break;
  448.  
  449.     case WM_COMMAND:                    /* Posted by pushbutton or key  */
  450.       switch( SHORT1FROMMP( mp1 ) )     /* Extract the command value    */
  451.       {
  452.         case DID_CANCEL:         /* The Cancel pushbutton or Escape key */
  453.           WinSetFocus(HWND_DESKTOP, hwndControlList );   /* Re-start with focus in listbox */
  454.           WinSendMsg (WinWindowFromID(hwndDlg, DID_OK),  /* Re-start to show OK OK as default ENTER */
  455.                                       BM_SETDEFAULT,
  456.                                       MPFROMSHORT(TRUE), 0L);
  457.           WinDismissDlg( hwndDlg, DID_CANCEL);  /* Removes the dialog box    */
  458.         break;
  459.  
  460.  
  461.         case DID_OK:
  462.            /***************************************/
  463.            /*  Get Message selected from list box */
  464.            /***************************************/
  465.            sSelection = (SHORT)WinSendMsg( hwndControlList,
  466.                                             LM_QUERYSELECTION, 0, 0);
  467.  
  468.            /***********************************/
  469.            /*  If slection was made set text  */
  470.            /***********************************/
  471.            if (sSelection != LIT_NONE)
  472.              {
  473.                WinSendMsg(WinWindowFromID( hwndDlg, IDC_SELECTBOX),
  474.                           LM_QUERYITEMTEXT,
  475.                           MPFROM2SHORT(sSelection, MESSAGE_MAX),
  476.                           MPFROMP(pszControl)  );
  477.  
  478.  
  479.                ExecuteControlMessage(MessageList[sSelection].lMessageValue,  /* Message Value */
  480.                                      pszControl,  /* Message String          */
  481.                                      hwndDlg);
  482.              }
  483.           break;
  484.  
  485.         case IDC_MESSAGE_HELP:
  486.            /*****************************************/
  487.            /*  Get Message selected from list box.  */
  488.            /*****************************************/
  489.            sSelection = (SHORT)WinSendMsg( hwndControlList,
  490.                                             LM_QUERYSELECTION, 0, 0);
  491.  
  492.            /***********************************/
  493.            /*  If slection was made set text  */
  494.            /***********************************/
  495.            if (sSelection != LIT_NONE)
  496.              {
  497.                WinSendMsg(WinWindowFromID( hwndDlg, IDC_SELECTBOX),
  498.                           LM_QUERYITEMTEXT,
  499.                           MPFROM2SHORT(sSelection, MESSAGE_MAX),
  500.                           MPFROMP(pszControl)  );
  501.  
  502.                /***********************************************************/
  503.                /* Set the Help Panel to match highlighted Control Message */
  504.                /***********************************************************/
  505.                MessageHelpPanel = MessageList[sSelection].ulMessageHelpValue;
  506.  
  507.  
  508.                /********************************************************/
  509.                /* Display the Help panel for highlited Control Message */
  510.                /********************************************************/
  511.                WinSendMsg(hwndHelp, HM_DISPLAY_HELP,
  512.                                     MPFROM2SHORT(MessageHelpPanel,  NULL),
  513.                                     MPFROMSHORT(HM_RESOURCEID) );
  514.              }
  515.         break;
  516.       }
  517.       break;
  518.  
  519.     case WM_CONTROL:
  520.       switch( SHORT2FROMMP( mp1 ) )     /* Extract the command value    */
  521.       {
  522.         case LN_SELECT:          /* Item in listbox was selected        */
  523.            /*****************************************************/
  524.            /* A selection was made - show the OK button as      */
  525.            /* the default action for when ENTER Key is pressed. */
  526.            /*****************************************************/
  527.            WinSendMsg (WinWindowFromID(hwndDlg, DID_OK),
  528.                                        BM_SETDEFAULT,
  529.                                        MPFROMSHORT(TRUE), 0L);
  530.         break;
  531.  
  532.        case LN_ENTER:
  533.          {
  534.            /*****************************************************/
  535.            /* If user double-clicked on an item, react the same */
  536.            /* as if the user pressed OK pushbutton              */
  537.            /*****************************************************/
  538.  
  539.            /***************************************************************/
  540.            /* The Default state must be removed from the pushbuttons or   */
  541.            /* they will also get executed.                                */
  542.            /***************************************************************/
  543.            WinSendMsg (WinWindowFromID(hwndDlg, DID_OK),
  544.                                        BM_SETDEFAULT, FALSE, 0L);
  545.            WinSendMsg (WinWindowFromID(hwndDlg, DID_CANCEL),
  546.                                        BM_SETDEFAULT, FALSE, 0L);
  547.            WinSendMsg (WinWindowFromID(hwndDlg, IDC_MESSAGE_HELP),
  548.                                        BM_SETDEFAULT, FALSE, 0L);
  549.  
  550.            WinSendMsg( hwndDlg,
  551.                        WM_COMMAND,
  552.                        MPFROMSHORT(DID_OK),
  553.                        MPFROM2SHORT(CMDSRC_PUSHBUTTON, TRUE) );
  554.  
  555.            WinSetFocus(HWND_DESKTOP, hwndControlList );      /* focus to listbox items */
  556.          }
  557.         break;
  558.       }
  559.       break;
  560.  
  561.     default:
  562.       return WinDefDlgProc( hwndDlg, msg, mp1, mp2 );
  563.   }
  564.   return (MRESULT) FALSE;
  565.  
  566. }
  567.  
  568.  
  569. /*****************************************************************************/
  570. /*                                                                           */
  571. /*  ExecuteControlMessage(LONG lMessageValue, PSZ pszChosenItem, HWND hwnd)  */
  572. /*                                                                           */
  573. /*  Notes:                                                                   */
  574. /*                                                                           */
  575. /*                                                                           */
  576. /*  Attributes:                                                              */
  577. /*                                                                           */
  578. /*  Returns: void                                                            */
  579. /*                                                                           */
  580. /*  Change History:                                                          */
  581. /*                                                                           */
  582. /*  04-01-93 - Creation                                CPS                   */
  583. /*                                                                           */
  584. /*****************************************************************************/
  585.  
  586. void ExecuteControlMessage(LONG lMessageValue, PSZ pszChosenItem, HWND hwnd)
  587. {
  588. BOOL      rc;                 /* Return Code                                 */
  589.  
  590. HPOINTER  DrawPointer;        /* Draw Pointer returned from query            */
  591. HPOINTER  OldDrawPointer;     /* Draw Pointer before new setting             */
  592. CHAR      szDrawPointer[10];  /* Draw Pointer in string format               */
  593.  
  594. USHORT    usResult;
  595. CHAR      szTempString[40];    /* temporary string buffer                    */
  596.  
  597. ULONG     ulWidth;             /* Drawing Width in pels                      */
  598. ULONG     ulWidthCompare;
  599.  
  600. COLOR     lColorReturn;        /* Return from query of color                 */
  601. COLOR     lColorCompare;
  602.  
  603.  
  604. USHORT    usInvisible;         /* TRUE if invisible                          */
  605.  
  606.  
  607. ULONG     ulStrokeCount;       /* Return from GET_STROKE_COUNT               */
  608.  
  609. ULONG     ulStrokeNumber;               /* Stroke number selected to change  */
  610. CHAR      szStrokeColor[25];            /* Stroke color selected to change to*/
  611.  
  612. ULONG     ulAuxData;                    /* retrieve ADF_ALL or zero          */
  613. USHORT    usAuxReturn;
  614.  
  615. HBITMAP   hBitmap;                      /* handle returned from GET_BITMAP   */
  616.  
  617.  
  618. ULONG     ulBitmapSize;        /* Return from query of bitmap_size           */
  619. SHORT     sSizeX;              /* Size in pixels of bitmap in X direction    */
  620. SHORT     sSizeY;              /* Size in pixels of bitmap in Y direction    */
  621.  
  622. ULONG     ulStrokeLength;      /* Return from QUERY_STROKE_LENGTH            */
  623.  
  624.  switch( lMessageValue )                     /* Execute the Control Message  */
  625.  {
  626.  
  627.    case SKM_DELETE_ALL_STROKES:         /* Execute SKM_DELETE_ALL_STROKES    */
  628.      rc = (BOOL) WinSendMsg(hSKETCHControl,
  629.                             SKM_DELETE_ALL_STROKES,
  630.                             NULL, NULL);
  631.  
  632.      if( rc == FALSE )
  633.        ShowMessageBox(hwnd, IDMSG_NOTHING_CLEAR, NULL);
  634.      else
  635.        ShowMessageBox(hwnd, IDMSG_ALL_STROKES_CLEARED, NULL);
  636.      break;
  637.  
  638.  
  639.    case SKM_UNDO_LAST_STROKE:           /* Execute SKM_UNDO_LAST_STROKE      */
  640.      rc = (BOOL) WinSendMsg(hSKETCHControl,
  641.                             SKM_UNDO_LAST_STROKE,
  642.                             NULL, NULL);
  643.      if( rc == FALSE )
  644.        ShowMessageBox(hwnd, IDMSG_NOTHING_UNDO, NULL);
  645.      else
  646.        ShowMessageBox(hwnd, IDMSG_LAST_STROKE_CLEARED, NULL);
  647.      break;
  648.  
  649.    case SKM_QUERY_CTL_DRAW_POINTER:    /* Execute SKM_QUERY_CTL_DRAW_POINTER */
  650.     DrawPointer = (LONG) WinSendMsg(hSKETCHControl,
  651.                                     SKM_QUERY_CTL_DRAW_POINTER,
  652.                                     NULL, NULL);
  653.  
  654.  
  655.     if (DrawPointer == hptrt1)
  656.       strcpy(szTempString, "PEN");
  657.     else
  658.       if (DrawPointer == hpDefault)
  659.         strcpy(szTempString, "DEFAULT");
  660.       else
  661.         strcpy(szTempString, "UNKNOWN");
  662.  
  663.     ShowMessageBox(hwnd, IDMSG_DRAWPOINTER_QUERY, szTempString);
  664.     break;
  665.  
  666.    case SKM_QUERY_CTL_INK_WIDTH:         /* Execute SKM_QUERY_CTL_INK_WIDTH  */
  667.      ulWidth = (ULONG) WinSendMsg(hSKETCHControl,
  668.                                    SKM_QUERY_CTL_INK_WIDTH,
  669.                                    NULL, NULL);
  670.      if (ulWidth)
  671.        {
  672.          sprintf(szTempString, "%ld", ulWidth); /* put width in a string */
  673.          ShowMessageBox(hwnd, IDMSG_INK_WIDTH_QUERY, szTempString); /* show width */
  674.        }
  675.      else
  676.        ShowMessageBox(hwnd, IDMSG_MESSAGE_FAIL, pszChosenItem);
  677.      break;
  678.  
  679.    case SKM_QUERY_CTL_INK_COLOR:         /* Execute SKM_QUERY_CTL_INK_COLOR  */
  680.      lColorReturn =  (COLOR) WinSendMsg(hSKETCHControl,
  681.                                        SKM_QUERY_CTL_INK_COLOR,
  682.                                        NULL, NULL);
  683.      if (lColorReturn == CLR_ERROR)
  684.        ShowMessageBox(hwnd, IDMSG_MESSAGE_FAIL, pszChosenItem);
  685.      else
  686.        {
  687.          GetColorString(lColorReturn, (PSZ) &szTempString);   /* get color string*/
  688.          ShowMessageBox(hwnd, IDMSG_INK_COLOR_QUERY, szTempString); /* show color str  */
  689.        }
  690.      break;
  691.  
  692.    case SKM_QUERY_CTL_INVISIBLE_MODE:/* Execute SKM_QUERY_CTL_INVISIBLE_MODE */
  693.      usInvisible =   (USHORT) WinSendMsg(hSKETCHControl,
  694.                                          SKM_QUERY_CTL_INVISIBLE_MODE,
  695.                                          NULL, NULL);
  696.      if ( usInvisible == TRUE)
  697.        strcpy(szTempString, "\"INVISIBLE\"");
  698.      else
  699.        strcpy(szTempString, "\"VISIBLE\"");
  700.      ShowMessageBox(hwnd, IDMSG_DISPLAY_MODE, szTempString);
  701.      break;
  702.  
  703.    case SKM_SET_CTL_DRAW_POINTER:        /* Execute SKM_SET_CTL_DRAW_POINTER */
  704.     /****************************************/
  705.     /* First, What is it set to now?        */
  706.     /* If it is the Default, change to PEN; */
  707.     /* if it is the PEN, change to Default. */
  708.     /****************************************/
  709.     DrawPointer = (LONG) WinSendMsg(hSKETCHControl,
  710.                                     SKM_QUERY_CTL_DRAW_POINTER,
  711.                                     NULL, NULL);
  712.  
  713.     /****************************************/
  714.     /* Drawing pointer is currently set     */
  715.     /* to default Sketch input pointer,     */
  716.     /* change it the the PEN pointer.       */
  717.     /****************************************/
  718.     if (DrawPointer == hpDefault)
  719.       {
  720.         OldDrawPointer = (HPOINTER)WinSendMsg(hSKETCHControl,
  721.                                               SKM_SET_CTL_DRAW_POINTER,
  722.                                               MPFROMLONG(hptrt1), NULL);
  723.         if (OldDrawPointer == hptrt1)
  724.           strcpy(szDrawPointer, "PEN");
  725.         else
  726.           if (OldDrawPointer == hpDefault)
  727.             strcpy(szDrawPointer, "Default");
  728.           else
  729.             strcpy(szDrawPointer, "UNKNOWN");
  730.  
  731.         sprintf(szTempString, "\nPrevious = %s.\nNew = PEN.",
  732.                                szDrawPointer);
  733.         ShowMessageBox(hwnd, IDMSG_DRAWPOINTER_SET, szTempString);
  734.  
  735.       }
  736.     else
  737.       /****************************************/
  738.       /* Drawing pointer is currently set     */
  739.       /* to PEN pointer, change back to       */
  740.       /* default Sketch input pointer.        */
  741.       /****************************************/
  742.       {
  743.         OldDrawPointer = (HPOINTER)WinSendMsg(hSKETCHControl,
  744.                                               SKM_SET_CTL_DRAW_POINTER,
  745.                                               MPFROMLONG(hpDefault), NULL);
  746.         if (OldDrawPointer == hptrt1)
  747.           strcpy(szDrawPointer, "PEN");
  748.         else
  749.           if (OldDrawPointer == hpDefault)
  750.             strcpy(szDrawPointer, "Default");
  751.           else
  752.             strcpy(szDrawPointer, "UNKNOWN");
  753.  
  754.         sprintf(szTempString, "\nPrevious = %s.\nNew = DEFAULT.",
  755.                                szDrawPointer);
  756.         ShowMessageBox(hwnd, IDMSG_DRAWPOINTER_SET, szTempString);
  757.  
  758.       }
  759.  
  760.      break;
  761.  
  762.    case SKM_SET_CTL_INK_WIDTH:           /* Execute SKM_SET_CTL_INK_WIDTH    */
  763.     /********************************/
  764.     /*  Get desired width from user */
  765.     /********************************/
  766.      usResult = WinDlgBox(HWND_DESKTOP,      /* place anywhere on desktop    */
  767.                      hwnd,                   /* owned by frame               */
  768.                      (PFNWP) WidthDlgProc,   /* Address of width procedure   */
  769.                      0L,                     /* Module handle                */
  770.                      IDD_GETWIDTH,           /* Dialog identifier in resource*/
  771.                      &ulWidth);              /* Return the width             */
  772.  
  773.      if (usResult == DID_OK)
  774.        {
  775.          rc = (BOOL) WinSendMsg(hSKETCHControl, SKM_SET_CTL_INK_WIDTH,
  776.                                 MPFROMLONG(ulWidth), NULL);
  777.  
  778.          sprintf(szTempString, "%ld", ulWidth);
  779.          if (rc)
  780.            ShowMessageBox(hwnd, IDMSG_INK_WIDTH_SET, szTempString);
  781.          else
  782.            ShowMessageBox(hwnd, IDMSG_MESSAGE_FAIL, pszChosenItem);
  783.        }
  784.  
  785.  
  786.      break;
  787.  
  788.    case SKM_SET_CTL_INK_COLOR:           /* Execute SKM_SET_CTL_INK_COLOR    */
  789.      /*************************************************/
  790.      /* First, Query the current color to init color  */
  791.      /* selection button to current color             */
  792.      /*************************************************/
  793.      lColorReturn = (COLOR) WinSendMsg(hSKETCHControl,
  794.                            SKM_QUERY_CTL_INK_COLOR,
  795.                            NULL, NULL);
  796.      if (lColorReturn == CLR_ERROR)
  797.        ShowMessageBox(hwnd, IDMSG_MESSAGE_FAIL, pszChosenItem);
  798.      else
  799.      {
  800.      /***************************************/
  801.      /* Prompt User for color to change to. */
  802.      /***************************************/
  803.      usResult =  WinDlgBox(HWND_DESKTOP,         /* place anywhere on desktop     */
  804.                            hwnd,                 /* owned by frame                */
  805.                            (PFNWP) ColorDlgProc, /* Address of color procedure    */
  806.                            0L,                   /* Module handle                 */
  807.                            IDD_COLORSELECTION,   /* Dialog identifier in resource */
  808.                            &lColorReturn);       /* create parms                  */
  809.  
  810.      /***************************************/
  811.      /* Change to selected color.           */
  812.      /***************************************/
  813.      if (usResult == DID_OK)
  814.        {
  815.          rc = (BOOL) WinSendMsg(hSKETCHControl,
  816.                                 SKM_SET_CTL_INK_COLOR,
  817.                                 MPFROMLONG(lColorReturn), NULL);
  818.          if (rc)
  819.            {
  820.              GetColorString(lColorReturn, (PSZ) &szStrokeColor);/* get color strng*/
  821.              ShowMessageBox(hwnd, IDMSG_INK_COLOR_SET, szStrokeColor);
  822.            }
  823.          else
  824.            ShowMessageBox(hwnd, IDMSG_MESSAGE_FAIL, pszChosenItem);
  825.        }
  826.      }
  827.      break;
  828.  
  829.    case SKM_SET_CTL_INVISIBLE_MODE:    /* Execute SKM_SET_CTL_INVISIBLE_MODE */
  830.      /***************************************/
  831.      /* First, is ink invisible or visible? */
  832.      /***************************************/
  833.      usInvisible =   (USHORT) WinSendMsg(hSKETCHControl,
  834.                                          SKM_QUERY_CTL_INVISIBLE_MODE,
  835.                                          NULL, NULL);
  836.  
  837.      /****************************************/
  838.      /* Prompt User for visible or invisible */
  839.      /****************************************/
  840.      usResult =  WinDlgBox(HWND_DESKTOP,          /* place anywhere on desktop     */
  841.                            hwnd,                  /* owned by frame                */
  842.                            (PFNWP) VisibleDlgProc,/* Address of visible procedure  */
  843.                            0L,                    /* Module handle                 */
  844.                            IDD_VISIBLE,           /* Dialog identifier in resource */
  845.                            &usInvisible);           /* create parms                  */
  846.  
  847.  
  848.      /***************************************/
  849.      /* Change to visible or invisible.     */
  850.      /***************************************/
  851.      if (usResult == DID_OK)
  852.        {
  853.          rc =  (BOOL) WinSendMsg(hSKETCHControl,
  854.                                  SKM_SET_CTL_INVISIBLE_MODE,
  855.                                  MPFROMSHORT(usInvisible), NULL);
  856.          if (rc == FALSE)
  857.            ShowMessageBox(hwnd, IDMSG_MESSAGE_FAIL, pszChosenItem);
  858.        }
  859.      break;
  860.  
  861.    case SKM_RENDER_TO_CLIPBOARD:             /* Execute SKM_RENDER_TO_CLIPBOARD */
  862.      rc = (BOOL) WinSendMsg(hSKETCHControl,
  863.                             SKM_RENDER_TO_CLIPBOARD,
  864.                             NULL, NULL);
  865.      if( rc == FALSE )
  866.        ShowMessageBox(hwnd, IDMSG_MESSAGE_FAIL, pszChosenItem);
  867.      break;
  868.  
  869.    case SKM_QUERY_CTL_STROKE_COUNT:
  870.      ulStrokeCount =  (ULONG) WinSendMsg(hSKETCHControl,
  871.                                        SKM_QUERY_CTL_STROKE_COUNT,
  872.                                        NULL, NULL);
  873.      sprintf(szTempString, "%ld", ulStrokeCount);/* put stroke count in string*/
  874.      ShowMessageBox(hwnd, IDMSG_STROKE_COUNT, szTempString); /* show stroke count */
  875.      break;
  876.  
  877.  
  878.    case SKM_SET_STROKE_INK_COLOR:
  879.     /************************************/
  880.     /*  Ask user what stroke to change. */
  881.     /************************************/
  882.      usResult = WinDlgBox(HWND_DESKTOP,                /* place anywhere on desktop    */
  883.                           hwnd,                        /* owned by frame               */
  884.                           (PFNWP) GetStrokeNumberProc, /* Address of procedure         */
  885.                           0L,                          /* Module handle                */
  886.                           IDD_GETSTROKENUMBER,         /* Dialog identifier in resource*/
  887.                           &ulStrokeNumber);            /* Return Stroke chosen         */
  888.  
  889.      if (usResult == DID_OK)
  890.        {
  891.  
  892.          /************************/
  893.          /* Color Selection Init */
  894.          /************************/
  895.          lColorReturn = (COLOR) WinSendMsg(hSKETCHControl,
  896.                                           SKM_QUERY_STROKE_INK_COLOR,
  897.                                           MPFROMLONG(ulStrokeNumber), /* stroke number  */
  898.                                           NULL);
  899.          if (lColorReturn == CLR_ERROR)
  900.            ShowMessageBox(hwnd, IDMSG_MESSAGE_FAIL, pszChosenItem);
  901.          else
  902.            {
  903.            usResult =  WinDlgBox(HWND_DESKTOP,         /* place anywhere on desktop     */
  904.                                  hwnd,                 /* owned by frame                */
  905.                                  (PFNWP) ColorDlgProc, /* Address of Color procedure    */
  906.                                  0L,                   /* Module handle                 */
  907.                                  IDD_COLORSELECTION,   /* Dialog identifier in resource */
  908.                                  &lColorReturn);       /* create parms                  */
  909.  
  910.            if (usResult == DID_OK)
  911.              {
  912.  
  913.                /************************/
  914.                /* Set Stroke Color.    */
  915.                /************************/
  916.                rc = (BOOL) WinSendMsg(hSKETCHControl,
  917.                                       SKM_SET_STROKE_INK_COLOR,
  918.                                       MPFROMLONG(ulStrokeNumber), /* stroke number */
  919.                                       MPFROMP(lColorReturn) );    /* color         */
  920.                if (rc)
  921.                  {
  922.                    GetColorString(lColorReturn, (PSZ) &szStrokeColor);/* get color strng*/
  923.                    sprintf(szTempString, "\nStroke #%ld = %s", ulStrokeNumber, szStrokeColor);
  924.                    ShowMessageBox(hwnd, IDMSG_STROKE_COLOR_SET, szTempString);
  925.                  }
  926.                else
  927.                  ShowMessageBox(hwnd, IDMSG_MESSAGE_FAIL, pszChosenItem);
  928.              } /* end color chosen    */
  929.            }
  930.        } /* end chose Stroke            */
  931.      break;
  932.  
  933.    case SKM_SET_STROKE_INK_WIDTH:
  934.     /************************************/
  935.     /*  Ask user what stroke to change. */
  936.     /************************************/
  937.      usResult = WinDlgBox(HWND_DESKTOP,      /* place anywhere on desktop    */
  938.                      hwnd,                   /* owned by frame               */
  939.                      (PFNWP) GetStrokeNumberProc,   /* Address of procedure  */
  940.                      0L,                     /* Module handle                */
  941.                      IDD_GETSTROKENUMBER,    /* Dialog identifier in resource*/
  942.                      &ulStrokeNumber);       /* Return stroke number         */
  943.  
  944.      if (usResult == DID_OK)
  945.        {
  946.          /***************************************/
  947.          /*  Ask user what to set the width to. */
  948.          /***************************************/
  949.          usResult =  WinDlgBox(HWND_DESKTOP,           /* place anywhere on desktop               */
  950.                                      hwnd,                       /* owned by frame                */
  951.                                       (PFNWP) WidthDlgProc,      /* Address of width procedure    */
  952.                                         0L,                      /* Module handle                 */
  953.                                           IDD_GETWIDTH,          /* Dialog identifier in resource */
  954.                                             &ulWidth);
  955.  
  956.          if (usResult == DID_OK)
  957.            {
  958.              /****************************/
  959.              /*  Set the stroke width.   */
  960.              /****************************/
  961.              rc = (BOOL) WinSendMsg(hSKETCHControl,
  962.                                     SKM_SET_STROKE_INK_WIDTH,
  963.                                     MPFROMLONG(ulStrokeNumber), /* stroke number  */
  964.                                     MPFROMLONG(ulWidth) );     /* width          */
  965.              if (rc)
  966.                {
  967.                  sprintf(szTempString, "\nStroke #%ld = %ld", ulStrokeNumber, ulWidth);
  968.                  ShowMessageBox(hwnd, IDMSG_STROKE_WIDTH_SET, szTempString);
  969.                }
  970.              else
  971.                ShowMessageBox(hwnd, IDMSG_MESSAGE_FAIL, pszChosenItem);
  972.            } /* end width chosen    */
  973.        } /* end chose Stroke            */
  974.      break;
  975.  
  976.    case SKM_GET_BITMAP:
  977.      /************************************************************/
  978.      /* First, Query the bitmap handle.                          */
  979.      /* Next, display the handle and tell user to press OK to    */
  980.      /* save the bitmpap to a file using this handle.            */
  981.      /************************************************************/
  982.      hBitmap = (HBITMAP)WinSendMsg(hSKETCHControl, SKM_GET_BITMAP, NULL, NULL);
  983.      sprintf(szTempString, "%ld.\n", hBitmap);      /* put handle in string  */
  984.      if (MBID_OK == ShowMessageBox(hwnd, IDMSG_BITMAP_HANDLE_SAVE,
  985.                                     szTempString) )
  986.        {
  987.          SaveBmpInFile(hwnd, hBitmap);
  988.        }
  989.    break;
  990.  
  991.    case SKM_QUERY_BITMAP_SIZE:
  992.      ulBitmapSize = (ULONG) WinSendMsg(hSKETCHControl,
  993.                                        SKM_QUERY_BITMAP_SIZE, NULL, NULL);
  994.  
  995.      if (ulBitmapSize)
  996.        {
  997.  
  998.          sSizeX = LOUSHORT(ulBitmapSize);  /* size in pixels of X direction  */
  999.          sSizeY = HIUSHORT(ulBitmapSize);  /* size in pixels of Y direction  */
  1000.          sprintf(szTempString, "\nX direction = %d\nY direction = %d", sSizeX, sSizeY);
  1001.          ShowMessageBox(hwnd, IDMSG_BITMAP_SIZE_QUERY, szTempString);
  1002.  
  1003.        }
  1004.      else
  1005.        ShowMessageBox(hwnd, IDMSG_MESSAGE_FAIL, pszChosenItem);
  1006.  
  1007.    break;
  1008.  
  1009.    case SKM_QUERY_STROKE_LENGTH:
  1010.     /************************************/
  1011.     /*  Ask user what stroke to query.  */
  1012.     /************************************/
  1013.      usResult = WinDlgBox(HWND_DESKTOP,      /* place anywhere on desktop    */
  1014.                      hwnd,                   /* owned by frame               */
  1015.                      (PFNWP) GetStrokeNumberProc,   /* Address of procedure  */
  1016.                      0L,                     /* Module handle                */
  1017.                      IDD_GETSTROKENUMBER,    /* Dialog identifier in resource*/
  1018.                      &ulStrokeNumber);       /* Return stroke number         */
  1019.  
  1020.      if (usResult == DID_OK)
  1021.        {
  1022.          /******************************/
  1023.          /* Query the stroke's length. */
  1024.          /******************************/
  1025.          ulStrokeLength = (ULONG) WinSendMsg(hSKETCHControl,
  1026.                                              SKM_QUERY_STROKE_LENGTH,
  1027.                                              MPFROMLONG(ulStrokeNumber),
  1028.                                              NULL);
  1029.  
  1030.          sprintf(szTempString, "\nStroke #%ld = %ld", ulStrokeNumber, ulStrokeLength);
  1031.          ShowMessageBox(hwnd, IDMSG_STROKE_LENGTH_QUERY, szTempString);
  1032.        }
  1033.  
  1034.    break;
  1035.  
  1036.    case SKM_QUERY_STROKE_DATA:
  1037.     /************************************/
  1038.     /*  Ask user what stroke to query.  */
  1039.     /************************************/
  1040.      usResult = WinDlgBox(HWND_DESKTOP,      /* place anywhere on desktop    */
  1041.                      hwnd,                   /* owned by frame               */
  1042.                      (PFNWP) GetStrokeNumberProc,   /* Address of procedure  */
  1043.                      0L,                     /* Module handle                */
  1044.                      IDD_GETSTROKENUMBER,    /* Dialog identifier in resource*/
  1045.                      &ulStrokeNumber);       /* Return stroke number         */
  1046.  
  1047.      if (usResult == DID_OK)
  1048.        {
  1049.          /*******************************/
  1050.          /*  Query the stroke's length. */
  1051.          /*******************************/
  1052.          ulStrokeLength = (LONG) WinSendMsg(hSKETCHControl,
  1053.                                             SKM_QUERY_STROKE_LENGTH,
  1054.                                             MPFROMLONG(ulStrokeNumber),
  1055.                                             NULL);
  1056.  
  1057.          /*******************************************************/
  1058.          /* Allocate a buffer (non-shared) based on that size.  */
  1059.          /*******************************************************/
  1060.          pStrokeData = malloc(ulStrokeLength);
  1061.          if (!pStrokeData)
  1062.            {
  1063.             sprintf(szTempString, "%ld", ulStrokeNumber);/* current stroke num */
  1064.             ShowMessageBox(hwnd, IDMSG_MEMORY_FAIL_GETSTROKE, szTempString);
  1065.            }
  1066.          else
  1067.            {
  1068.  
  1069.              /*******************************/
  1070.              /* Get the Stroke information. */
  1071.              /*******************************/
  1072.              rc = (BOOL) WinSendMsg(hSKETCHControl,
  1073.                                     SKM_QUERY_STROKE_DATA,
  1074.                                     MPFROMLONG(ulStrokeNumber),
  1075.                                     MPFROMP(pStrokeData) );
  1076.  
  1077.              if( rc )
  1078.                {
  1079.                  /******************************************/
  1080.                  /* Display some of the Stroke Information */
  1081.                  /******************************************/
  1082.                  WinDlgBox(HWND_DESKTOP,      /* place anywhere on desktop    */
  1083.                            hwnd,              /* owned by frame               */
  1084.                            (PFNWP) DisplayStrokeInfoDlgProc,  /* Proc Address */
  1085.                            0L,                /* Module handle                */
  1086.                            IDD_STROKE_INFO,   /* Dialog identifier in resource*/
  1087.                            &ulStrokeNumber);  /* Initialization data          */
  1088.  
  1089.                }
  1090.              else
  1091.                ShowMessageBox(hwnd, IDMSG_MESSAGE_FAIL, pszChosenItem);
  1092.  
  1093.              free(pStrokeData);
  1094.            }
  1095.        }
  1096.    break;
  1097.  
  1098.    case SKM_QUERY_STROKE_INK_COLOR:
  1099.     /************************************/
  1100.     /*  Ask user what stroke to query.  */
  1101.     /************************************/
  1102.      usResult = WinDlgBox(HWND_DESKTOP,      /* place anywhere on desktop    */
  1103.                      hwnd,                   /* owned by frame               */
  1104.                      (PFNWP) GetStrokeNumberProc,   /* Address of procedure  */
  1105.                      0L,                     /* Module handle                */
  1106.                      IDD_GETSTROKENUMBER,    /* Dialog identifier in resource*/
  1107.                      &ulStrokeNumber);       /* Return stroke number         */
  1108.  
  1109.      if (usResult == DID_OK)
  1110.        {
  1111.          /****************************/
  1112.          /*  Query the stroke color. */
  1113.          /****************************/
  1114.          lColorReturn = (LONG) WinSendMsg(hSKETCHControl,
  1115.                                SKM_QUERY_STROKE_INK_COLOR,
  1116.                                MPFROMLONG(ulStrokeNumber), /* stroke number  */
  1117.                                NULL );
  1118.  
  1119.          GetColorString(lColorReturn,(PSZ) &szStrokeColor);/* get color strng*/
  1120.          sprintf(szTempString, "\nStroke #%ld = %s", ulStrokeNumber, szStrokeColor);
  1121.          ShowMessageBox(hwnd, IDMSG_STROKE_COLOR_QUERY, szTempString);
  1122.        } /* end Stroke Number chosen    */
  1123.    break;
  1124.  
  1125.    case SKM_QUERY_STROKE_INK_WIDTH:
  1126.     /************************************/
  1127.     /*  Ask user what stroke to query.  */
  1128.     /************************************/
  1129.      usResult = WinDlgBox(HWND_DESKTOP,      /* place anywhere on desktop    */
  1130.                      hwnd,                   /* owned by frame               */
  1131.                      (PFNWP) GetStrokeNumberProc,   /* Address of procedure  */
  1132.                      0L,                     /* Module handle                */
  1133.                      IDD_GETSTROKENUMBER,    /* Dialog identifier in resource*/
  1134.                      &ulStrokeNumber);       /* Return Stroke Number         */
  1135.  
  1136.      if (usResult == DID_OK)
  1137.        {
  1138.          /************************************/
  1139.          /* Query the stroke ink width.      */
  1140.          /************************************/
  1141.          ulWidth = (ULONG) WinSendMsg(hSKETCHControl,
  1142.                            SKM_QUERY_STROKE_INK_WIDTH,
  1143.                            MPFROMLONG(ulStrokeNumber), /* stroke number  */
  1144.                            NULL);
  1145.          if (ulWidth)
  1146.            {
  1147.              sprintf(szTempString, "\nStroke #%ld = %ld", ulStrokeNumber, ulWidth);
  1148.              ShowMessageBox(hwnd, IDMSG_STROKE_WIDTH_QUERY, szTempString);
  1149.            }
  1150.          else
  1151.            ShowMessageBox(hwnd, IDMSG_MESSAGE_FAIL, pszChosenItem);
  1152.        } /* end choose Stroke Number    */
  1153.    break;
  1154.  
  1155.  
  1156.  
  1157.    case SKM_SET_CTL_AUXDATA_MODE:
  1158.      /****************************************/
  1159.      /* Prompt User for all aux data or none */
  1160.      /****************************************/
  1161.      usResult =  WinDlgBox(HWND_DESKTOP,          /* place anywhere on desktop     */
  1162.                            hwnd,                  /* owned by frame                */
  1163.                            (PFNWP) AllNoneAuxDlgProc,/* Address of proc            */
  1164.                            0L,                    /* Module handle                 */
  1165.                            IDD_AUX,               /* Dialog identifier in resource */
  1166.                            &usAuxReturn);         /* create parms     */
  1167.  
  1168.  
  1169.      /***************************************/
  1170.      /* Change to visible or invisible.     */
  1171.      /***************************************/
  1172.      if (usResult == DID_OK)
  1173.        {
  1174.          usAux = usAuxReturn;  /* set or change aux flag only if OK pressed. */
  1175.         /**********************************************************/
  1176.         /* Send so subsequent strokes will retrieve all the aux   */
  1177.         /* data or none of the aux data.                          */
  1178.         /**********************************************************/
  1179.         if (usAux)
  1180.           ulAuxData = ADF_ALL;
  1181.         else
  1182.           ulAuxData = 0;
  1183.         rc = (BOOL) WinSendMsg(hSKETCHControl,
  1184.                                SKM_SET_CTL_AUXDATA_MODE,
  1185.                                MPFROMLONG(ulAuxData),
  1186.                                NULL);
  1187.         if (rc)
  1188.           {
  1189.             if (usAux)
  1190.               ShowMessageBox(hwnd, IDMSG_AUX_ALL_SET, NULL);
  1191.             else
  1192.               ShowMessageBox(hwnd, IDMSG_AUX_NONE_SET, NULL);
  1193.           }
  1194.         else
  1195.            ShowMessageBox(hwnd, IDMSG_MESSAGE_FAIL, pszChosenItem);
  1196.        } /* end if aux all or none selection was made. */
  1197.  
  1198.    break;
  1199.  
  1200.    case SKN_INK_COLOR_CHANGE:
  1201.      /*******************************************************************/
  1202.      /* Change color to user selection to cause an SKN_COLOR_CHANGE     */
  1203.      /* notification to be sent.                                        */
  1204.      /*******************************************************************/
  1205.      lColorReturn = (COLOR) WinSendMsg(hSKETCHControl, SKM_QUERY_CTL_INK_COLOR,
  1206.                                      NULL, NULL); /* get current color       */
  1207.      if (lColorReturn == CLR_ERROR)
  1208.        ShowMessageBox(hwnd, IDMSG_MESSAGE_FAIL, pszChosenItem);
  1209.      else
  1210.      {
  1211.      usResult =  WinDlgBox(HWND_DESKTOP,           /* place anywhere on desktop */
  1212.                        hwnd,                       /* owned by frame            */
  1213.                         (PFNWP) ColorDlgProc,      /* Address of Color procedure */
  1214.                           0L,                      /* Module handle              */
  1215.                             IDD_COLORSELECTION,    /* Dialog identifier in resource */
  1216.                              &lColorReturn);        /* create parms               */
  1217.      if (usResult == DID_OK)
  1218.        {
  1219.  
  1220.          /******************************************************/
  1221.          /* Query the Color, if different from selected        */
  1222.          /* color, show the notification sent from the Control */
  1223.          /******************************************************/
  1224.          lColorCompare = (COLOR) WinSendMsg(hSKETCHControl,
  1225.                                            SKM_QUERY_CTL_INK_COLOR,
  1226.                                            NULL, NULL);
  1227.  
  1228.          if (lColorCompare!= lColorReturn)
  1229.            {
  1230.  
  1231.              bLookAtNotification = TRUE;    /* Display the notification message  */
  1232.              rc = (BOOL) WinSendMsg(hSKETCHControl, SKM_SET_CTL_INK_COLOR,
  1233.                                     MPFROMLONG(lColorReturn), NULL);
  1234.              if (rc == FALSE )
  1235.                {
  1236.                  ShowMessageBox(hwnd, IDMSG_MESSAGE_FAIL, pszChosenItem);
  1237.                  bLookAtNotification = FALSE;
  1238.                }
  1239.            }
  1240.        }
  1241.      }
  1242.      break;
  1243.  
  1244.    case SKN_INK_WIDTH_CHANGE:
  1245.      /*******************************************************************/
  1246.      /* Change width to user selection to cause an SKN_WIDTH_CHANGE     */
  1247.      /* notification to be sent.                                        */
  1248.      /*******************************************************************/
  1249.      usResult = WinDlgBox(HWND_DESKTOP,      /* place anywhere on desktop    */
  1250.                      hwnd,                   /* owned by frame               */
  1251.                      (PFNWP) WidthDlgProc,   /* Address of width procedure   */
  1252.                      0L,                     /* Module handle                */
  1253.                      IDD_GETWIDTH,           /* Dialog identifier in resource*/
  1254.                      &ulWidth);              /* Return Width                 */
  1255.  
  1256.      if (usResult == DID_OK)
  1257.        {
  1258.          /******************************************************/
  1259.          /* Query the Width, if different from selected        */
  1260.          /* width, show the notification sent from the Control */
  1261.          /******************************************************/
  1262.          ulWidthCompare = (ULONG) WinSendMsg(hSKETCHControl,
  1263.                                              SKM_QUERY_CTL_INK_WIDTH,
  1264.                                              NULL, NULL);
  1265.          if (ulWidthCompare != ulWidth)
  1266.            {
  1267.  
  1268.              bLookAtNotification = TRUE;    /* Display notification message  */
  1269.              rc = (BOOL) WinSendMsg(hSKETCHControl,
  1270.                                     SKM_SET_CTL_INK_WIDTH,
  1271.                                     MPFROMLONG(ulWidth), NULL);
  1272.              if (rc == FALSE )
  1273.                {
  1274.                  ShowMessageBox(hwnd, IDMSG_MESSAGE_FAIL, pszChosenItem);
  1275.                  bLookAtNotification = FALSE;
  1276.                }
  1277.            }
  1278.        }
  1279.      break;
  1280.  
  1281.    case SKN_STROKE_ADD:
  1282.      /*******************************************************************/
  1283.      /* When user makes a stroke, prompt will ask if really want to add */
  1284.      /*******************************************************************/
  1285.      bLookAtNotification = TRUE;
  1286.      break;
  1287.  
  1288.    case SKN_STROKE_UNDO:
  1289.      /*******************************************************************/
  1290.      /* Issue an SKM_UNDO_STROKE if there is a stroke to undo.          */
  1291.      /*******************************************************************/
  1292.      ulStrokeCount =  (ULONG) WinSendMsg(hSKETCHControl,
  1293.                                          SKM_QUERY_CTL_STROKE_COUNT,
  1294.                                          NULL, NULL);
  1295.      if( ulStrokeCount)
  1296.        {
  1297.          bLookAtNotification = TRUE;
  1298.          WinSendMsg(hSKETCHControl,
  1299.                     SKM_UNDO_LAST_STROKE,
  1300.                     NULL, NULL);
  1301.        }
  1302.      else
  1303.        ShowMessageBox(hwnd, IDMSG_NOTHING_UNDO, NULL);
  1304.      break;
  1305.  
  1306.    case SKN_CONTROL_CLEARED:
  1307.      /*******************************************************************/
  1308.      /* Issue an SKM_DELETE_ALL_STROKES if there is a stroke to clear.  */
  1309.      /*******************************************************************/
  1310.      ulStrokeCount =  (LONG) WinSendMsg(hSKETCHControl,
  1311.                                         SKM_QUERY_CTL_STROKE_COUNT,
  1312.                                         NULL, NULL);
  1313.  
  1314.      if( ulStrokeCount)
  1315.        {
  1316.          bLookAtNotification = TRUE;
  1317.          WinSendMsg(hSKETCHControl,
  1318.                     SKM_DELETE_ALL_STROKES,
  1319.                     NULL, NULL);
  1320.        }
  1321.      else
  1322.        ShowMessageBox(hwnd, IDMSG_NOTHING_CLEAR, NULL);
  1323.      break;
  1324.  
  1325.  
  1326.  } /* end switch */
  1327.  
  1328. }
  1329.  
  1330. /****************************************************************************/
  1331. /*  Name:   GetColorString                                                  */
  1332. /*                                                                          */
  1333. /*  Description : Match the color to it's coordinating color string.        */
  1334. /*                                                                          */
  1335. /*  Parameters :  LONG      - number of the color                           */
  1336. /*                char *    - string to return the actual color string in   */
  1337. /*                                                                          */
  1338. /*  1/93 CPS                                                                */
  1339. /****************************************************************************/
  1340. VOID GetColorString(LONG ColNum, PSZ szColor)
  1341. {
  1342.  
  1343.   switch (ColNum)
  1344.     {
  1345.     case CLR_WHITE:
  1346.       strcpy(szColor, "WHITE");
  1347.       break;
  1348.     case CLR_BLUE:
  1349.       strcpy(szColor, "BLUE");
  1350.       break;
  1351.     case CLR_RED:
  1352.       strcpy(szColor, "RED");
  1353.       break;
  1354.     case CLR_PINK:
  1355.       strcpy(szColor, "PINK");
  1356.       break;
  1357.     case CLR_GREEN:
  1358.       strcpy(szColor, "GREEN");
  1359.       break;
  1360.     case CLR_CYAN:
  1361.       strcpy(szColor, "CYAN");
  1362.       break;
  1363.     case CLR_YELLOW:
  1364.       strcpy(szColor, "YELLOW");
  1365.       break;
  1366.     case CLR_BLACK:
  1367.       strcpy(szColor, "BLACK");
  1368.       break;
  1369.     case CLR_DARKGRAY:
  1370.       strcpy(szColor, "DARK GRAY");
  1371.       break;
  1372.     case CLR_DARKBLUE:
  1373.       strcpy(szColor, "DARK BLUE");
  1374.       break;
  1375.     case CLR_DARKRED:
  1376.       strcpy(szColor, "DARK RED");
  1377.       break;
  1378.     case CLR_DARKPINK:
  1379.       strcpy(szColor, "DARK PINK");
  1380.       break;
  1381.     case CLR_DARKGREEN:
  1382.       strcpy(szColor, "DARK GREEN");
  1383.       break;
  1384.     case CLR_DARKCYAN:
  1385.       strcpy(szColor, "DARK CYAN");
  1386.       break;
  1387.     case CLR_BROWN:
  1388.       strcpy(szColor, "BROWN");
  1389.       break;
  1390.     case CLR_PALEGRAY:
  1391.       strcpy(szColor, "PALE GRAY");
  1392.       break;
  1393.     default:
  1394.       strcpy(szColor, "UNKNOWN");
  1395.  
  1396.     }
  1397. }  /* end proc */
  1398.  
  1399. /***************************************************************************/
  1400. /*  Name : ColorDlgProc                                                    */
  1401. /*                                                                         */
  1402. /*  Description : Get desired color from the user.                         */
  1403. /*                                                                         */
  1404. /* Parameters   : hwnd - Window handle to which message is addressed       */
  1405. /*                msg - Message type                                       */
  1406. /*                mp1 - First message parameter                            */
  1407. /*                mp2 - Second message parameter                           */
  1408. /*                                                                         */
  1409. /*                                                                         */
  1410. /***************************************************************************/
  1411. MRESULT EXPENTRY ColorDlgProc( HWND hwndDlg, ULONG msg, MPARAM mp1, MPARAM mp2 )
  1412. {
  1413.  
  1414. HWND hwndButton;                 /* handle of current button                */
  1415. static PLONG plColorSelection;   /* pointer to actual color variable        */
  1416. static LONG lColorTemp;          /* temporary color                         */
  1417.  
  1418.  
  1419.   switch ( msg )
  1420.   {
  1421.  
  1422.     case WM_INITDLG:                /* Get pointer to actual color variable */
  1423.       plColorSelection = PVOIDFROMMP(mp2);
  1424.  
  1425.       switch ( *plColorSelection)      /* find the handle of the current choice */
  1426.       {
  1427.          case CLR_WHITE:
  1428.            hwndButton = WinWindowFromID(hwndDlg, IDC_WHITE);
  1429.            break;
  1430.  
  1431.          case CLR_BLUE:
  1432.            hwndButton = WinWindowFromID(hwndDlg, IDC_BLUE);
  1433.            break;
  1434.  
  1435.          case CLR_RED:
  1436.            hwndButton = WinWindowFromID(hwndDlg, IDC_RED);
  1437.            break;
  1438.  
  1439.          case CLR_PINK:
  1440.            hwndButton = WinWindowFromID(hwndDlg, IDC_PINK);
  1441.            break;
  1442.  
  1443.          case CLR_GREEN:
  1444.            hwndButton = WinWindowFromID(hwndDlg, IDC_GREEN);
  1445.            break;
  1446.  
  1447.          case CLR_CYAN:
  1448.            hwndButton = WinWindowFromID(hwndDlg, IDC_CYAN);
  1449.            break;
  1450.  
  1451.          case CLR_YELLOW:
  1452.            hwndButton = WinWindowFromID(hwndDlg, IDC_YELLOW);
  1453.            break;
  1454.  
  1455.          case CLR_BLACK:
  1456.            hwndButton = WinWindowFromID(hwndDlg, IDC_BLACK);
  1457.            break;
  1458.  
  1459.          case CLR_DARKGRAY:
  1460.            hwndButton = WinWindowFromID(hwndDlg, IDC_DARKGRAY);
  1461.            break;
  1462.  
  1463.          case CLR_DARKBLUE:
  1464.            hwndButton = WinWindowFromID(hwndDlg, IDC_DARKBLUE);
  1465.            break;
  1466.  
  1467.          case CLR_DARKRED:
  1468.            hwndButton = WinWindowFromID(hwndDlg, IDC_DARKRED);
  1469.            break;
  1470.  
  1471.          case CLR_DARKPINK:
  1472.            hwndButton = WinWindowFromID(hwndDlg, IDC_DARKPINK);
  1473.            break;
  1474.  
  1475.          case CLR_DARKGREEN:
  1476.            hwndButton = WinWindowFromID(hwndDlg, IDC_DARKGREEN);
  1477.            break;
  1478.  
  1479.          case CLR_DARKCYAN:
  1480.            hwndButton = WinWindowFromID(hwndDlg, IDC_DARKCYAN);
  1481.            break;
  1482.  
  1483.          case CLR_BROWN:
  1484.            hwndButton = WinWindowFromID(hwndDlg, IDC_BROWN);
  1485.            break;
  1486.  
  1487.          case CLR_PALEGRAY:
  1488.            hwndButton = WinWindowFromID(hwndDlg, IDC_PALEGRAY);
  1489.            break;
  1490.  
  1491.       } /* end switch */
  1492.       WinSendMsg (hwndButton, BM_CLICK, 0L, 0L); /* turn on current choice */
  1493.       return ( (MRESULT) TRUE);  /* to indicate we changed focus */
  1494.  
  1495.     case WM_CONTROL:
  1496.       if (SHORT2FROMMP (mp1) == BN_CLICKED)
  1497.       {
  1498.       /* track the currently selected button */
  1499.         switch (SHORT1FROMMP(mp1) )
  1500.         {
  1501.  
  1502.          case IDC_WHITE:
  1503.            lColorTemp = CLR_WHITE;
  1504.            break;
  1505.  
  1506.          case IDC_BLUE:
  1507.            lColorTemp = CLR_BLUE;
  1508.            break;
  1509.  
  1510.          case IDC_RED:
  1511.            lColorTemp = CLR_RED;
  1512.            break;
  1513.  
  1514.          case IDC_PINK:
  1515.            lColorTemp = CLR_PINK;
  1516.            break;
  1517.  
  1518.          case IDC_GREEN:
  1519.            lColorTemp = CLR_GREEN;
  1520.            break;
  1521.  
  1522.          case IDC_CYAN:
  1523.            lColorTemp = CLR_CYAN;
  1524.            break;
  1525.  
  1526.          case IDC_YELLOW:
  1527.            lColorTemp = CLR_YELLOW;
  1528.            break;
  1529.  
  1530.          case IDC_BLACK:
  1531.            lColorTemp = CLR_BLACK;
  1532.            break;
  1533.  
  1534.          case IDC_DARKGRAY:
  1535.            lColorTemp = CLR_DARKGRAY;
  1536.            break;
  1537.  
  1538.          case IDC_DARKBLUE:
  1539.            lColorTemp = CLR_DARKBLUE;
  1540.            break;
  1541.  
  1542.          case IDC_DARKRED:
  1543.            lColorTemp = CLR_DARKRED;
  1544.            break;
  1545.  
  1546.          case IDC_DARKPINK:
  1547.            lColorTemp = CLR_DARKPINK;
  1548.            break;
  1549.  
  1550.          case IDC_DARKGREEN:
  1551.            lColorTemp = CLR_DARKGREEN;
  1552.            break;
  1553.  
  1554.          case IDC_DARKCYAN:
  1555.            lColorTemp = CLR_DARKCYAN;
  1556.            break;
  1557.  
  1558.          case IDC_BROWN:
  1559.            lColorTemp = CLR_BROWN;
  1560.            break;
  1561.  
  1562.          case IDC_PALEGRAY:
  1563.            lColorTemp = CLR_PALEGRAY;
  1564.            break;
  1565.  
  1566.  
  1567.         } /* end switch */
  1568.       } /* end if */
  1569.       return (MRESULT)0;
  1570.  
  1571.     case WM_COMMAND:                    /* Posted by pushbutton or key  */
  1572.       switch( SHORT1FROMMP( mp1 ) )     /* Extract the command value    */
  1573.       {
  1574.         case DID_OK:
  1575.           *plColorSelection = lColorTemp;  /* update the actual color var */
  1576.  
  1577.           WinDismissDlg(hwndDlg, DID_OK);
  1578.           break;
  1579.  
  1580.         case DID_CANCEL:         /* The Cancel pushbutton or Escape key */
  1581.           WinDismissDlg( hwndDlg, DID_CANCEL );  /* Removes the dialog box    */
  1582.           break;
  1583.       }
  1584.       return(MRESULT)0;
  1585.  
  1586.   default:
  1587.     return WinDefDlgProc(hwndDlg, msg, mp1, mp2);
  1588.   }
  1589.  return WinDefDlgProc(hwndDlg, msg, mp1, mp2);
  1590. }
  1591. /********************** End of dialog procedure  ************************/
  1592.  
  1593. /*****************************************************************************/
  1594. /*  Name:   ShowMessageBox                                                   */
  1595. /*                                                                           */
  1596. /*  Description : Display Message to the user                                */
  1597. /*                                                                           */
  1598. /*  Concepts : Displays the Info/warning/error message box with the message  */
  1599. /*             given in idMsg retrived from the message table                */
  1600. /*             Called whever a Info/warning/error occurs and a message wishes*/
  1601. /*             to be displayed to the user.                                  */
  1602. /*                                                                           */
  1603. /*  API's : WinLoadMessage                                                   */
  1604. /*          WinAlarm                                                         */
  1605. /*          WinMessageBox                                                    */
  1606. /*                                                                           */
  1607. /*  Parameters :  hwnd      - window handle of the owner of the              */
  1608. /*                            message box                                    */
  1609. /*                idMsg     - id of message to be retrieved from             */
  1610. /*                            resource file                                  */
  1611. /*                                                                           */
  1612. /*                szExtendedMessage - extended message                       */
  1613. /*  Returns: USHORT                                                          */
  1614. /*                                                                           */
  1615. /*****************************************************************************/
  1616. USHORT ShowMessageBox(HWND hwnd, USHORT idMsg, PSZ szExtendedMessage)
  1617. {
  1618.   CHAR    szText[MAXTEXTLEN];
  1619.   CHAR    szTitle[240];
  1620.   USHORT  ulAlarm;
  1621.   USHORT  ulStyle;
  1622.  
  1623.   if (idMsg > IDMSG_SHOWERROR)
  1624.     {
  1625.     WinLoadMessage(hab, 0L, IDMSG_SHOWERROR, 240, (PSZ) szTitle);
  1626.     ulAlarm = WA_ERROR;
  1627.     ulStyle = MB_OK | MB_ERROR | MB_MOVEABLE;
  1628.     }
  1629.   else
  1630.   if (idMsg > IDMSG_SHOWWARNING)
  1631.     {
  1632.     WinLoadMessage(hab, 0L, IDMSG_SHOWWARNING, 240, (PSZ) szTitle);
  1633.     ulAlarm = WA_WARNING;
  1634.     ulStyle = MB_OKCANCEL | MB_ICONEXCLAMATION | MB_MOVEABLE;
  1635.     }
  1636.   else
  1637.     {  /* Information message */
  1638.     WinLoadMessage(hab, 0L, IDMSG_SHOWINFO, 240, (PSZ) szTitle);
  1639.     ulAlarm = WA_NOTE;
  1640.     ulStyle = MB_OK | MB_INFORMATION | MB_MOVEABLE;
  1641.     }
  1642.  
  1643.   WinLoadMessage(hab, 0L, idMsg, MAXTEXTLEN, (PSZ) szText);
  1644.   WinAlarm(HWND_DESKTOP, ulAlarm);
  1645.  
  1646.   sprintf(szMessageBoxString, szText, szExtendedMessage);
  1647.  
  1648.   return(WinMessageBox(HWND_DESKTOP,
  1649.                        hwnd,
  1650.                        szMessageBoxString,
  1651.                        szTitle,
  1652.                        IDD_MSGBOX,
  1653.                        ulStyle));
  1654. }
  1655.  
  1656. /***************************************************************************/
  1657. /*  Name : VisibleDlgProc                                                  */
  1658. /*                                                                         */
  1659. /*  Description : Get Invisible or Visible Mode selection.                 */
  1660. /*                                                                         */
  1661. /* Parameters   : hwnd - Window handle to which message is addressed       */
  1662. /*                msg - Message type                                       */
  1663. /*                mp1 - First message parameter                            */
  1664. /*                mp2 - Second message parameter                           */
  1665. /*                                                                         */
  1666. /*                                                                         */
  1667. /***************************************************************************/
  1668. MRESULT EXPENTRY VisibleDlgProc( HWND hwndDlg, ULONG msg, MPARAM mp1, MPARAM mp2 )
  1669. {
  1670.  
  1671. HWND hwndButton;                 /* handle of current button                */
  1672. static PSHORT pModeSelection;    /* pointer to actual mode variable         */
  1673. static USHORT usModeTemp;        /* temporary mode                          */
  1674.  
  1675.  
  1676.   switch ( msg )
  1677.   {
  1678.  
  1679.     case WM_INITDLG:                /* Get pointer to actual mode variable   */
  1680.       pModeSelection =  PVOIDFROMMP(mp2);
  1681.  
  1682.       switch ( *pModeSelection)     /* set button to whatever is active.     */
  1683.       {
  1684.          case TRUE:
  1685.            hwndButton = WinWindowFromID(hwndDlg, IDC_INVISIBLE);
  1686.            break;
  1687.  
  1688.          case FALSE:
  1689.            hwndButton = WinWindowFromID(hwndDlg, IDC_VISIBLE);
  1690.            break;
  1691.  
  1692.  
  1693.       } /* end switch */
  1694.       WinSendMsg (hwndButton, BM_CLICK, 0L, 0L); /* turn on current choice */
  1695.       return ( (MRESULT) TRUE);  /* to indicate we changed focus */
  1696.  
  1697.     case WM_CONTROL:
  1698.       if (SHORT2FROMMP (mp1) == BN_CLICKED)
  1699.       {
  1700.       /* track the currently selected button */
  1701.         switch (SHORT1FROMMP(mp1) )
  1702.         {
  1703.  
  1704.          case IDC_INVISIBLE:
  1705.            usModeTemp = TRUE;
  1706.            break;
  1707.  
  1708.          case IDC_VISIBLE:
  1709.            usModeTemp = FALSE;
  1710.            break;
  1711.  
  1712.         } /* end switch */
  1713.       } /* end if */
  1714.       return (MRESULT)0;
  1715.  
  1716.     case WM_COMMAND:                    /* Posted by pushbutton or key  */
  1717.       switch( SHORT1FROMMP( mp1 ) )     /* Extract the command value    */
  1718.       {
  1719.         case DID_OK:
  1720.           *pModeSelection = usModeTemp;    /* update the actual mode var     */
  1721.  
  1722.           WinDismissDlg(hwndDlg, DID_OK);
  1723.           break;
  1724.  
  1725.         case DID_CANCEL:         /* The Cancel pushbutton or Escape key */
  1726.           WinDismissDlg( hwndDlg, DID_CANCEL );  /* Removes the dialog box    */
  1727.           break;
  1728.       }
  1729.       return(MRESULT)0;
  1730.  
  1731.   default:
  1732.     return WinDefDlgProc(hwndDlg, msg, mp1, mp2);
  1733.   }
  1734. return WinDefDlgProc( hwndDlg, msg, mp1, mp2 );
  1735. }
  1736. /********************** End of dialog procedure  ************************/
  1737.  
  1738.  
  1739. /*****************************************************************************/
  1740. /*  Name : GetStrokeNumberProc                                               */
  1741. /*                                                                           */
  1742. /*  Description : Get stroke to be changed from the user.                    */
  1743. /*                                                                           */
  1744. /* Parameters   : hwnd - Window handle to which message is addressed         */
  1745. /*                msg - Message type                                         */
  1746. /*                mp1 - First message parameter                              */
  1747. /*                mp2 - Second message parameter                             */
  1748. /*                                                                           */
  1749. /*                                                                           */
  1750. /*****************************************************************************/
  1751. MRESULT EXPENTRY GetStrokeNumberProc( HWND hwndDlg, ULONG msg, MPARAM mp1, MPARAM mp2 )
  1752. {
  1753.  
  1754.        CHAR      szStroke[6];          /* Select stroke number               */
  1755. static PULONG    pulStroke;            /* Stroke                             */
  1756. static ULONG     ulStrokeTemp;
  1757.        ULONG     ulStrokeCount;        /* Check if stroke is valid stroke    */
  1758.  
  1759.   switch ( msg )
  1760.   {
  1761.  
  1762.     case WM_INITDLG:
  1763.  
  1764.        pulStroke = PVOIDFROMMP(mp2);         /* Stroke Number parm           */
  1765.  
  1766.        /****************************/
  1767.        /*  Set field length limit. */
  1768.        /****************************/
  1769.        WinSendMsg( WinWindowFromID( hwndDlg, IDC_STROKEINPUT),
  1770.                    EM_SETTEXTLIMIT, (MPARAM)5, (MPARAM)0);
  1771.        break;
  1772.  
  1773.  
  1774.     case WM_COMMAND:                    /* Posted by pushbutton or key  */
  1775.       switch( SHORT1FROMMP( mp1 ) )     /* Extract the command value    */
  1776.       {
  1777.         case DID_OK:                    /* The Enter pushbutton or key. */
  1778.                                         /* WinQueryWindowText copies the*/
  1779.                                         /* contents of the entry field  */
  1780.                                         /* into szStroke                */
  1781.         WinQueryWindowText( WinWindowFromID( hwndDlg, IDC_STROKEINPUT),
  1782.                               6,
  1783.                               szStroke);
  1784.  
  1785.         ulStrokeTemp = atol(szStroke);
  1786.  
  1787.         /*******************************************/
  1788.         /*  Check that it is a valid stroke number */
  1789.         /*******************************************/
  1790.         ulStrokeCount =  (ULONG) WinSendMsg(hSKETCHControl,
  1791.                                             SKM_QUERY_CTL_STROKE_COUNT,
  1792.                                             NULL, NULL);
  1793.  
  1794.  
  1795.         if ( (ulStrokeTemp <= ulStrokeCount) && (ulStrokeTemp > 0 ) )
  1796.           {
  1797.             *pulStroke = ulStrokeTemp;       /* Return chosen stroke number */
  1798.              WinDismissDlg(hwndDlg, DID_OK);
  1799.           }
  1800.         else
  1801.           {
  1802.             ShowMessageBox(hwndDlg, IDMSG_STROKE_INVALID, szStroke);
  1803.             WinSetDlgItemText(hwndDlg, IDC_STROKEINPUT, "");
  1804.             WinSetFocus(HWND_DESKTOP, WinWindowFromID(hwndDlg, IDC_STROKEINPUT) );
  1805.           }
  1806.         break;
  1807.  
  1808.         case DID_CANCEL:         /* The Cancel pushbutton or Escape key */
  1809.           WinDismissDlg( hwndDlg, DID_CANCEL);  /* Removes the dialog box    */
  1810.           break;
  1811.       }
  1812.       break;
  1813.     default:
  1814.       return WinDefDlgProc( hwndDlg, msg, mp1, mp2 );
  1815.   }
  1816.   return (MRESULT) FALSE;
  1817. }
  1818. /********************** End of dialog procedure  ************************/
  1819.  
  1820. /****************************************************************************/
  1821. /*  Name : WidthDlgProc                                                     */
  1822. /*                                                                          */
  1823. /*  Description : Get desired width from the user.                          */
  1824. /*                                                                          */
  1825. /* Parameters   : hwnd - Window handle to which message is addressed        */
  1826. /*                msg - Message type                                        */
  1827. /*                mp1 - First message parameter                             */
  1828. /*                mp2 - Second message parameter                            */
  1829. /*                                                                          */
  1830. /*                                                                          */
  1831. /****************************************************************************/
  1832. MRESULT EXPENTRY WidthDlgProc( HWND hwndDlg, ULONG msg, MPARAM mp1, MPARAM mp2 )
  1833. {
  1834.  
  1835.  
  1836. static PULONG    pulWidth;             /* Width                              */
  1837. static ULONG     ulWidthTemp;
  1838.        CHAR      szWidth[2];           /* Stroke width selected to change    */
  1839.  
  1840.   switch ( msg )
  1841.   {
  1842.  
  1843.     case WM_INITDLG:
  1844.  
  1845.        pulWidth = PVOIDFROMMP(mp2);         /* Width Parm                   */
  1846.  
  1847.        /**************************************/
  1848.        /*  Set field length limit.           */
  1849.        /**************************************/
  1850.        WinSendMsg( WinWindowFromID( hwndDlg, IDC_WIDTHINPUT),
  1851.                    EM_SETTEXTLIMIT, (MPARAM)1, (MPARAM)0);
  1852.        break;
  1853.  
  1854.     case WM_COMMAND:                    /* Posted by pushbutton or key       */
  1855.       switch( SHORT1FROMMP( mp1 ) )     /* Extract the command value         */
  1856.       {
  1857.         case DID_OK:                    /* The Enter pushbutton or key.      */
  1858.                                         /* WinQueryWindowText copies the     */
  1859.                                         /* contents of the entry field       */
  1860.                                         /* into szWidth.                     */
  1861.           WinQueryWindowText( WinWindowFromID( hwndDlg, IDC_WIDTHINPUT),
  1862.                               2,
  1863.                               szWidth);
  1864.  
  1865.           ulWidthTemp = atol(szWidth);
  1866.           if ( (ulWidthTemp < 1) || (ulWidthTemp > 2) )
  1867.             {
  1868.               ShowMessageBox(hwndDlg, IDMSG_INK_WIDTH_SET_FAIL, NULL);
  1869.               WinSetDlgItemText(hwndDlg, IDC_WIDTHINPUT, "");
  1870.               WinSetFocus(HWND_DESKTOP, WinWindowFromID(hwndDlg, IDC_WIDTHINPUT) );
  1871.             }
  1872.           else
  1873.             {
  1874.               *pulWidth = ulWidthTemp;       /* Return chosen width          */
  1875.               WinDismissDlg(hwndDlg, DID_OK);
  1876.             }
  1877.           break;
  1878.  
  1879.         case DID_CANCEL:         /* The Cancel pushbutton or Escape key      */
  1880.           WinDismissDlg( hwndDlg, DID_CANCEL);  /* Removes the dialog box    */
  1881.           break;
  1882.       }
  1883.       break;
  1884.     default:
  1885.       return WinDefDlgProc( hwndDlg, msg, mp1, mp2 );
  1886.   }
  1887.   return (MRESULT) FALSE;
  1888. }
  1889. /********************** End of dialog procedure  ************************/
  1890.  
  1891. /*****************************************************************************/
  1892. /* InitHelp()                                                                */
  1893. /*                                                                           */
  1894. /* DESCRIPTION: Help Procedure                                               */
  1895. /*                                                                           */
  1896. /*                                                                           */
  1897. /*****************************************************************************/
  1898.  
  1899. VOID    InitHelp(VOID)
  1900. {
  1901.  
  1902.   HELPINIT      HelpInit;
  1903.  
  1904.    HelpInit.pszHelpLibraryName       = "sketsamp.hlp";
  1905.    HelpInit.pszHelpWindowTitle       = "Sketch Controls Sample Program Help";
  1906.    HelpInit.hmodHelpTableModule      = 0;
  1907.    HelpInit.hmodAccelActionBarModule = 0;
  1908.    HelpInit.phtHelpTable             = (PHELPTABLE)MAKEULONG( SKETCH_HELPTABLE, 0xffff );
  1909.  
  1910.    HelpInit.cb                       = sizeof( HELPINIT );
  1911.    HelpInit.ulReturnCode             = 0L;
  1912.    HelpInit.pszTutorialName          = (PSZ)NULL;
  1913.    HelpInit.idAccelTable             = 0L;
  1914.    HelpInit.idActionBar              = 0L;
  1915.    HelpInit.fShowPanelId             = CMIC_HIDE_PANEL_ID;
  1916.  
  1917.    if ( ! ( hwndHelp = WinCreateHelpInstance( hab, &HelpInit ) ) )
  1918.      {
  1919.  
  1920.        /***************************/
  1921.        /* Help Creation error.    */
  1922.        /***************************/
  1923.        ShowMessageBox(HWND_DESKTOP, IDMSG_NO_HELP, NULL);
  1924.  
  1925.  
  1926.      }
  1927.    else
  1928.      {
  1929.        WinAssociateHelpInstance( hwndHelp, hwndFrame );
  1930.      }
  1931.  
  1932. }
  1933.  
  1934. /****************************************************************************/
  1935. /*  Name : AllNoneAuxDlgProc                                                */
  1936. /*                                                                          */
  1937. /*  Description : Ask user if he wants ALL or NONE Auxilliary data          */
  1938. /*                                                                          */
  1939. /* Parameters   : hwnd - Window handle to which message is addressed        */
  1940. /*                msg - Message type                                        */
  1941. /*                mp1 - First message parameter                             */
  1942. /*                mp2 - Second message parameter                            */
  1943. /*                                                                          */
  1944. /*                                                                          */
  1945. /****************************************************************************/
  1946. MRESULT EXPENTRY AllNoneAuxDlgProc( HWND hwndDlg, ULONG msg, MPARAM mp1, MPARAM mp2 )
  1947. {
  1948. HWND hwndButton;                 /* handle of current button                */
  1949. static USHORT usAuxTemp;         /* temporary Aux Pointer                   */
  1950. static PSHORT pAuxSelection;     /* pointer to actual mode variable         */
  1951.  
  1952.  
  1953.   switch ( msg )
  1954.   {
  1955.  
  1956.     case WM_INITDLG:                /* Get pointer to aux var                */
  1957.       pAuxSelection =  PVOIDFROMMP(mp2);
  1958.  
  1959.  
  1960.       switch ( usAux)               /* set button to whatever is active.     */
  1961.       {
  1962.          case TRUE:
  1963.            hwndButton = WinWindowFromID(hwndDlg, IDC_ALLAUX);
  1964.            break;
  1965.  
  1966.          case FALSE:
  1967.            hwndButton = WinWindowFromID(hwndDlg, IDC_NONEAUX);
  1968.            break;
  1969.  
  1970.  
  1971.       } /* end switch */
  1972.       WinSendMsg (hwndButton, BM_CLICK, 0L, 0L); /* turn on current choice */
  1973.       return ( (MRESULT) TRUE);  /* to indicate we changed focus */
  1974.  
  1975.     case WM_CONTROL:
  1976.       if (SHORT2FROMMP (mp1) == BN_CLICKED)
  1977.       {
  1978.       /* track the currently selected button */
  1979.         switch (SHORT1FROMMP(mp1) )
  1980.         {
  1981.  
  1982.          case IDC_NONEAUX:
  1983.            usAuxTemp = FALSE;
  1984.            break;
  1985.  
  1986.          case IDC_ALLAUX:
  1987.            usAuxTemp = TRUE;
  1988.            break;
  1989.  
  1990.         } /* end switch */
  1991.       } /* end if */
  1992.       return (MRESULT)0;
  1993.  
  1994.     case WM_COMMAND:                    /* Posted by pushbutton or key  */
  1995.       switch( SHORT1FROMMP( mp1 ) )     /* Extract the command value    */
  1996.       {
  1997.         case DID_OK:
  1998.           *pAuxSelection = usAuxTemp;    /* update the actual return       */
  1999.  
  2000.           WinDismissDlg(hwndDlg, DID_OK);
  2001.           break;
  2002.  
  2003.         case DID_CANCEL:         /* The Cancel pushbutton or Escape key */
  2004.           WinDismissDlg( hwndDlg, DID_CANCEL );  /* Removes the dialog box    */
  2005.           break;
  2006.  
  2007.         case IDC_AUX_HELP:
  2008.                /********************************************************/
  2009.                /* Display the Help panel for Auxiliary data choices.   */
  2010.                /********************************************************/
  2011.                WinSendMsg(hwndHelp, HM_DISPLAY_HELP,
  2012.                                     MPFROM2SHORT(PANEL_AUX, NULL),
  2013.                                     MPFROMSHORT(HM_RESOURCEID) );
  2014.         break;
  2015.  
  2016.       }
  2017.       return(MRESULT)0;
  2018.  
  2019.   default:
  2020.     return WinDefDlgProc(hwndDlg, msg, mp1, mp2);
  2021.   }
  2022. return WinDefDlgProc( hwndDlg, msg, mp1, mp2 );
  2023. }
  2024. /********************** End of dialog procedure  ************************/
  2025.  
  2026. /****************************************************************************/
  2027. /* SaveBmpInFile  -  Save the bitmap to file on disk.                       */
  2028. /*                   User select file name.                                 */
  2029. /*  Parameters:                                                             */
  2030. /*                                                                          */
  2031. /*  Return Value:                                                           */
  2032. /*                                                                          */
  2033. /****************************************************************************/
  2034. VOID SaveBmpInFile(HWND hwndDlg, HBITMAP hBitmap)
  2035. {
  2036.   APIRET rc;                               /* return code                    */
  2037.  
  2038.   HFILE             hfBmpFile;
  2039.  
  2040.   BITMAPFILEHEADER2 bmpFileHdr2;
  2041.   PBYTE             pbBuffer = NULL;
  2042.   ULONG             ulRGBTbl;              /* buffer lengths                 */
  2043.   ULONG             ulImgData;
  2044.   ULONG             ulTotal;
  2045.   ULONG             ulBmpFileHdr2;
  2046.   PBITMAPINFO2      pbmi = NULL;           /* info structure                 */
  2047.  
  2048.   ULONG             ulBytesWritten;        /* Bytes Written to file          */
  2049.   ULONG             ulAction;
  2050.  
  2051.  
  2052.   HDC      hMemoryDC;
  2053.   HPS      hMemoryPS;
  2054.   SIZEL    sizeL;
  2055.  
  2056.  
  2057.   FILEDLG           SaveFileDlg;           /* Chose name to save bitmap      */
  2058.   char pszTitle[40] = "Enter file name to save bitmap.";
  2059.   char pszFullFile[CCHMAXPATH] = "?.bmp";
  2060.   HDIR         hdir;
  2061.   FILEFINDBUF  findbuf;
  2062.   ULONG        cFilenames;
  2063.  
  2064.   cFilenames = 1;
  2065.   hdir = HDIR_SYSTEM;
  2066.  
  2067.   /*****************************************************/
  2068.   /* First, Get name of file to save as.               */
  2069.   /*****************************************************/
  2070.   memset(&SaveFileDlg, 0, sizeof(FILEDLG) );
  2071.   SaveFileDlg.cbSize = sizeof(FILEDLG);
  2072.   SaveFileDlg.fl = FDS_SAVEAS_DIALOG | FDS_CENTER;/* Save File Dialog        */
  2073.   SaveFileDlg.pszTitle = pszTitle;                /* Dialog title string     */
  2074.   strcpy(SaveFileDlg.szFullFile, pszFullFile);    /* File name               */
  2075.  
  2076.   WinFileDlg(HWND_DESKTOP, hwndDlg, &SaveFileDlg);       /* get file name    */
  2077.  
  2078.   if (SaveFileDlg.lReturn == DID_CANCEL)
  2079.     return;
  2080.  
  2081.   /***************************************/
  2082.   /* Check if this file already exists.  */
  2083.   /* If it does give chance to cancel.   */
  2084.   /***************************************/
  2085.   rc = DosFindFirst(SaveFileDlg.szFullFile,
  2086.                     &hdir,
  2087.                     FILE_NORMAL,
  2088.                     &findbuf,
  2089.                     sizeof(findbuf),
  2090.                     &cFilenames,
  2091.                     FIL_STANDARD);
  2092.  
  2093.   DosFindClose(hdir);
  2094.  
  2095.   if (!rc)                     /* requested file name already exists. */
  2096.  
  2097.     {
  2098.       if (MBID_OK != ShowMessageBox(hwndDlg, IDMSG_BITMAP_REALLY_SAVE,
  2099.                                     SaveFileDlg.szFullFile) )
  2100.  
  2101.       return;
  2102.     }
  2103.  
  2104.  
  2105.   if( (hMemoryDC = DevOpenDC(hab, OD_MEMORY, (PSZ) "*", 0L, 0L, 0L)) != NULLHANDLE )
  2106.   {
  2107.     sizeL.cx = 0L;                               /* 0, when using GPIA_ASSOC */
  2108.     sizeL.cy = 0L;
  2109.  
  2110.     if( (hMemoryPS = GpiCreatePS( hab, hMemoryDC, &sizeL , PU_PELS | GPIT_MICRO | GPIA_ASSOC | GPIF_DEFAULT)) != NULLHANDLE )
  2111.     {
  2112.       if( GpiSetBitmap( hMemoryPS, hBitmap) == NULLHANDLE )
  2113.       {
  2114.         bmpFileHdr2.bmp2.cbFix = sizeof (BITMAPINFOHEADER2);
  2115.         GpiQueryBitmapInfoHeader(hBitmap, &bmpFileHdr2.bmp2);
  2116.  
  2117.  
  2118.         /************************************************************/
  2119.         /* Compute the size of the image_data buffer and the bitmap */
  2120.         /* information structure.                                   */
  2121.         /************************************************************/
  2122.         ulBmpFileHdr2 = sizeof (BITMAPFILEHEADER2);
  2123.  
  2124.         ulImgData = (((bmpFileHdr2.bmp2.cBitCount * bmpFileHdr2.bmp2.cx) + 31) / 32)
  2125.                        * 4 * bmpFileHdr2.bmp2.cy * bmpFileHdr2.bmp2.cPlanes;
  2126.  
  2127.         ulRGBTbl = (sizeof(RGB2) * (1 << bmpFileHdr2.bmp2.cBitCount));
  2128.  
  2129.         ulTotal = ulBmpFileHdr2 + ulImgData + ulRGBTbl;
  2130.  
  2131.         bmpFileHdr2.usType   = BFT_BMAP;
  2132.         bmpFileHdr2.cbSize   = ulTotal;
  2133.         bmpFileHdr2.xHotspot = 0;
  2134.         bmpFileHdr2.yHotspot = 0;
  2135.         bmpFileHdr2.offBits  = ulBmpFileHdr2 + ulRGBTbl;
  2136.         /*******************************************************/
  2137.         /* Allocate a buffer (non-shared) based on that size.  */
  2138.         /*******************************************************/
  2139.         pbBuffer = malloc(ulTotal);
  2140.         if (pbBuffer)
  2141.           {
  2142.             memcpy(pbBuffer, &bmpFileHdr2, sizeof(BITMAPFILEHEADER2));
  2143.             /*******************************************************/
  2144.             /* Allocate a buffer (non-shared) based on that size.  */
  2145.             /*******************************************************/
  2146.             pbmi = malloc(ulTotal);
  2147.             if (pbmi)
  2148.               {
  2149.                 pbmi = (PBITMAPINFO2) (pbBuffer +
  2150.                                        (LONG) sizeof(BITMAPFILEHEADER2) -
  2151.                                        (LONG) sizeof(BITMAPINFOHEADER2));
  2152.                 pbmi->cbFix = bmpFileHdr2.bmp2.cbFix;
  2153.                 pbmi->cPlanes = bmpFileHdr2.bmp2.cPlanes;
  2154.                 pbmi->cBitCount = bmpFileHdr2.bmp2.cBitCount;
  2155.                 GpiQueryBitmapBits(hMemoryPS,
  2156.                                    0L,
  2157.                                    (LONG) bmpFileHdr2.bmp2.cy,
  2158.                                    pbBuffer + bmpFileHdr2.offBits,
  2159.                                    pbmi);
  2160.                 /*******************************************************/
  2161.                 /* Open the file to save the signature.                */
  2162.                 /*******************************************************/
  2163.                 rc = DosOpen(SaveFileDlg.szFullFile,
  2164.                              &hfBmpFile,
  2165.                              &ulAction,
  2166.                              ulImgData,
  2167.                              FILE_NORMAL,
  2168.                              OPEN_ACTION_CREATE_IF_NEW |
  2169.                              OPEN_ACTION_REPLACE_IF_EXISTS,
  2170.                              OPEN_FLAGS_WRITE_THROUGH |
  2171.                              OPEN_FLAGS_NO_CACHE |
  2172.                              OPEN_FLAGS_NOINHERIT |
  2173.                              OPEN_SHARE_DENYREADWRITE |
  2174.                              OPEN_ACCESS_READWRITE ,
  2175.                              (PEAOP2)NULL);
  2176.                 if (!rc)
  2177.                   {
  2178.  
  2179.                     /*******************************************************/
  2180.                     /* Write HEADER AND BITMAP image to file.              */
  2181.                     /*******************************************************/
  2182.                     DosWrite(hfBmpFile,
  2183.                              pbBuffer,
  2184.                              ulTotal,
  2185.                              &ulBytesWritten);
  2186.                     DosClose(hfBmpFile);
  2187.                     ShowMessageBox(hwndDlg, IDMSG_BMP_SAVED_OK, SaveFileDlg.szFullFile);
  2188.                   }
  2189.                 else
  2190.                   ShowMessageBox(hwndDlg, IDMSG_FILE_ERROR, NULL);
  2191.                 free(pbBuffer);
  2192.                 free(pbmi);
  2193.               } /* buffer created */
  2194.             else
  2195.               {
  2196.                 ShowMessageBox(hwndDlg, IDMSG_MEMORY_ERROR, NULL);
  2197.                 free(pbBuffer);
  2198.               }
  2199.           } /* buffer created */
  2200.         else
  2201.             ShowMessageBox(hwndDlg, IDMSG_MEMORY_ERROR, NULL);
  2202.       } /* memory ps */
  2203.  
  2204.       GpiAssociate( hMemoryPS, NULLHANDLE );    /* DisAssoc memory bitmap */
  2205.       GpiSetBitmap( hMemoryPS, NULLHANDLE );    /* PS no longer has a BMP */
  2206.       GpiDestroyPS( hMemoryPS );                /* Destroy the PS         */
  2207.     } /* memoryDC created */
  2208.  
  2209.     DevCloseDC( hMemoryDC );                    /* Close the DC              */
  2210.   }
  2211.  
  2212. }
  2213. /********************** End of Function *************************************/
  2214.  
  2215. /*****************************************************************************/
  2216. /*                                                                           */
  2217. /*  CreateControls - Create the following controls:  Selection Button        */
  2218. /*                                                   Cancel Button           */
  2219. /*                                                   Help Button             */
  2220. /*                                                   Sketch Window           */
  2221. /*                                                                           */
  2222. /*****************************************************************************/
  2223.  
  2224. void CreateControls(HWND hwnd)
  2225. {
  2226.  
  2227.   ULONG ulWindowStyle;
  2228.  
  2229.  
  2230. ulWindowStyle = WS_VISIBLE | BS_PUSHBUTTON | BS_DEFAULT;
  2231.  
  2232. hSELECTButton = WinCreateWindow( hwnd,              /* parent                */
  2233.                                  WC_BUTTON,         /* class name            */
  2234.                                  "SELECT CONTROL",  /* caption               */
  2235.                                   ulWindowStyle,    /* style                 */
  2236.                                   5L,               /* x of window position  */
  2237.                                   5L,               /* y of window position  */
  2238.                                   200L,             /* cx width of window    */
  2239.                                   30L,              /* cy length of window   */
  2240.                                   hwnd,             /* owner                 */
  2241.                                   HWND_BOTTOM,      /* position (nop)        */
  2242.                                   IDC_SELECT,       /* id                    */
  2243.                                   (PVOID) NULL,     /* parms passed wm_create*/
  2244.                                   (PVOID) NULL );   /* presparams            */
  2245.  
  2246.  
  2247.   ulWindowStyle = WS_VISIBLE | BS_PUSHBUTTON;
  2248.  
  2249.   hCANCELButton = WinCreateWindow( hwnd,              /* parent              */
  2250.                                    WC_BUTTON,         /* class name          */
  2251.                                    "CANCEL",          /* Cancel Button       */
  2252.                                    ulWindowStyle,     /* style               */
  2253.                                    210L,              /* x of window position*/
  2254.                                    5L,                /* y of window position*/
  2255.                                    88L,               /* cx width of window  */
  2256.                                    30L,               /* cy length of window */
  2257.                                    hwnd,              /* owner               */
  2258.                                    HWND_BOTTOM,       /* position (nop)      */
  2259.                                    IDC_CANCEL,        /* Control ID          */
  2260.                                    (PVOID) NULL,      /* parms passed to wm_c*/
  2261.                                    (PVOID) NULL );    /* presparams          */
  2262.  
  2263.  
  2264.   ulWindowStyle = WS_VISIBLE | BS_PUSHBUTTON | BS_HELP | BS_NOPOINTERFOCUS;
  2265.  
  2266.   hHELPButton = WinCreateWindow( hwnd,                /* parent              */
  2267.                                    WC_BUTTON,         /* class name          */
  2268.                                    "HELP",            /* Help                */
  2269.                                    ulWindowStyle,     /* style               */
  2270.                                    300L,              /* x of window position*/
  2271.                                    5L,                /* y of window position*/
  2272.                                    70L,               /* cx width of window  */
  2273.                                    30L,               /* cy length of window */
  2274.                                    hwnd,              /* owner               */
  2275.                                    HWND_BOTTOM,       /* position (nop)      */
  2276.                                    IDC_SKETCH_HELP,   /* Control ID          */
  2277.                                    (PVOID) NULL,      /* parms passed to wm_c*/
  2278.                                    (PVOID) NULL );    /* presparams          */
  2279.  
  2280.   ulWindowStyle = WS_VISIBLE | SKS_BORDER;
  2281.  
  2282.   hSKETCHControl  = WinCreateWindow( hwnd,            /* parent              */
  2283.                                      WC_SKETCH,       /* class name          */
  2284.                                      "",              /* Caption             */
  2285.                                      ulWindowStyle,   /* style               */
  2286.                                      5L,              /* x  window position  */
  2287.                                      40L,             /* y  window position  */
  2288.                                      195L,            /* cx width of window  */
  2289.                                      90L,             /* cy length of window */
  2290.                                      hwnd,            /* owner               */
  2291.                                      HWND_BOTTOM,     /* position (nop)      */
  2292.                                      IDC_SKETCH,      /* Control ID          */
  2293.                                      (PVOID) NULL,    /* parms passed to wm_c*/
  2294.                                      (PVOID) NULL );  /* presparams          */
  2295.  
  2296.   bWindowsCreated = TRUE;
  2297.  
  2298. }
  2299. /********************** End of Function *************************************/
  2300.  
  2301. /*****************************************************************************/
  2302. /*  Name : DisplayStrokeInfoDlgProc                                          */
  2303. /*                                                                           */
  2304. /*  Description : Display some of the information for a particular stroke.   */
  2305. /*                                                                           */
  2306. /* Parameters   : hwnd - Window handle to which message is addressed         */
  2307. /*                msg - Message type                                         */
  2308. /*                mp1 - First message parameter                              */
  2309. /*                mp2 - Second message parameter                             */
  2310. /*                                                                           */
  2311. /*****************************************************************************/
  2312. MRESULT EXPENTRY DisplayStrokeInfoDlgProc( HWND hwndDlg, ULONG msg, MPARAM mp1, MPARAM mp2 )
  2313. {
  2314.  
  2315. CHAR             szTempString[40];     /* temporary string buffer            */
  2316. PULONG           pulStrokeNumber;      /* Stroke Number                      */
  2317.  
  2318.  
  2319.   switch ( msg )
  2320.   {
  2321.     case WM_INITDLG:
  2322.        pulStrokeNumber =  PVOIDFROMMP(mp2);  /* Stroke Number parm           */
  2323.  
  2324.        /**************************************/
  2325.        /* Set Stroke Information.            */
  2326.        /**************************************/
  2327.  
  2328.        /************************/
  2329.        /* Stroke Number        */
  2330.        /************************/
  2331.        sprintf(szTempString, "%ld", *pulStrokeNumber);
  2332.        WinSetDlgItemText(hwndDlg, IDC_STROKE_NUMBER_DATA, szTempString);
  2333.  
  2334.        /************************/
  2335.        /* Stroke Color         */
  2336.        /************************/
  2337.        GetColorString(pStrokeData->ulStrokeColor, (PSZ) &szTempString); /* get color string*/
  2338.        WinSetDlgItemText(hwndDlg, IDC_STROKE_COLOR_DATA, szTempString);
  2339.  
  2340.        /************************/
  2341.        /* Stroke Width         */
  2342.        /************************/
  2343.        sprintf(szTempString, "%ld", pStrokeData->ulStrokeWidth);
  2344.        WinSetDlgItemText(hwndDlg, IDC_STROKE_WIDTH_DATA, szTempString);
  2345.  
  2346.        /************************/
  2347.        /* ulTimestamp          */
  2348.        /************************/
  2349.        sprintf(szTempString, "%ld",pStrokeData->pStroke->ulTimestamp);
  2350.        WinSetDlgItemText(hwndDlg, IDC_TIMESTAMP_DATA, szTempString);
  2351.  
  2352.        /************************/
  2353.        /* cbStructSize         */
  2354.        /************************/
  2355.        sprintf(szTempString, "%ld",pStrokeData->pStroke->cbStructSize);
  2356.        WinSetDlgItemText(hwndDlg, IDC_STRUCT_SIZE_DATA, szTempString);
  2357.  
  2358.        /************************/
  2359.        /* ulSource             */
  2360.        /************************/
  2361.        sprintf(szTempString, "%ld",pStrokeData->pStroke->ulSource);
  2362.        WinSetDlgItemText(hwndDlg, IDC_SOURCE_DATA, szTempString);
  2363.  
  2364.        /************************/
  2365.        /* ulResolution         */
  2366.        /************************/
  2367.        sprintf(szTempString, "%ld",pStrokeData->pStroke->ulResolution);
  2368.        WinSetDlgItemText(hwndDlg, IDC_RESOLUTION_DATA, szTempString);
  2369.  
  2370.        /************************/
  2371.        /* ulSampleRate         */
  2372.        /************************/
  2373.        sprintf(szTempString, "%ld",pStrokeData->pStroke->ulSampleRate);
  2374.        WinSetDlgItemText(hwndDlg, IDC_SAMPLE_RATE_DATA, szTempString);
  2375.  
  2376.        /************************/
  2377.        /* ulNumPoints          */
  2378.        /************************/
  2379.        sprintf(szTempString, "%ld",pStrokeData->pStroke->ulNumPoints);
  2380.        WinSetDlgItemText(hwndDlg, IDC_NUMPOINTS_DATA, szTempString);
  2381.  
  2382.  
  2383.        break;
  2384.  
  2385.  
  2386.     case WM_COMMAND:                    /* Posted by pushbutton or key  */
  2387.       switch( SHORT1FROMMP( mp1 ) )     /* Extract the command value    */
  2388.       {
  2389.         case DID_CANCEL:              /* The Cancel pushbutton or Escape key */
  2390.           WinDismissDlg( hwndDlg, DID_CANCEL);  /* Removes the dialog box    */
  2391.           return (MRESULT) FALSE;
  2392.       }
  2393.       break;
  2394.     default:
  2395.       return WinDefDlgProc( hwndDlg, msg, mp1, mp2 );
  2396.   }
  2397.   return (MRESULT) FALSE;
  2398. }
  2399. /********************** End of Function *************************************/
  2400.