Linking Commands to Include Files

If you put the C code that defines what you want a command to do into an include file, QuickCase:W can link the command and its include file.

Summary: Design Suggestion

Using include files to define commands lets you create a collection of reusable, modular pieces that define the commonly used elements of most applications. The files you create can be used in any future applications that use the same command—with no additional development time.

·To link a text file to a command:

1.Do one of the following:

Click the command you want to link the file to.

Press ALT+F6 to activate the prototyped window; press ALT again to activate the menu bar; highlight the item with the ARROW keys; and press ENTER.

The Update Menu Item dialog box appears.

2.Click the User-Defined Code option in the Link To dropdown list box.

3.Choose the Configure Link button. The User-Defined Code dialog box appears (Figure 5.15).

4.Select the name of the text file you want to link to the command.

5.Choose OK.

When QuickCase:W generates the event handler for a command identified in Step 1, it inserts a #include reference to the file you choose in Step 4.

For example, if you link a command named Calculate to an include file named CALC.INC, QuickCase:W places the following code in the event-handling section of the generated .C file:

case IDM_F_CALCULATE:

/* Place User Code to respond to the */

/* Menu Item Named "&Calculate" here. */

#include "CALC.INC"

break;

If the include file completely defines what you want the command to do, no other code is necessary.

Note that the structure of the include file is different from regular source code or include files. The file containing user-defined code must be a collection of statements. If you want to use local variables, you must surround variable declarations and statements with curly braces.

For example, in response to the command &Calculate, the file CALC.INC could contain:

Calculate() ;

or:

{

int i ;

i = Calculate() ;

}

But it could not contain:

int i ;

i = Calculate() ;

nor could it have any function definitions:

int Calculate (void)

{

return x * y ;

}