How to add a Print or Open button to a dialog box
This document explains how to add a Print or Open PushButton control to the installer dialog boxes. The Print or Open buttons can be added to any dialog box that contains a RichText control, including the predefined ReadmeDlg and LicenseDlg dialog boxes.
Recommended procedure
The recommended procedure to add a Print or Open PushButton control is as follows.
- Right-click anywhere in the dialog box and choose New Control > PushButton from the popup menu.
- Use the mouse to move the newly created control into the desired position. You can make finer adjustments with the keyboard: the arrow keys move the control, while Shift+arrow keys resize the control.
- Set the PushButton control attributes as follows:
- Control ID - Automatic
- Name - any unique name, for example PrintButton or OpenButton.
- Caption type - Text (if you want to display an icon or bitmap, set to Icon or Bitmap as desired).
- Caption - Enter an appropriate text, for example &Print or &Open. The ampersands define the (underlined) keyboard accelerator.
- Leave the other attributes at their default; if necessary, refer to the PushButton control documentation for details.
- Right-click on the new control, then choose New Event Handler... from the popup menu.
- In the Select Dialog Event dialog box that appears, select the new control under Event source (it should be preselected already), then select OnClicked in the Available events list. Then click Select.
- The Event handlers tab is now visible and the newly added event handler (called PrintButton:OnClicked or OpenButton:OnClicked, or something similar) is selected.
- Right-click on the event handler, then choose New Action > Set Window State from the popup menu.
- Set the Set Window State attributes as follows:
- Action name - anything unique
- Description - leave empty
- State action - ShellExecute
- Window - click on the ... (browse) button to the right of the field to open the Select Dialog or Control dialog box, then select the RichText control in the parent dialog box. (For the predefined LicenseDlg and ReadmeDlg dialog boxes, this would be the MainText control in the corresponding dialog box.)
- Text/Value - Set to open to open the rich text resource in an external viewer, or set to print to print it with the default application.
- Rebuild your project.
What happens when the user clicks the Print or Open button during installation is that the RichText control saves its contents to a temporary RTF disk file, then uses the Windows Shell to open or print the text with the appropriate application. The default application for RTF files is WordPad, which is included with all Windows releases. However, if another word processor is installed, it will typically be the word processor that takes over the RTF file handling and takes care of the opening or printing.