home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / pentlk11.zip / SKETSAMP.H < prev    next >
Text File  |  1994-01-13  |  17KB  |  301 lines

  1.  
  2. /*****************************************************************************/
  3. /*                                                                           */
  4. /*  File Name   : SKETSAMP.H                                                 */
  5. /*                                                                           */
  6. /*  Description : Sample Program for SKETCH Controls                         */
  7. /*  Copyright (C) 1993 IBM Corporation                                       */
  8. /*                                                                           */
  9. /*      DISCLAIMER OF WARRANTIES.  The following [enclosed] code is          */
  10. /*      sample code created by IBM Corporation. This sample code is not      */
  11. /*      part of any standard or IBM product and is provided to you solely    */
  12. /*      for  the purpose of assisting you in the development of your         */
  13. /*      applications.  The code is provided "AS IS", without                 */
  14. /*      warranty of any kind.  IBM shall not be liable for any damages       */
  15. /*      arising out of your use of the sample code, even if they have been   */
  16. /*      advised of the possibility of such damages.                          */
  17. /*                                                                           */
  18. /*****************************************************************************/
  19.  
  20. #define ID_MAIN       1000       /* main window */
  21.  
  22. /***************/
  23. /* Dialog ID's */
  24. /***************/
  25. #define IDC_SELECT                  501       /* Pushbutton to Select Control*/
  26. #define IDC_SKETCH                  502
  27. #define IDC_SKETCH_HELP             503
  28. #define IDC_CANCEL                  504
  29.  
  30. #define MESSAGE_MAX   40         /* Maximum length of a Control Message      */
  31. #define MAXTEXTLEN    75         /* Maximum length for text.                 */
  32.  
  33. /****************************/
  34. /* Draw Pointer ID's        */
  35. /****************************/
  36. #define PTR_PEN       202
  37.  
  38. /************************************************/
  39. /* List Box  ID's   - Control Message Selection */
  40. /************************************************/
  41. #define IDD_SELECTCONTROL           525
  42. #define IDC_SELECTBOX               526
  43. #define IDC_MESSAGE_HELP            527
  44.  
  45. /************************************************/
  46. /* Dlg Box ID's     - Color Selection           */
  47. /************************************************/
  48. #define IDD_COLORSELECTION          535
  49. #define IDC_WHITE                   536
  50. #define IDC_BLACK                   537
  51. #define IDC_BLUE                    538
  52. #define IDC_RED                     539
  53. #define IDC_PINK                    540
  54. #define IDC_GREEN                   541
  55. #define IDC_CYAN                    542
  56. #define IDC_YELLOW                  543
  57. #define IDC_DARKGRAY                544
  58. #define IDC_DARKBLUE                545
  59. #define IDC_DARKRED                 546
  60. #define IDC_DARKPINK                547
  61. #define IDC_DARKGREEN               548
  62. #define IDC_DARKCYAN                549
  63. #define IDC_BROWN                   550
  64. #define IDC_PALEGRAY                551
  65.  
  66. /**************************************************/
  67. /* Dlg Box ID's     - Visible/Invisible Selection */
  68. /**************************************************/
  69. #define IDD_VISIBLE                 560
  70. #define IDC_VISIBLE                 561
  71. #define IDC_INVISIBLE               562
  72.  
  73. /*************************************************/
  74. /* Dlg Box ID's     - Stroke Number Selection    */
  75. /*************************************************/
  76. #define IDD_GETSTROKENUMBER         563
  77. #define IDC_STROKETEXT              564
  78. #define IDC_STROKEINPUT             565
  79.  
  80. /************************************************/
  81. /* Dlg Box ID's     - Stroke Width Selection    */
  82. /************************************************/
  83. #define IDD_GETWIDTH                566
  84. #define IDC_WIDTHTEXT               567
  85. #define IDC_WIDTHINPUT              568
  86.  
  87. /**************************************************/
  88. /* Dlg Box ID's     - Auxiliary Data Selection    */
  89. /**************************************************/
  90. #define IDD_AUX                     570
  91. #define IDC_ALLAUX                  571
  92. #define IDC_NONEAUX                 572
  93. #define IDC_AUX_HELP                573
  94.  
  95. /************************************************/
  96. /* Dlg Box ID's     - Display Stroke Info       */
  97. /************************************************/
  98. #define IDD_STROKE_INFO             575
  99. #define IDC_STROKE_NUMBER           576
  100. #define IDC_STROKE_NUMBER_DATA      577
  101. #define IDC_STROKE_COLOR            578
  102. #define IDC_STROKE_COLOR_DATA       579
  103. #define IDC_STROKE_WIDTH            580
  104. #define IDC_STROKE_WIDTH_DATA       581
  105. #define IDC_TIMESTAMP               582
  106. #define IDC_TIMESTAMP_DATA          583
  107. #define IDC_STRUCT_SIZE             584
  108. #define IDC_STRUCT_SIZE_DATA        585
  109. #define IDC_SOURCE                  586
  110. #define IDC_SOURCE_DATA             587
  111. #define IDC_RESOLUTION              588
  112. #define IDC_RESOLUTION_DATA         589
  113. #define IDC_SAMPLE_RATE             590
  114. #define IDC_SAMPLE_RATE_DATA        591
  115. #define IDC_NUMPOINTS               592
  116. #define IDC_NUMPOINTS_DATA          593
  117.  
  118. /****************************/
  119. /* Message Box ID           */
  120. /****************************/
  121. #define IDD_MSGBOX                600
  122.  
  123.  
  124. /*********************************************/
  125. /* Test Messagetable Ids                     */
  126. /*********************************************/
  127. #define IDMSG_SHOWINFO                700    /* Information Message                                  */
  128. #define IDMSG_INK_COLOR_QUERY         701    /* The INK color is %s.                                 */
  129. #define IDMSG_INK_COLOR_SET           702    /* The INK color has been set to %s.                    */
  130. #define IDMSG_INK_WIDTH_QUERY         703    /* The INK width is %s.                                 */
  131. #define IDMSG_INK_WIDTH_SET           704    /* The INK width has been set to %s.                    */
  132. #define IDMSG_DISPLAY_MODE            705    /* The display mode is %s.                              */
  133. #define IDMSG_DRAWPOINTER_QUERY       706    /* The drawing pointer is %s."                          */
  134. #define IDMSG_DRAWPOINTER_SET         707    /* Set Drawing Pointer:%s"                              */
  135. #define IDMSG_INK_COLOR_CHANGE        708    /* COLOR CHANGE NOTIFICATION:  Ink color changed to %s! */
  136. #define IDMSG_INK_WIDTH_CHANGE        709    /* WIDTH CHANGE NOTIFICATION:  Ink width changed to %s! */
  137. #define IDMSG_NOTHING_CLEAR           710    /* No Strokes in Database to clear!                     */
  138. #define IDMSG_NOTHING_UNDO            711    /* No Strokes in Database to undo!                      */
  139. #define IDMSG_STROKE_COUNT            712    /* Database Stroke Count = %s.                          */
  140. #define IDMSG_AUX_ALL_SET             714    /* Subsequent strokes will retrieve auxiliary data.     */
  141. #define IDMSG_AUX_NONE_SET            715    /* Subsequent strokes will NOT retrieve auxiliary data. */
  142. #define IDMSG_BMP_SAVED_OK            716    /* Bitmap Saved to file %s!"                            */
  143. #define IDMSG_BITMAP_SIZE_QUERY       717    /* Bitmap Size:%s"                                    */
  144. #define IDMSG_STROKE_COLOR_QUERY      718    /* Query Stroke Color:%s"                             */
  145. #define IDMSG_STROKE_COLOR_SET        719    /* Set Stroke Color:%s                                */
  146. #define IDMSG_STROKE_WIDTH_QUERY      720    /* Query Stroke Width:%s"                             */
  147. #define IDMSG_STROKE_WIDTH_SET        721    /* Set Stroke Width:%s                                */
  148. #define IDMSG_STROKE_LENGTH_QUERY     722    /* Query Stroke Length:%s"                                  */
  149. #define IDMSG_ALL_STROKES_CLEARED     723    /* All Strokes Cleared!                         */
  150. #define IDMSG_LAST_STROKE_CLEARED     724    /* Last Stroke Cleared!                         */
  151.  
  152.  
  153. #define IDMSG_SHOWWARNING             740     /* Warning Message                                         */
  154. #define IDMSG_STROKE_ADD              741     /* STROKE ADD NOTIFICATION:  Press OK to add stroke #%s to the database.     */
  155. #define IDMSG_STROKE_UNDO             742     /* STROKE UNDO NOTIFICATION: Press OK to delete stroke #%s from the database.*/
  156. #define IDMSG_STROKE_CLEAR            743     /* STROKE CLEAR NOTIFICATION: Press OK to clear all(%s) strokes.             */
  157. #define IDMSG_BITMAP_HANDLE_SAVE      744     /* Bitmap Handle = %sPress OK to save the bitmap to a file.*/
  158. #define IDMSG_BITMAP_REALLY_SAVE      745     /* File %s already exists and WILL BE ERASED! */
  159.  
  160.  
  161. #define IDMSG_SHOWERROR               750    /* Error Message                */
  162. #define IDMSG_MESSAGE_FAIL            751    /* %s FAILED.                   */
  163. #define IDMSG_NO_PEN_RUNNING          752    /* Pen for OS/2 is not running. */
  164. #define IDMSG_NO_HELP                 753    /* Missing HELP.                */
  165. #define IDMSG_MEMORY_ERROR            754    /* Memory Failure - Bitmap cannot be saved. */
  166. #define IDMSG_FILE_ERROR              755    /* File Error - Bitmap cannot be saved. */
  167. #define IDMSG_MEMORY_FAIL_GETSTROKE   756    /* Memory Fail during Stroke #%s retrieve!  */
  168. #define IDMSG_INK_WIDTH_SET_FAIL      757    /* FAIL!  Width can only be set to 1 or 2 pels. */
  169. #define IDMSG_STROKE_INVALID          758    /* Stroke #%s is invalid!                               */
  170.  
  171. /*********************************************/
  172. /* Help IDs                                  */
  173. /*********************************************/
  174. #define SKETCH_HELPTABLE              800
  175. #define DLG_CHOOSE_HELPSUBTABLE       801
  176. #define SKETCH_HELPSUBTABLE           802
  177. #define DLG_CHOOSE_AUXSUBTABLE        803
  178.  
  179. #define PANEL_SKETCH                  804     /* F1 or Help button pressed at Sketch Window */
  180.  
  181. #define PANEL_MESSAGE                 805     /* F1 pressed at Select Window */
  182.  
  183. #define PANEL_AUX                     806     /* F1 pressed at Choose Aux    */
  184.  
  185. #define PANEL_SKM_DELETE_ALL_STROKES       815 /* Help button pressed at SKM_DELETE_ALL_STROKES     */
  186. #define PANEL_SKM_UNDO_LAST_STROKE         816 /* Help button pressed at SKM_UNDO__LAST_STROKE      */
  187. #define PANEL_SKM_QUERY_CTL_DRAW_POINTER   817 /* Help button pressed at SKM_QUERY_CTL_DRAW_POINTER */
  188. #define PANEL_SKM_QUERY_CTL_INK_WIDTH      818 /* Help button pressed at SKM_QUERY_CTL_INK_WIDTH    */
  189. #define PANEL_SKM_QUERY_CTL_INK_COLOR      819 /* Help button pressed at SKM_QUERY_CTL_INK_COLOR    */
  190. #define PANEL_SKM_QUERY_CTL_INVISIBLE_MODE 820
  191. #define PANEL_SKM_SET_CTL_DRAW_POINTER     821
  192. #define PANEL_SKM_SET_CTL_INK_WIDTH        822
  193. #define PANEL_SKM_SET_CTL_INK_COLOR        823
  194. #define PANEL_SKM_SET_CTL_INVISIBLE_MODE   824
  195. #define PANEL_SKM_RENDER_TO_CLIPBOARD      825
  196. #define PANEL_SKM_QUERY_CTL_STROKE_COUNT   826
  197. #define PANEL_SKM_SET_STROKE_INK_COLOR     827
  198. #define PANEL_SKM_SET_STROKE_INK_WIDTH     828
  199. #define PANEL_SKN_INK_COLOR_CHANGE         829
  200. #define PANEL_SKN_STROKE_ADD               830
  201. #define PANEL_SKN_STROKE_UNDO              831
  202. #define PANEL_SKN_CONTROL_CLEARED          832
  203. #define PANEL_SKM_SET_CTL_AUXDATA_MODE     833
  204. #define PANEL_SKN_INK_WIDTH_CHANGE         834
  205. #define PANEL_SKM_GET_BITMAP               835
  206. #define PANEL_SKM_QUERY_BITMAP_SIZE        836
  207. #define PANEL_SKM_QUERY_STROKE_LENGTH      837
  208. #define PANEL_SKM_QUERY_STROKE_DATA        838
  209. #define PANEL_SKM_QUERY_STROKE_INK_COLOR   839
  210. #define PANEL_SKM_QUERY_STROKE_INK_WIDTH   840
  211.  
  212.  
  213.  
  214. MRESULT EXPENTRY ClientWndProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2 );
  215. MRESULT EXPENTRY ChooseControlProc( HWND hwndDlg, ULONG msg, MPARAM mp1, MPARAM mp2 );
  216. MRESULT EXPENTRY ColorDlgProc( HWND hwndDlg, ULONG msg, MPARAM mp1, MPARAM mp2 );
  217. MRESULT EXPENTRY VisibleDlgProc( HWND hwndDlg, ULONG msg, MPARAM mp1, MPARAM mp2 );
  218. MRESULT EXPENTRY AllNoneAuxDlgProc( HWND hwndDlg, ULONG msg, MPARAM mp1, MPARAM mp2 );
  219. MRESULT EXPENTRY GetStrokeNumberProc( HWND hwndDlg, ULONG msg, MPARAM mp1, MPARAM mp2 );
  220. MRESULT EXPENTRY WidthDlgProc( HWND hwndDlg, ULONG msg, MPARAM mp1, MPARAM mp2 );
  221. MRESULT EXPENTRY DisplayStrokeInfoDlgProc( HWND hwndDlg, ULONG msg, MPARAM mp1, MPARAM mp2 );
  222.  
  223. int     main( VOID );
  224.  
  225. VOID    ExecuteControlMessage(LONG lMessageValue, PSZ pszChosenItem, HWND hwnd);
  226. VOID    GetColorString(LONG ColNum, PSZ szColor);
  227. USHORT  ShowMessageBox(HWND hwnd, USHORT idMsg, PSZ szExtendedMessage);
  228. VOID    InitHelp(VOID);
  229. VOID    SaveBmpInFile(HWND hwndDlg, HBITMAP hBitmap);
  230. VOID    CreateControls(HWND hwnd);
  231.  
  232.  
  233. /*************************/
  234. /* Global Variables      */
  235. /*************************/
  236.   HWND      hwndFrame;             /* window handle                          */
  237.   HAB       hab;                   /* anchor block handle                    */
  238.  
  239.   HWND      hSKETCHControl;        /* Sketch Window                          */
  240.   HWND      hSELECTButton;
  241.   HWND      hCANCELButton;
  242.   HWND      hHELPButton;
  243.   HWND      hwndSelectDlg;         /* Select Dialog handle */
  244.  
  245.   HPOINTER  hptrt1;                /* Black Pen Drawing Pointer              */
  246.   HPOINTER  hpDefault;             /* Default Sketch Control Drawing Pointer */
  247.  
  248.   CHAR      szMessageBoxString[240];      /* Complete message to user        */
  249.  
  250.   BOOL      bLookAtNotification;  /* flag to verify that a notification message was received */
  251.                                   /* TRUE if want to display message showing that notification was received */
  252.   BOOL      bWindowsCreated;      /* TRUE if successfully create sketch control, and action buttons         */
  253.  
  254.   HWND      hwndHelp;
  255.  
  256.   USHORT    usAux = FALSE;       /* TRUE if want all Aux data                */
  257.  
  258.   PSKETCHSTROKEDEF pStrokeData = NULL; /* Stroke Data Structure              */
  259.  
  260.  
  261. /**********************************************************/
  262. /* Select Control Listbox, Execution and Help Information */
  263. /**********************************************************/
  264. struct MessageData
  265.   {
  266.     PSZ    pszMessageName;      /* Control Message Name String               */
  267.     LONG   lMessageValue;       /* Control Message Value                     */
  268.     ULONG  ulMessageHelpValue;  /* Control Message Help                      */
  269.   };
  270.  
  271. struct MessageData MessageList[27] =  {
  272. {"SKM_DELETE_ALL_STROKES",      SKM_DELETE_ALL_STROKES,       PANEL_SKM_DELETE_ALL_STROKES      },
  273. {"SKM_UNDO_LAST_STROKE",        SKM_UNDO_LAST_STROKE,         PANEL_SKM_UNDO_LAST_STROKE        },
  274. {"SKM_QUERY_CTL_DRAW_POINTER",  SKM_QUERY_CTL_DRAW_POINTER,   PANEL_SKM_QUERY_CTL_DRAW_POINTER  },
  275. {"SKM_SET_CTL_DRAW_POINTER",    SKM_SET_CTL_DRAW_POINTER,     PANEL_SKM_SET_CTL_DRAW_POINTER    },
  276. {"SKM_QUERY_CTL_INK_WIDTH",     SKM_QUERY_CTL_INK_WIDTH,      PANEL_SKM_QUERY_CTL_INK_WIDTH     },
  277. {"SKM_SET_CTL_INK_WIDTH",       SKM_SET_CTL_INK_WIDTH,        PANEL_SKM_SET_CTL_INK_WIDTH       },
  278. {"SKM_QUERY_CTL_INK_COLOR",     SKM_QUERY_CTL_INK_COLOR,      PANEL_SKM_QUERY_CTL_INK_COLOR     },
  279. {"SKM_SET_CTL_INK_COLOR",       SKM_SET_CTL_INK_COLOR,        PANEL_SKM_SET_CTL_INK_COLOR       },
  280. {"SKM_QUERY_CTL_INVISIBLE_MODE",SKM_QUERY_CTL_INVISIBLE_MODE, PANEL_SKM_QUERY_CTL_INVISIBLE_MODE},
  281. {"SKM_SET_CTL_INVISIBLE_MODE",  SKM_SET_CTL_INVISIBLE_MODE,   PANEL_SKM_SET_CTL_INVISIBLE_MODE  },
  282. {"SKM_QUERY_STROKE_INK_COLOR",  SKM_QUERY_STROKE_INK_COLOR,   PANEL_SKM_QUERY_STROKE_INK_COLOR },
  283. {"SKM_SET_STROKE_INK_COLOR",    SKM_SET_STROKE_INK_COLOR,     PANEL_SKM_SET_STROKE_INK_COLOR    },
  284. {"SKM_QUERY_STROKE_INK_WIDTH",  SKM_QUERY_STROKE_INK_WIDTH,   PANEL_SKM_QUERY_STROKE_INK_WIDTH  },
  285. {"SKM_SET_STROKE_INK_WIDTH",    SKM_SET_STROKE_INK_WIDTH,     PANEL_SKM_SET_STROKE_INK_WIDTH    },
  286. {"SKM_QUERY_STROKE_LENGTH",     SKM_QUERY_STROKE_LENGTH,      PANEL_SKM_QUERY_STROKE_LENGTH     },
  287. {"SKM_QUERY_STROKE_DATA",       SKM_QUERY_STROKE_DATA,        PANEL_SKM_QUERY_STROKE_DATA       },
  288. {"SKM_QUERY_CTL_STROKE_COUNT",  SKM_QUERY_CTL_STROKE_COUNT,   PANEL_SKM_QUERY_CTL_STROKE_COUNT  },
  289. {"SKM_GET_BITMAP",              SKM_GET_BITMAP,               PANEL_SKM_GET_BITMAP              },
  290. {"SKM_QUERY_BITMAP_SIZE",       SKM_QUERY_BITMAP_SIZE,        PANEL_SKM_QUERY_BITMAP_SIZE       },
  291. {"SKM_SET_CTL_AUXDATA_MODE",    SKM_SET_CTL_AUXDATA_MODE,     PANEL_SKM_SET_CTL_AUXDATA_MODE    },
  292. {"SKM_RENDER_TO_CLIPBOARD",     SKM_RENDER_TO_CLIPBOARD,      PANEL_SKM_RENDER_TO_CLIPBOARD     },
  293. {"SKN_INK_COLOR_CHANGE",        SKN_INK_COLOR_CHANGE,         PANEL_SKN_INK_COLOR_CHANGE        },
  294. {"SKN_INK_WIDTH_CHANGE",        SKN_INK_WIDTH_CHANGE,         PANEL_SKN_INK_WIDTH_CHANGE        },
  295. {"SKN_STROKE_ADD",              SKN_STROKE_ADD,               PANEL_SKN_STROKE_ADD              },
  296. {"SKN_STROKE_UNDO",             SKN_STROKE_UNDO,              PANEL_SKN_STROKE_UNDO             },
  297. {"SKN_CONTROL_CLEARED",         SKN_CONTROL_CLEARED,          PANEL_SKN_CONTROL_CLEARED         },
  298. {NULL,                           0L,                              0UL                           }
  299. };
  300.  
  301.