home *** CD-ROM | disk | FTP | other *** search
/ Microsoft Programmer's Library 1.3 / Microsoft-Programers-Library-v1.3.iso / sampcode / os2sdk / os2sdk12 / sort / sort.h < prev    next >
Encoding:
C/C++ Source or Header  |  1990-07-06  |  5.0 KB  |  126 lines

  1. /* This header file does all the necessary includes and defines all the
  2.    structures and constants needed for the sort program                 */
  3.  
  4. #define INCL_WIN
  5. #define INCL_WINHEAP
  6. #define INCL_WINDIALOGS
  7. #define INCL_GPIPRIMITIVES
  8. #define INCL_GPIBITMAPS
  9. #define INCL_DOSPROCESS
  10. #define _MT
  11.  
  12. #include <os2.h>
  13. #include <dos.h>
  14. #include <stdio.h>
  15. #include <string.h>
  16. #include <process.h>
  17. #include <stdlib.h>
  18.  
  19. /* This structure is passed into various routines and contains various
  20.    information, often depending on who is passing the information.
  21.    hwnd holds the main window handle for routines that need to draw.
  22.    fContinueCalc is used by routines that have the ability to abort
  23.          when the calling routine sets this flag to FALSE.
  24.    usID is set to the offset number of a thread and is used to pass
  25.          a message back to the window proc when the thread terminates.
  26.    (*pFunc)() passes the function to be called to the generic thread
  27.          starting routine CalcThread.
  28.    Array points to the beginning of the data set to be used by the
  29.          various sorts.  This pointer is used in the Display thread
  30.          to point to the variable that is dynamically modified to
  31.          contain the current height of the client window.
  32.    cArray is the number of elements in Array.  It serves no purpose in
  33.          the Display thread.
  34.    pcSetSize is used only by the Display thread to point to a dynamically
  35.          modified variable which contains the user-modifiable data
  36.          set size.                                                    */
  37.  
  38. typedef struct
  39. {
  40.    HWND   hwnd;
  41.    BOOL   fContinueCalc;
  42.    BYTE   *pcThreadCnt;
  43.    USHORT usID;
  44.    VOID   (*pFunc)(VOID *);
  45.    USHORT *Array;
  46.    USHORT cArray;
  47.    USHORT *pcSetSize;
  48. } CALCPARAM;
  49. typedef CALCPARAM FAR *PCALCPARAM;
  50.  
  51. /* Function Definitions */
  52.  
  53. MRESULT EXPENTRY ClientWndProc  (HWND, USHORT, MPARAM, MPARAM);
  54. MRESULT EXPENTRY EntryFldDlgProc(HWND, USHORT, MPARAM, MPARAM);
  55. INT  main(VOID);
  56. VOID _cdecl FAR CalcThread(PCALCPARAM);
  57. VOID _cdecl FAR DispThread(PCALCPARAM);
  58. VOID EnableMenuItem(HWND hwnd, SHORT sMenuItem, BOOL fEnable);
  59. VOID RandomizeData(USHORT);
  60. VOID BubbleSort(PCALCPARAM);
  61. VOID BatcherSort(PCALCPARAM);
  62. VOID BatcherSortR(PCALCPARAM, USHORT, USHORT, USHORT, BOOL);
  63. VOID QuickSort(PCALCPARAM);
  64. VOID QuickSortR(PCALCPARAM, SHORT, SHORT);
  65. VOID InsertionSort(PCALCPARAM);
  66.  
  67. #define STACKSIZE        4096    /* Arbitrary size for a stack     */
  68. #define LISTCNT             4    /* Number of data sets            */
  69. #define NELEMS            512    /* Number of items in a data set  */
  70.  
  71. #define XOFFSET            10    /* Pixel offset for axis in X dir */
  72. #define YOFFSET            40    /* Pixel offset for axis in Y dir */
  73.  
  74. #define COLUMNOFFSET      100    /* Column offset for sort names   */
  75. #define ROWOFFSET          12    /* Row offset for sort names      */
  76. #define COLUMNCNT           4    /* Max # of text columns          */
  77. #define ROWCNT              2    /* Max # of text rows             */
  78.  
  79. /****** Resource IDs *****/
  80.  
  81.  
  82. #define ID_MAINMENU    1
  83. #define BMP_SORT       1
  84. #define IDM_START      2
  85. #define IDM_STOP       3
  86. #define IDM_SET        4
  87. #define IDM_RANDOM     5
  88. #define ID_SETCOUNT    6
  89. #define ID_ENTRYFLD    7
  90. #define UM_CALC_DONE   (WM_USER+0) /* Message posted when thread terminates */
  91.  
  92.  
  93. /* Macro for drawing a rectangle.  Assumes hps and ptl structs are defined
  94.    in the calling module. */
  95.  
  96. #define DrawRect(x1,y1,x2,y2,color)  ptl.x = (LONG) (x1);             \
  97.                                      ptl.y = (LONG) (y1);             \
  98.                                      GpiSetCurrentPosition(hps,&ptl); \
  99.                                      ptl.x = (LONG) (x2);             \
  100.                                      ptl.y = (LONG) (y2);             \
  101.                                      GpiSetColor(hps,color);          \
  102.                                      GpiBox(hps,DRO_FILL,&ptl,0L,0L);
  103.  
  104. /* Macro for drawing a line.  Assumes hps and ptl structs are defined
  105.    in the calling module. */
  106.  
  107. #define DrawLine(x1,y1,x2,y2,color)  ptl.x = (LONG) (x1);             \
  108.                                      ptl.y = (LONG) (y1);             \
  109.                                      GpiSetCurrentPosition(hps,&ptl); \
  110.                                      ptl.x = (LONG) (x2);             \
  111.                                      ptl.y = (LONG) (y2);             \
  112.                                      GpiSetColor(hps,color);          \
  113.                                      GpiLine(hps,&ptl);
  114.  
  115. /* Macro for drawing a point.  Assumes hps and ptl structs are defined
  116.    in the calling module. */
  117.  
  118. #define Draw2Pel(x1,y1,color)        ptl.x = (LONG) (x1);             \
  119.                                      ptl.y = (LONG) (y1);             \
  120.                                      GpiSetColor(hps,color);          \
  121.                                      GpiSetPel(hps,&ptl);             \
  122.                                      ptl.y++;                         \
  123.                                      GpiSetPel(hps,&ptl);
  124.  
  125. 
  126.