// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
// ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
// PARTICULAR PURPOSE.
//
// Copyright (C) 1993, 1994  Microsoft Corporation.  All Rights Reserved.
//
// PURPOSE:
//    Contains declarations for all globally scoped names in the program.
//

//-------------------------------------------------------------------------
// Product identifier string defines

//  **TODO** Change these strings to the name of your application.

#define APPNAME       Threads
#define ICONFILE      THREADS.ICO
#define SZAPPNAME     "Threads"
#define SZDESCRIPTION "Thread Example Application"
#define SZABOUT       "About Threads"
#define SZVERSION     "Version 4.0"

// This is the class name of the child window
#define SZTHREADCHILD "ThrdChld"

//
// A user defined message so we can communicate with the child
// windows.
//
#define WM_THREADSTATE (WM_USER + 1156)

//-------------------------------------------------------------------------
// Because this application uses threads.  This 
// application will only run/compile/work under 32-bit
// version of windows.  There is no need to try and port it
// back to 16-bit Windows.  If you need to look at a 16-bit
// comm sample, take a look at a PeekMessage sample on the
// KnowledgeBase library.  We're just being doubly sure here
// that the Win32 #define gets set.
// 
#ifndef WIN32 
#define WIN32
#endif

//-------------------------------------------------------------------------
// Since this is a multi-threaded application, we have to 
// be sure to set the following definition.
//
#define _MT 

//-------------------------------------------------------------------------
// Functions for handling main window messages.  The message-dispatching
// mechanism expects all message-handling functions to have the following
// prototype:
//
//     LRESULT FunctionName(HWND, UINT, WPARAM, LPARAM);

// Thread functions for our 4 windows.
void CountThread(void *arg);
void GCDThread(void *arg);
void PrimeThread(void *arg);
void RectThread(void *arg);

// **TODO**  Add message-handling function prototypes here.  Be sure to
//           add the function names to the main window message table in
//           threads.c.
LRESULT MsgCreate(HWND, UINT, WPARAM, LPARAM);
LRESULT MsgSize(HWND, UINT, WPARAM, LPARAM);
LRESULT MsgCommand(HWND, UINT, WPARAM, LPARAM);
LRESULT MsgDestroy(HWND, UINT, WPARAM, LPARAM);
LRESULT MsgClose(HWND, UINT, WPARAM, LPARAM);

//-------------------------------------------------------------------------
// Functions for handling main window commands--ie. functions for
// processing WM_COMMAND messages based on the wParam value.
// The message-dispatching mechanism expects all command-handling
// functions to have the following prototype:
//
//     LRESULT FunctionName(HWND, WORD, WORD, HWND);

// **TODO**  Add message-handling function prototypes here.  Be sure to
//           add the function names to the main window command table in
//           threads.c.
//
LRESULT CmdThreadState(HWND, WORD, WORD, HWND);
LRESULT CmdExit(HWND, WORD, WORD, HWND);
LRESULT CmdAbout(HWND, WORD, WORD, HWND);

//-------------------------------------------------------------------------
// Global function prototypes.
// **TODO**  Add global function prototypes here.
//
BOOL InitApplication(HINSTANCE);
BOOL InitInstance(HINSTANCE, int);
BOOL CenterWindow(HWND, HWND);

//-------------------------------------------------------------------------
// Callback functions.  These are called by Windows.
// **TODO**  Add new callback function prototypes here.  
//
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
LRESULT CALLBACK ThreadChildWndProc(HWND, UINT, WPARAM, LPARAM);

//-------------------------------------------------------------------------
// ID definitions.  These definitions are used to associate menu
// items with commands and othre resources.
//
// **TODO**  Add IDs for all menu commands here.  Be sure that the IDs you
//           add are also added to the main window command table in threads.c
//           and the menu statements in the resource file.
//

// File menu
#define IDM_EXIT        1000

// Threads menu
#define IDM_COUNT       1100
#define IDM_GCD         1101
#define IDM_PRIME       1102
#define IDM_RECT        1103

// Help menu
#define IDM_ABOUT       1200

// String Table ID definitions.
#define IDS_APPNAME         1
#define IDS_DESCRIPTION     2
#define IDS_THREADCHILD     3

//
// Control ID's for the child windows.  It is important not to change
// these because I use them as indexes into the ThreadInfo array.
//
#define IDC_COUNT           0
#define IDC_GCD             1
#define IDC_PRIME           2
#define IDC_RECT            3

