home *** CD-ROM | disk | FTP | other *** search
/ QBasic & Borland Pascal & C / Delphi5.iso / C / BC_502 / THREAD.PAK / GLOBALS.H < prev    next >
Encoding:
C/C++ Source or Header  |  1997-05-06  |  6.1 KB  |  161 lines

  1. // THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
  2. // ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
  3. // THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
  4. // PARTICULAR PURPOSE.
  5. //
  6. // Copyright (C) 1993-1995  Microsoft Corporation.  All Rights Reserved.
  7. //
  8. // PURPOSE:
  9. //    Contains declarations for all globally scoped names in the program.
  10. //
  11.  
  12.  
  13. //-------------------------------------------------------------------------
  14. // Functions for handling main window messages.  The message-dispatching
  15. // mechanism expects all message-handling functions to have the following
  16. // prototype:
  17. //
  18. //     LRESULT FunctionName(HWND, UINT, WPARAM, LPARAM);
  19.  
  20. LRESULT MsgCreate(HWND, UINT, WPARAM, LPARAM);
  21. LRESULT MsgSize(HWND, UINT, WPARAM, LPARAM);
  22. LRESULT MsgCommand(HWND, UINT, WPARAM, LPARAM);
  23. LRESULT MsgDestroy(HWND, UINT, WPARAM, LPARAM);
  24. LRESULT MsgClose(HWND, UINT, WPARAM, LPARAM);
  25.  
  26. LRESULT MsgSizeThread(HWND, UINT, WPARAM, LPARAM);
  27.  
  28. //-------------------------------------------------------------------------
  29. // Functions for handling main window commands--ie. functions for
  30. // processing WM_COMMAND messages based on the wParam value.
  31. // The message-dispatching mechanism expects all command-handling
  32. // functions to have the following prototype:
  33. //
  34. //     LRESULT FunctionName(HWND, WORD, WORD, HWND);
  35.  
  36. LRESULT CmdThreadState(HWND, WORD, WORD, HWND);
  37. LRESULT CmdExit(HWND, WORD, WORD, HWND);
  38. LRESULT CmdAbout(HWND, WORD, WORD, HWND);
  39.  
  40. //-------------------------------------------------------------------------
  41. // Thread functions for our 4 windows.
  42.  
  43. DWORD WINAPI CountThread(LPVOID arg);
  44. DWORD WINAPI GCDThread(LPVOID arg);
  45. DWORD WINAPI PrimeThread(LPVOID arg);
  46. DWORD WINAPI RectThread(LPVOID arg);
  47.  
  48. //-------------------------------------------------------------------------
  49. // Global function prototypes.
  50.  
  51. BOOL InitApplication(HINSTANCE, int);
  52. BOOL CenterWindow(HWND, HWND);
  53.  
  54. //-------------------------------------------------------------------------
  55. // Callback functions.  These are called by Windows.
  56.  
  57. LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
  58. LRESULT CALLBACK ThreadChildWndProc(HWND, UINT, WPARAM, LPARAM);
  59.  
  60. //-------------------------------------------------------------------------
  61. // Global variable declarations.
  62.  
  63. //
  64. // We need this structure to communicate between the child window proc
  65. // and the thread proc.  Specifically we need to track of the window handle
  66. // each thread is associated with, the size of the client area of the child
  67. // window, and the flag which terminates each thread.
  68. //
  69. typedef struct tagThreadInfo
  70. {
  71.     HWND    hwnd;
  72.     HANDLE  hThread;        // Used to wait for the thread.
  73.     int cy;
  74.     int cx;
  75.     BOOL bThreadState;      // TRUE means the thread is active
  76. } THREADINFO, LPTHREADINFO;
  77.  
  78. extern HINSTANCE    hInst;          // The current instance handle
  79. extern char         szAppName[];    // The name of this application
  80. extern char         szTitle[];      // The title bar text
  81. extern THREADINFO   ThreadInfo[];   // Keeps information about the threads
  82. extern LONG         cyChar;         // character height
  83. extern LONG         cxChar;         // character width
  84.  
  85. #define hwndMDIClient NULL        /* Stub for NON-MDI applications. */
  86.  
  87. //-------------------------------------------------------------------------
  88. // Message and command dispatch infrastructure.  The following type
  89. // definitions and functions are used by the message and command dispatching
  90. // mechanism and do not need to be changed.
  91. // Function pointer prototype for message handling functions.
  92. //
  93. typedef LRESULT (*PFNMSG)(HWND,UINT,WPARAM,LPARAM);
  94.  
  95. // Function pointer prototype for command handling functions.
  96. typedef LRESULT (*PFNCMD)(HWND,WORD,WORD,HWND);
  97.  
  98. //
  99. // Enumerated type used to determine which default window procedure
  100. // should be called by the message- and command-dispatching mechanism
  101. // if a message or command is not handled explicitly.
  102. //
  103. typedef enum
  104. {
  105.    edwpNone,            // Do not call any default procedure.
  106.    edwpWindow,          // Call DefWindowProc.
  107.    edwpDialog,          // Call DefDlgProc (This should be used only for
  108.                         // custom dialogs - standard dialog use edwpNone).
  109.    edwpMDIChild,        // Call DefMDIChildProc.
  110.    edwpMDIFrame         // Call DefFrameProc.
  111. } EDWP;                 // Enumeration for Default Window Procedures
  112.  
  113. // This structure maps messages to message handling functions.
  114. typedef struct _MSD
  115. {
  116.     UINT   uMessage;
  117.     PFNMSG pfnmsg;
  118. } MSD;                  // Message Dispatch structure
  119.  
  120. //
  121. // This structure contains all of the information that a window
  122. // procedure passes to DispMessage in order to define the message
  123. // dispatching behavior for the window.
  124. //
  125. typedef struct _MSDI
  126. {
  127.     int  cmsd;          // Number of message dispatch structs in rgmsd
  128.     MSD *rgmsd;         // Table of message dispatch structures
  129.     EDWP edwp;          // Type of default window handler needed.
  130. } MSDI, FAR *LPMSDI;    // Message Dipatch Information
  131.  
  132. // This structure maps command IDs to command handling functions.
  133. typedef struct _CMD
  134. {
  135.     WORD   wCommand;
  136.     PFNCMD pfncmd;
  137. } CMD;                 // CoMmand Dispatch structure
  138.  
  139. //
  140. // This structure contains all of the information that a command
  141. // message procedure passes to DispCommand in order to define the
  142. // command dispatching behavior for the window.
  143. //
  144. typedef struct _CMDI
  145. {
  146.     int  ccmd;          // Number of command dispatch structs in rgcmd
  147.     CMD *rgcmd;         // Table of command dispatch structures
  148.     EDWP edwp;          // Type of default window handler needed.
  149. } CMDI, FAR *LPCMDI;    // Command Dispatch Information
  150.  
  151. //
  152. // Message and command dispatching functions.  They look up messages
  153. // and commands in the dispatch tables and call the appropriate handler
  154. // function.
  155. //
  156. LRESULT DispMessage(LPMSDI, HWND, UINT, WPARAM, LPARAM);
  157. LRESULT DispCommand(LPCMDI, HWND, WPARAM, LPARAM);
  158.  
  159. extern MSDI msdiMain;   // Message dispatch information for the main window
  160. extern CMDI cmdiMain;   // Command dispatch information for the main window
  161.