Adding Buttons

To add buttons to Viewer, enter the CreateButton command in the [CONFIG] section of the project file. You might recognize this command from Chapter 3, “Creating Topics,” where it was used to add the Search button to the Viewer button bar. In its general form, the CreateButton command uses the following syntax:

CreateButton("button-id","button-label", "command")

Button-id is a name, enclosed in quotes, that Viewer uses internally to identify your button. To disable or remove the button in certain topics, or change the operations that the button performs in certain topics, you use this name to identify the button.

Note:

The following button IDs are used for standard Viewer buttons and cannot be given in a CreateButton command: “btn_contents” (Contents), “btn_search” (Index), “btn_back” (Back), “btn_history” (History), “btn_previous” (<<), and “btn_next” (>>).

Button-label is the label, enclosed in quotes, you want to appear on the button. Viewer looks at the longest button label entered and makes all buttons that size. Use the names on the seven default buttons as a guide for the length and types of labels you should use.

Command is the Viewer command you are executing, enclosed in double quotes. The command can also be a function in an external DLL that you've registered as a Viewer command using Viewer's RegisterRoutine command. The HAudioCommand, HAudioDialog, HDisplayBmp, and HAnimateCommand commands are examples of external DLL calls registered as Viewer commands. (See Chapter 18, “Multimedia Viewer Commands,” for more information on how to use RegisterRoutine.)

Viewer carries out this command whenever the user chooses the button. See Chapter 18, “Multimedia Viewer Commands,” for a complete list of these commands and a description of the format they use. The following example adds a button labeled “Time” and uses ExecProgram to run the Alarm Clock application.

[CONFIG]
CreateButton("time_btn", "&Time", "ExecProgram(`alarmclk', 0)")

The ampersand (&) before the “T” in Time means that the T is underlined on the button, and the user can press the T key to select the button. The button appears as shown in the following illustration: