The Template.H Header File

The WinHello demo did not require an .H header file, but the Template demo (and all further demos in this book) does require a header. In this case, this requirement is dictated by the need to define a new, application-specific message value. Remember, the Windows.H (or the WinDef.H) header supplies the stock definitions used, but values for any messages that are not already provided must be defined in the application’s header file, where these definitions can be accessed by both the resource editor(s) and the C compiler.

//============================//
//   Template.H header file   //
//============================//
#define IDM_ABOUT 100

In this case, only one message value is required: IDM_ABOUT. However, in later examples, much longer lists of defines will be quite common. Also, in most cases, there is no need to worry about value conflicts between values defined in the application header and values defined in the Windows.H header because these will be used in different contexts. It may be useful, however, to avoid values less than 100. Using higher values will avoid confusion with some common standard button IDs and will help you to group values as much as practical for your own clarity.

Also, many programmers prefer to include forward function declarations in the application header, as shown in the following code. However, including these declarations is optional, and unless required by your own organization and function ordering, they may be omitted entirely.

//==========================================//
// forward function declarations (optional) //
//==========================================//
BOOL InitApplication( HANDLE );
BOOL InitInstance( HANDLE, int );
long FAR PASCAL WndProc( HWND, UINT, UINT, LONG );
BOOL FAR PASCAL AboutProc( HWND, UINT, UINT, LONG );

© 1998 SYBEX Inc. All rights reserved.