2.4.2 Creating a Header File

It is often useful to create a header file in which to define constants and function prototypes for your application. Most applications consist of at least two source files that share common constants: the C-language source file and the resource-definition file. Since Microsoft Windows Resource Compiler (RC) carries out the same preprocessing as CL, it is useful and convenient to place constant definitions in a single header file and then include that file in both the C-language source file and the resource-definition file.

For example, for the Generic application, you can place the prototypes for WinMain, MainWndProc, About, InitApplication, and InitInstance, and the definition

of the menu identifier for the About command, in the GENERIC.H header file. The file should look like this:

#define IDM_ABOUT 100

int PASCAL          WinMain(HINSTANCE, HINSTANCE, LPSTR, int);
BOOL                InitApplication(HINSTANCE);
BOOL                InitInstance(HINSTANCE, int);
LRESULT FAR PASCAL  MainWndProc(HWND, UINT, WPARAM, LPARAM);
BOOL FAR PASCAL     About(HWND, WORD, WPARAM, LPARAM);

Since GENERIC.H refers to Windows data types, you must include it after WINDOWS.H, which defines those data types. The beginning of your source files should look like this:

#include <windows.h>     /* required for all Windows applications */
#include "generic.h"     /* specific to this program              */