home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / tolkit45.zip / os2tk45 / samples / os2 / semaph / semaph.h < prev    next >
C/C++ Source or Header  |  1999-05-11  |  12KB  |  313 lines

  1. /*static char *SCCSID = "@(#)semaph.h   6.12 92/02/19";*/
  2. /*==============================================================*\
  3.  *                                                              *
  4.  *  SEMAPH.H Sample PM application header file                  *
  5.  *      (C) Copyright IBM Corporation 1992.                     *
  6.  *                                                              *
  7.  *--------------------------------------------------------------*
  8.  *                                                              *
  9.  *  This header file contains the application wide constants    *
  10.  *  and structure definitions.                                  *
  11.  *                                                              *
  12. \*==============================================================*/
  13. #define INCL_WIN
  14. #define INCL_GPI
  15. #define INCL_DEV
  16. #define INCL_AVIO
  17. #define INCL_PIC
  18. #define INCL_HELP
  19. #define INCL_ORDERS
  20. #define INCL_BITMAPFILEFORMAT
  21. #define INCL_FONTFILEFORMAT
  22. #define INCL_WINMESSAGEMGR
  23. #define INCL_DOSPROCESS
  24. #define INCL_ERRORS
  25. #define INCL_BASE
  26.  
  27. #include <os2.h>
  28. #include <stdio.h>
  29. #include <string.h>
  30. #include <stdlib.h>
  31.  
  32. #define IDR_RESOURCE                    1000     /* resource identifier */
  33. #define ID_TIMER                           1
  34. #define ID_NULL                           -1
  35. #define IDR_BITMAP                         2
  36. #define IDC_BITMAP                         3
  37.  
  38. /*--------------------------------------------------------------*\
  39.  *  Menu item ids                                               *
  40. \*--------------------------------------------------------------*/
  41. #define IDM_OPTIONS_NTHRDS              4100
  42. #define IDM_OPTIONS_NTHRDS_2            4102
  43. #define IDM_OPTIONS_NTHRDS_4            4104
  44. #define IDM_OPTIONS_NTHRDS_8            4108
  45. #define IDM_OPTIONS_NTHRDS_16           4116
  46. #define IDM_OPTIONS_TIMEOUT             4200
  47.  
  48. #define IDM_SEMSTART                    4211
  49. #define IDM_SEMSTART_MANUAL             4212
  50. #define IDM_SEMSTART_AUTO               4213
  51. #define IDM_SEMSTOP                     4214
  52. #define IDM_SEM_RESUMEAUTO              4215
  53. #define IDM_POST                        4216
  54. #define IDM_MSGBOX                      4217
  55.  
  56. #define IDM_HELP                        4230
  57. #define IDM_HELPINDEX                   4231
  58. #define IDM_GENERALHELP                 4232
  59. #define IDM_TUTORIAL                    4233
  60. #define IDM_USINGHELP                   4234
  61. #define IDM_HELPPRODUCTINFO             4235
  62.  
  63. /* private message */
  64. #define IDM_STOPFINISHED                4240
  65.  
  66. /*--------------------------------------------------------------*\
  67.  *  Stringtable ids                                             *
  68. \*--------------------------------------------------------------*/
  69.          /* for help menu module */
  70. #define IDS_APPNAME                      101
  71. #define IDS_HELPLIBRARYNAME              102
  72. #define IDS_HELPWINDOWTITLE              103
  73. #define IDS_TITLE                        104
  74. #define IDS_UNTITLED                     105
  75.  
  76. /*--------------------------------------------------------------*\
  77.  *  Help table and subtables                                    *
  78. \*--------------------------------------------------------------*/
  79. #define SEMAPH_HELP_TABLE                   9000
  80.  
  81. /*--------------------------------------------------------------*\
  82.  *  Main window help panels                                     *
  83. \*--------------------------------------------------------------*/
  84. #define SUBTABLE_MAIN                       9100
  85. #define PANEL_MAIN                          9110
  86. #define PANEL_HELP                          9120
  87. #define PANEL_GENERALHELP                   9130
  88. #define PANEL_USINGHELP                     9140
  89. #define PANEL_TUTORIAL                      9150
  90. #define PANEL_HELPINDEX                     9160
  91. #define PANEL_HELPPRODUCTINFO               9170
  92. #define PANEL_KEYSHELP                      9180
  93.  
  94. #define PANEL_NTHRDSHELP                    9181
  95. #define PANEL_THRDS2HELP                    9182
  96. #define PANEL_THRDS4HELP                    9183
  97. #define PANEL_THRDS8HELP                    9184
  98. #define PANEL_THRDS16HELP                   9185
  99.  
  100. #define PANEL_STARTHELP                     9186
  101. #define PANEL_AUTOHELP                      9187
  102. #define PANEL_MANUALHELP                    9188
  103.  
  104. #define PANEL_TIMEOUTHELP                   9189
  105. #define PANEL_STOPHELP                      9191
  106. #define PANEL_RESUMEHELP                    9192
  107. #define PANEL_POSTHELP                      9193
  108.  
  109. /*--------------------------------------------------------------*\
  110.  *  Enter text dialog help subtable                             *
  111. \*--------------------------------------------------------------*/
  112. #define SUBTABLE_PRODUCTINFODLG             9200
  113. #define PANEL_PRODUCTINFODLG                9210
  114. #define PANEL_PRODUCTINFO_OK                9211
  115.  
  116. #define ENTERTEXTDLG                      0x1000
  117. #define DEMOMSGBOX                        0x1006
  118. #define TIMERBOX                          0x1001
  119. #define REFRESHBOX                        0x1002
  120.  
  121. #define WM_USERCHANGED               (WM_USER+1)
  122. /*--------------------------------------------------------------*\
  123.  *  Message item ids                                            *
  124. \*--------------------------------------------------------------*/
  125. #define IDD_PRODUCTINFO                      152
  126. #define IDD_ENTRY                            153
  127. #define IDD_MLE                              154
  128. #define IDD_RADIO1                           155
  129. #define IDD_RADIO2                           156
  130. #define IDD_RADIO3                           157
  131. #define IDD_PUSHBUTTON                       158
  132. #define IDD_3STATE                           159
  133. #define IDD_CHECKBOX                         160
  134. #define IDD_LISTBOX                          161
  135. #define IDD_MULTISELLISTBOX                  162
  136. #define IDD_SIMPLE                           163
  137. #define IDD_DROPDOWN                         164
  138. #define IDD_DROPDOWNLIST                     165
  139. #define IDD_STATICTEXT                       166
  140. #define IDD_GROUPBOX                         167
  141. #define IDD_ICON                             168
  142. #define IDD_STATICFRAME                      169
  143. #define IDD_STATICRECT                       170
  144. #define IDD_FORECOLORLIST                    171
  145. #define IDD_BACKCOLORLIST                    172
  146. #define IDD_FONTLIST                         173
  147. #define IDD_SAMPLETEXT                       174
  148. #define IDD_DONE                             175
  149.  
  150. /*--------------------------------------------------------------*\
  151.  *  Messagetable ids                                            *
  152. \*--------------------------------------------------------------*/
  153. #define IDMSG_INITFAILED                     301
  154. #define IDMSG_MAINWINCREATEFAILED            302
  155. #define IDMSG_CANNOTGETHPS                   303
  156. #define IDMSG_CANNOTLOADSTRING               304
  157. #define IDMSG_CANNOTLOADEXITLIST             305
  158. #define IDMSG_HELPLOADERROR                  306
  159. #define IDMSG_HELPDISPLAYERROR               307
  160. #define IDMSG_CANNOTSTART                    308
  161.  
  162. /*--------------------------------------------------------------*\
  163.  *  Other constants                                             *
  164. \*--------------------------------------------------------------*/
  165. #define HELPLIBRARYNAMELEN 20  /* The length of library name */
  166. #define MESSAGELEN        150  /* maximum length for messages */
  167. #define RETURN_SUCCESS      0   /* successful return in DosExit */
  168. #define RETURN_ERROR        1        /* error return in DosExit */
  169. #define BEEP_WARN_FREQ     60      /* frequency of warning beep */
  170. #define BEEP_WARN_DUR     100       /* duration of warning beep */
  171. #define MAXWIDTH           80
  172. #define NUMLINES           25
  173. #define MAXTEXTLEN         40    /* maximum text length for window */
  174. #define MAXAPPNAMELEN      15
  175.  
  176. #define STACKSIZE     0X10000L
  177. #define TIMEOUTPERIOD      33L
  178. #define EVENTSEM            0
  179. #define STOPSEM            -1
  180. #define BASETEN            10
  181.  
  182. #define UNOWNED            -1
  183. #define NUMUSERS            8
  184. #define MAXUSERS           16
  185. #define CNT_SQUARES_EDGE    8
  186. #define MAXRESOURCES        (CNT_SQUARES_EDGE*CNT_SQUARES_EDGE)
  187. #define CNT_POINTS_EDGE     (CNT_SQUARES_EDGE+1)
  188. #define DIRTY               1
  189. #define CNT_SZHITS          5
  190.  
  191. /*--------------------------------------------------------------*\
  192.  *  Global variables                                            *
  193. \*--------------------------------------------------------------*/
  194. HWND         hwndMainFrame;            /* handle to the main frame window */
  195. HWND         hwndMain;                /* handle to the main client window */
  196. HAB          hab;                         /* anchor block for the process */
  197. HMQ          hmq;                 /* handle to the process' message queue */
  198. CHAR         szAppName[MAXAPPNAMELEN];     /* buffer for application name */
  199. USHORT       usConsumerThreadsCreated;
  200. TID          tidAutoThread;
  201. ULONG        ulTimeout;
  202. CHAR         szUntitled[MESSAGELEN];      /* buffer for "Untitled" string */
  203.       /* for help menu module */
  204. BOOL         fHelpEnabled;        /* flag to determine if help is enabled */
  205. static CHAR  szLibName[HELPLIBRARYNAMELEN];
  206. static CHAR  szWindowTitle[HELPLIBRARYNAMELEN];
  207. static HWND  hwndHelpInstance;
  208.  
  209. CHAR         szWindowText[MAXTEXTLEN];
  210. USHORT       cNumUsers;
  211. USHORT       fSemaphoreStarted;
  212. USHORT       fSemaphoreWasStarted;
  213. ULONG        fAutoMode;
  214. HEV          hevStop, hevStopAuto, hevItem;
  215. HMTX         hmtxOwnResource;
  216. HMUX         hmuxResource;
  217.  
  218. /*--------------------------------------------------------------*\
  219.  *  Data structures and typedefs                                *
  220. \*--------------------------------------------------------------*/
  221. struct _WINDOWDATA  {
  222.     LONG clrFore;
  223.     LONG clrBack;
  224.     UCHAR *szText[MAXTEXTLEN + 1];
  225. };
  226. typedef struct _WINDOWDATA WINDOWDATA;
  227. typedef WINDOWDATA * PWINDOWDATA;
  228.  
  229. typedef struct _thr {
  230.     TID   tid;
  231.     LONG  lHits;
  232.     RECTL rcl;
  233. } THRDATA;
  234.  
  235. typedef struct _sq {           /* square */
  236.     RECTL  rcl;
  237.     HEV    hev;
  238.     USHORT usOwner;
  239.     } SQ;
  240.  
  241. /*--------------------------------------------------------------*\
  242.  *  Global variables                                            *
  243. \*--------------------------------------------------------------*/
  244. SQ           aSquares[MAXRESOURCES];
  245. THRDATA      thrConsumers[MAXUSERS];
  246.  
  247. /*--------------------------------------------------------------*\
  248.  *  Entry point declarations                                    *
  249. \*--------------------------------------------------------------*/
  250. /* from sem_main.c*/
  251. INT main(VOID);
  252. MRESULT EXPENTRY MainWndProc(HWND, ULONG, MPARAM, MPARAM);
  253. VOID MessageBox(HWND, LONG, BOOL);
  254. VOID MainCommand(HWND, MPARAM, MPARAM);
  255.  
  256. /* from sem_init.c*/
  257. BOOL Init(VOID);
  258. VOID APIENTRY ExitProc(ULONG);
  259.  
  260. /* from sem_user.c */
  261. VOID UserCommand(MPARAM, MPARAM);
  262.  
  263. /* from sem_pnt.c */
  264. VOID MainPaint(HWND hwnd);
  265. VOID DrawResource(PRECTL, COLOR);
  266. VOID DrawRects(HPS);
  267. VOID DrawStats(ULONG);
  268. VOID SetRectPositions(SHORT, SHORT, SHORT, SHORT);
  269. VOID InfoLine (HPS);
  270.  
  271. /* from semaph.c */
  272. VOID InitSemaphExample(VOID);
  273. VOID UpdateStats (VOID);
  274. VOID SemError(PSZ,ULONG);
  275. ULONG  CreateAllSems(VOID);
  276. INT StartSemExample(VOID);
  277. VOID SignalUserEvent(PULONG);
  278. ULONG SetAutoMode(VOID);
  279. VOID BeginStop (PULONG);
  280. VOID ThreadConsumer(PVOID);
  281. VOID RunAuto(PVOID);
  282. VOID StopSemaphore(PVOID);
  283.  
  284. /* from sem_help.c */
  285. VOID InitHelp(VOID);
  286. VOID HelpHelpForHelp(MPARAM);
  287. VOID HelpExtended(MPARAM);
  288. VOID HelpKeys(MPARAM);
  289. VOID HelpIndex(MPARAM);
  290. VOID HelpAbout(MPARAM);
  291. VOID DisplayHelpPanel(LONG);
  292. VOID DestroyHelpInstance(VOID);
  293. MRESULT EXPENTRY AboutDlgProc(HWND, ULONG, MPARAM, MPARAM);
  294. VOID FixSysMenu(HWND);
  295.  
  296. /* from sem_dlg.c */
  297. MRESULT EXPENTRY TimeDlgProc(HWND, ULONG, MPARAM, MPARAM);
  298.  
  299. /******************************************************
  300.  *
  301.  * Cruiser version define
  302.  *
  303.  ******************************************************/
  304. #define     VER678
  305.  
  306. #ifndef max
  307. #define max(a,b) (((a) > (b))?(a):(b))
  308. #endif
  309.  
  310. #ifndef min
  311. #define min(a,b) (((a) < (b))?(a):(b))
  312. #endif
  313.