//  About dialog defines.
#define IDD_VERFIRST        100
#define IDD_VERLAST         104

//-------------------------------------------------------------------------
// Global variable declarations.

//
// We need this structure to communicate between the child window proc
// and the thread proc.  Specifically we need to track of the window handle
// each thread is associated with, the size of the client area of the child
// window, and the flag which terminates each thread.
//
typedef struct tagThreadInfo
{
    HWND hwnd;
    int cy;
    int cx;
    BOOL bThreadState;      // TRUE means the thread is active
    void *lpfnThread;
} THREADINFO, LPTHREADINFO;

extern HINSTANCE    hInst;          // The current instance handle
extern char         szAppName[];    // The name of this application
extern char         szTitle[];      // The title bar text
extern THREADINFO   ThreadInfo[];   // Keeps information about the threads
extern LONG         cyChar;         // character height
extern LONG         cxChar;         // character width

// **TODO**  For NON-MDI applications, uncomment line 1 below and comment
//           line 2.  For MDI applications, uncomment line 2 below, comment
//           line 1, and then define hwndMDIClient as a global variable in
//           INIT.C
#define hwndMDIClient NULL        /* (1) Stub for NON-MDI applications. */
// extern HWND hwndMDIClient;     /* (2) For MDI applications.          */

//-------------------------------------------------------------------------
// Message and command dispatch infrastructure.  The following type
// definitions and functions are used by the message and command dispatching
// mechanism and do not need to be changed.
// Function pointer prototype for message handling functions.
//
typedef LRESULT (*PFNMSG)(HWND,UINT,WPARAM,LPARAM);

// Function pointer prototype for command handling functions.
typedef LRESULT (*PFNCMD)(HWND,WORD,WORD,HWND);

//
// Enumerated type used to determine which default window procedure
// should be called by the message- and command-dispatching mechanism
// if a message or command is not handled explicitly.
//
typedef enum
{
   edwpNone,            // Do not call any default procedure.
   edwpWindow,          // Call DefWindowProc.
   edwpDialog,          // Call DefDlgProc (This should be used only for
                        // custom dialogs - standard dialog use edwpNone).
   edwpMDIChild,        // Call DefMDIChildProc.
   edwpMDIFrame         // Call DefFrameProc.
} EDWP;                 // Enumeration for Default Window Procedures

// This structure maps messages to message handling functions.
typedef struct _MSD
{
    UINT   uMessage;
    PFNMSG pfnmsg;
} MSD;                  // Message Dispatch structure

//
// This structure contains all of the information that a window
// procedure passes to DispMessage in order to define the message
// dispatching behavior for the window.
//
typedef struct _MSDI
{
    int  cmsd;          // Number of message dispatch structs in rgmsd
    MSD *rgmsd;         // Table of message dispatch structures
    EDWP edwp;          // Type of default window handler needed.
} MSDI, FAR *LPMSDI;    // Message Dipatch Information

// This structure maps command IDs to command handling functions.
typedef struct _CMD
{
    WORD   wCommand;
    PFNCMD pfncmd;
} CMD;                 // CoMmand Dispatch structure

//
// This structure contains all of the information that a command
// message procedure passes to DispCommand in order to define the
// command dispatching behavior for the window.
//
typedef struct _CMDI
{
    int  ccmd;          // Number of command dispatch structs in rgcmd
    CMD *rgcmd;         // Table of command dispatch structures
    EDWP edwp;          // Type of default window handler needed.
} CMDI, FAR *LPCMDI;    // Command Dispatch Information

//
// Message and command dispatching functions.  They look up messages
// and commands in the dispatch tables and call the appropriate handler
// function.
//
LRESULT DispMessage(LPMSDI, HWND, UINT, WPARAM, LPARAM);
LRESULT DispCommand(LPCMDI, HWND, WPARAM, LPARAM);

extern MSDI msdiMain;   // Message dispatch information for the main window
extern CMDI cmdiMain;   // Command dispatch information for the main window

//-------------------------------------------------------------------------
// Version string definitions--Leave these alone.
//
#define SZRCOMPANYNAME "CompanyName"
#define SZRDESCRIPTION "FileDescription"
#define SZRVERSION     "FileVersion"
#define SZRAPPNAME     "InternalName"
#define SZRCOPYRIGHT   "LegalCopyright"
#define SZRTRADEMARK   "LegalTrademarks"
#define SZRPRODNAME    "ProductName"
#define SZRPRODVER     "ProuctVersion"

